Skip to content

Commit

Permalink
update eslint-plugin-regexp, clean some duplicated rules
Browse files Browse the repository at this point in the history
  • Loading branch information
zloirock committed Sep 23, 2021
1 parent 84b1520 commit 8c1b38e
Show file tree
Hide file tree
Showing 8 changed files with 15 additions and 26 deletions.
26 changes: 10 additions & 16 deletions .eslintrc.js
Expand Up @@ -27,8 +27,6 @@ const base = {
'no-console': ERROR,
// disallow constant expressions in conditions
'no-constant-condition': [ERROR, { checkLoops: false }],
// disallow control characters in regular expressions
'no-control-regex': ERROR,
// disallow use of debugger
'no-debugger': ERROR,
// disallow duplicate arguments in functions
Expand All @@ -41,8 +39,6 @@ const base = {
'no-else-return': ERROR,
// disallow empty statements
'no-empty': ERROR,
// disallow the use of empty character classes in regular expressions
'no-empty-character-class': ERROR,
// disallow unnecessary boolean casts
'no-extra-boolean-cast': ERROR,
// disallow unnecessary semicolons
Expand All @@ -51,20 +47,14 @@ const base = {
'no-ex-assign': ERROR,
// disallow overwriting functions written as function declarations
'no-func-assign': ERROR,
// disallow invalid regular expression strings in the RegExp constructor
'no-invalid-regexp': ERROR,
// disallow irregular whitespace outside of strings and comments
'no-irregular-whitespace': ERROR,
// disallow literal numbers that lose precision
// 'no-loss-of-precision': ERROR, // TODO
// disallow characters which are made with multiple code points in character class syntax
'no-misleading-character-class': ERROR,
// disallow the use of object properties of the global object (Math and JSON) as functions
'no-obj-calls': ERROR,
// disallow use of Object.prototypes builtins directly
'no-prototype-builtins': ERROR,
// disallow multiple spaces in a regular expression literal
'no-regex-spaces': ERROR,
// disallow specific global variables
'no-restricted-globals': [ERROR, ...RESTRICTED_GLOBALS],
// disallow returning values from setters
Expand All @@ -81,8 +71,6 @@ const base = {
'no-unsafe-optional-chaining': ERROR,
// disallow loops with a body that allows only one iteration
'no-unreachable-loop': ERROR,
// disallow useless backreferences in regular expressions
'no-useless-backreference': ERROR,
// disallow comparisons with the value NaN
'use-isnan': ERROR,
// disallow unreachable statements after a return, throw, continue, or break statement
Expand Down Expand Up @@ -175,8 +163,6 @@ const base = {
'no-useless-catch': ERROR,
// disallow useless string concatenation
'no-useless-concat': ERROR,
// disallow unnecessary string escaping
// 'no-useless-escape': ERROR, // replaced by 'regexp/no-useless-escape'
// disallow void operators
'no-void': ERROR,
// disallow use of the with statement
Expand Down Expand Up @@ -406,8 +392,6 @@ const base = {
'unicorn/no-static-only-class': ERROR,
// disallow unreadable array destructuring
'unicorn/no-unreadable-array-destructuring': ERROR,
// disallow unsafe regular expressions
'unicorn/no-unsafe-regex': ERROR,
// disallow unused object properties
'unicorn/no-unused-properties': ERROR,
// forbid useless fallback when spreading in object literals
Expand Down Expand Up @@ -489,6 +473,10 @@ const base = {
'regexp/match-any': [ERROR, { allows: ['[\\S\\s]', 'dotAll'] }],
// enforce use of escapes on negation
'regexp/negation': ERROR,
// disallow elements that contradict assertions
'regexp/no-contradiction-with-assertion': ERROR,
// disallow control characters
'regexp/no-control-character': ERROR,
// disallow duplicate characters in the RegExp character class
'regexp/no-dupe-characters-character-class': ERROR,
// disallow duplicate disjunctions
Expand All @@ -497,6 +485,8 @@ const base = {
'regexp/no-empty-alternative': ERROR,
// disallow capturing group that captures empty
'regexp/no-empty-capturing-group': ERROR,
// disallow character classes that match no characters
'regexp/no-empty-character-class': ERROR,
// disallow empty group
'regexp/no-empty-group': ERROR,
// disallow empty lookahead assertion or empty lookbehind assertion
Expand All @@ -511,6 +501,8 @@ const base = {
'regexp/no-lazy-ends': ERROR,
// disallow legacy RegExp features
'regexp/no-legacy-features': ERROR,
// disallow multi-code-point characters in character classes and quantifiers
'regexp/no-misleading-unicode-character': ERROR,
// disallow non-standard flags
'regexp/no-non-standard-flag': ERROR,
// disallow obscure character ranges
Expand Down Expand Up @@ -831,6 +823,8 @@ const nodePackages = {
};

const nodeDev = {
// prefer lookarounds over capturing group that do not replace
'regexp/prefer-lookaround': ERROR,
// disallow unsupported ECMAScript built-ins on the specified version
'node/no-unsupported-features/node-builtins': [ERROR, { version: DEV_NODE_VERSIONS }],
...disable(forbidModernESBuiltIns),
Expand Down
2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -41,7 +41,7 @@
"eslint-plugin-jsonc": "^1.7.0",
"eslint-plugin-node": "^11.1.0",
"eslint-plugin-qunit": "^6.2.0",
"eslint-plugin-regexp": "^1.1.0",
"eslint-plugin-regexp": "^1.2.0",
"eslint-plugin-sonarjs": "~0.10.0",
"eslint-plugin-unicorn": "^36.0.0",
"jsonc-eslint-parser": "^1.4.1",
Expand Down
1 change: 0 additions & 1 deletion packages/core-js/internals/string-pad-webkit-bug.js
@@ -1,5 +1,4 @@
// https://github.com/zloirock/core-js/issues/280
var userAgent = require('../internals/engine-user-agent');

// eslint-disable-next-line unicorn/no-unsafe-regex -- safe
module.exports = /Version\/10(?:\.\d+){1,2}(?: [\w./]+)?(?: Mobile\/\w+)? Safari\//.test(userAgent);
4 changes: 2 additions & 2 deletions packages/core-js/modules/web.url.js
Expand Up @@ -39,12 +39,12 @@ var HEX_START = /^0x/i;
var OCT = /^[0-7]+$/;
var DEC = /^\d+$/;
var HEX = /^[\dA-Fa-f]+$/;
/* eslint-disable no-control-regex -- safe */
/* eslint-disable regexp/no-control-character -- safe */
var FORBIDDEN_HOST_CODE_POINT = /[\0\t\n\r #%/:<>?@[\\\]^|]/;
var FORBIDDEN_HOST_CODE_POINT_EXCLUDING_PERCENT = /[\0\t\n\r #/:<>?@[\\\]^|]/;
var LEADING_AND_TRAILING_C0_CONTROL_OR_SPACE = /^[\u0000-\u0020]+|[\u0000-\u0020]+$/g;
var TAB_AND_NEW_LINE = /[\t\n\r]/g;
/* eslint-enable no-control-regex -- safe */
/* eslint-enable regexp/no-control-character -- safe */
var EOF;

var parseHost = function (url, input) {
Expand Down
2 changes: 1 addition & 1 deletion packages/core-js/postinstall.js
Expand Up @@ -52,7 +52,7 @@ function isBannerRequired() {
}

function showBanner() {
// eslint-disable-next-line no-console,no-control-regex -- output
// eslint-disable-next-line no-console, regexp/no-control-character -- output
console.log(COLOR ? BANNER : BANNER.replace(/\u001B\[\d+m/g, ''));
}

Expand Down
1 change: 0 additions & 1 deletion tests/compat/tests.js
Expand Up @@ -25,7 +25,6 @@ if (v8) {

var IS_NODE = Object.prototype.toString.call(process) == '[object process]';

// eslint-disable-next-line unicorn/no-unsafe-regex -- safe
var WEBKIT_STRING_PAD_BUG = /Version\/10(?:\.\d+){1,2}(?: [\w./]+)?(?: Mobile\/\w+)? Safari\//.test(USERAGENT);

var DESCRIPTORS_SUPPORT = function () {
Expand Down
3 changes: 0 additions & 3 deletions tests/tests/es.regexp.constructor.js
Expand Up @@ -89,11 +89,8 @@ if (DESCRIPTORS) {
return `${ bar },${ foo }`;
}), 'def,abc', 'replace #2');
assert.same('12345'.replaceAll(RegExp('(?<d>[2-4])', 'g'), '$<d>$<d>'), '12233445', 'replaceAll');
// eslint-disable-next-line no-invalid-regexp -- required for testing
assert.throws(() => RegExp('(?<1a>b)'), SyntaxError, 'incorrect group name #1');
// eslint-disable-next-line no-invalid-regexp -- required for testing
assert.throws(() => RegExp('(?<a#>b)'), SyntaxError, 'incorrect group name #2');
// eslint-disable-next-line no-invalid-regexp -- required for testing
assert.throws(() => RegExp('(?< a >b)'), SyntaxError, 'incorrect group name #3');
});
}
2 changes: 1 addition & 1 deletion tests/tests/es.string.match.js
@@ -1,5 +1,5 @@
// TODO: fix escaping in regexps
/* eslint-disable regexp/prefer-regexp-exec, unicorn/no-unsafe-regex -- required for testing */
/* eslint-disable regexp/prefer-regexp-exec -- required for testing */
import { GLOBAL, NATIVE, STRICT } from '../helpers/constants';
import { patchRegExp$exec } from '../helpers/helpers';

Expand Down

0 comments on commit 8c1b38e

Please sign in to comment.