about summary refs log tree commit diff
path: root/.eslintrc.js
diff options
context:
space:
mode:
authorCommanderRoot <CommanderRoot@users.noreply.github.com>2022-04-04 18:19:45 +0200
committerGitHub <noreply@github.com>2022-04-04 12:19:45 -0400
commit0ec695e036dab45d57598f451266bd0b176df9fd (patch)
tree0b68486138f3ec36bdba2f58f3f8db41e5bae6a9 /.eslintrc.js
parent80ded02a4bd2ea6d5b9b69198753063224773f66 (diff)
Replace deprecated String.prototype.substr() (#17949)
* Replace deprecated String.prototype.substr()

.substr() is deprecated so we replace it with .slice() which works similarily but isn't deprecated

* Change String.prototype.substring() to String.prototype.slice()

.substring() and .slice() work very similary but .slice() is a bit faster and stricter

* Add ESLint rule to forbid usage of .substr and .substring

.substr() is deprecated and .substring() is very similar to .slice() so better to use .slice() at all times

Signed-off-by: Tobias Speicher <rootcommander@gmail.com>
Diffstat (limited to '.eslintrc.js')
-rw-r--r--.eslintrc.js5
1 files changed, 5 insertions, 0 deletions
diff --git a/.eslintrc.js b/.eslintrc.js
index 7dda01108..2a882f59c 100644
--- a/.eslintrc.js
+++ b/.eslintrc.js
@@ -79,6 +79,11 @@ module.exports = {
     'no-irregular-whitespace': 'error',
     'no-mixed-spaces-and-tabs': 'warn',
     'no-nested-ternary': 'warn',
+    'no-restricted-properties': [
+      'error',
+      { property: 'substring', message: 'Use .slice instead of .substring.' },
+      { property: 'substr', message: 'Use .slice instead of .substr.' },
+    ],
     'no-trailing-spaces': 'warn',
     'no-undef': 'error',
     'no-unreachable': 'error',