Skip to content

Commit

Permalink
improve linting settings
Browse files Browse the repository at this point in the history
  • Loading branch information
zloirock committed Mar 22, 2021
1 parent 6d36b3c commit db440fe
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 3 deletions.
12 changes: 11 additions & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -379,6 +379,8 @@ const base = {
'unicorn/no-hex-escape': 'error',
// disallow if as the only statement in an else block
'unicorn/no-lonely-if': 'error',
// forbid classes that only have static members
'unicorn/no-static-only-class': 'error',
// disallow unreadable array destructuring
'unicorn/no-unreadable-array-destructuring': 'error',
// disallow unsafe regular expressions
Expand Down Expand Up @@ -457,12 +459,18 @@ const base = {
'regexp/no-escape-backspace': 'error',
// disallow invisible raw character
'regexp/no-invisible-character': 'error',
// disallow legacy RegExp features
'regexp/no-legacy-features': 'error',
// disallow octal escape sequence
'regexp/no-octal': 'error',
// disallow unused capturing group
'regexp/no-unused-capturing-group': 'error',
// disallow useless backreferences in regular expressions
'regexp/no-useless-backreference': 'error',
// disallow character class with one character
'regexp/no-useless-character-class': 'error',
// disallow useless `$` replacements in replacement string
'regexp/no-useless-dollar-replacements': 'error',
// disallow unnecessary string escaping
'regexp/no-useless-escape': 'error',
// disallow unnecessary exactly quantifier
Expand All @@ -479,8 +487,10 @@ const base = {
'regexp/order-in-character-class': 'error',
// enforce using character class
'regexp/prefer-character-class': 'error',
// enforce using '\d'
// enforce using `\d`
'regexp/prefer-d': 'error',
// enforces escape of replacement `$` character (`$$`)
'regexp/prefer-escape-replacement-dollar-char': 'error',
// enforce using `+` quantifier
'regexp/prefer-plus-quantifier': 'error',
// enforce using quantifier
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@
"eslint-plugin-optimize-regex": "^1.2.0",
"eslint-plugin-qunit": "^6.0.0",
"eslint-plugin-radar": "~0.2.1",
"eslint-plugin-regexp": "~0.5.0",
"eslint-plugin-unicorn": "^28.0.2",
"eslint-plugin-regexp": "~0.6.1",
"eslint-plugin-unicorn": "^29.0.0",
"karma": "^6.2.0",
"karma-chrome-launcher": "^3.1.0",
"karma-phantomjs-launcher": "~1.0.4",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ var REPLACE_SUPPORTS_NAMED_GROUPS = !fails(function () {
// IE <= 11 replaces $0 with the whole match, as if it was $&
// https://stackoverflow.com/questions/6024666/getting-ie-to-replace-a-regex-with-the-literal-string-0
var REPLACE_KEEPS_$0 = (function () {
// eslint-disable-next-line regexp/prefer-escape-replacement-dollar-char -- required for testing
return 'a'.replace(/./, '$0') === '$0';
})();

Expand Down
1 change: 1 addition & 0 deletions tests/compat/tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -870,6 +870,7 @@ GLOBAL.tests = {
return ''.replace(O) == 7
&& execCalled
&& ''.replace(re2, '$<a>') === '7'
// eslint-disable-next-line regexp/prefer-escape-replacement-dollar-char -- required for testing
&& 'a'.replace(/./, '$0') === '$0'
&& /./[Symbol.replace]('a', '$0') === '$0';
},
Expand Down
6 changes: 6 additions & 0 deletions tests/tests/es.string.replace.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable regexp/no-unused-capturing-group -- required for testibg */
import { GLOBAL, NATIVE, STRICT } from '../helpers/constants';
import { patchRegExp$exec } from '../helpers/helpers';

Expand Down Expand Up @@ -124,7 +125,9 @@ const run = assert => {
assert.strictEqual('aaaaaaaaaa,aaaaaaaaaaaaaaa'.replace(/^(a+)\1*,\1+$/, '$1'), 'aaaaa', 'S15.5.4.11_A5_T1');

// https://github.com/zloirock/core-js/issues/471
// eslint-disable-next-line regexp/no-useless-dollar-replacements -- required for testing
assert.strictEqual('{price} Retail'.replace(/{price}/g, '$25.00'), '$25.00 Retail');
// eslint-disable-next-line regexp/prefer-escape-replacement-dollar-char -- required for testing
assert.strictEqual('a'.replace(/(.)/, '$0'), '$0');
};

Expand Down Expand Up @@ -203,12 +206,15 @@ QUnit.test('RegExp#@@replace correctly handles substitutions', assert => {
result.index = 1;
return result;
};
// eslint-disable-next-line regexp/no-useless-dollar-replacements -- false positive
assert.strictEqual('1234'.replace(re, '$1'), '174');
// eslint-disable-next-line regexp/no-useless-dollar-replacements -- required for testing
assert.strictEqual('1234'.replace(re, '$<!!!>'), '174');
assert.strictEqual('1234'.replace(re, '$`'), '114');
assert.strictEqual('1234'.replace(re, '$\''), '144');
assert.strictEqual('1234'.replace(re, '$$'), '1$4');
assert.strictEqual('1234'.replace(re, '$&'), '1234');
// eslint-disable-next-line regexp/prefer-escape-replacement-dollar-char -- required for testing
assert.strictEqual('1234'.replace(re, '$x'), '1$x4');

let args;
Expand Down

0 comments on commit db440fe

Please sign in to comment.