Skip to content

Commit 43a5f9e

Browse files
authored
feat: add eslint-plugin-regexp to eslint-config-eslint base config (#19951)
* feat: add eslint-plugin-regexp to eslint-config-eslint base config * resolve linting errors * apply fasttime's suggestions * revert regex change and suppress false positive * update eslint-plugin-regexp * remove start anchor from plugin member name regex
1 parent e2dc67d commit 43a5f9e

27 files changed

Lines changed: 48 additions & 42 deletions

docs/tools/markdown-it-rule-example.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ function markdownItRuleExample({ open, close }) {
7373
}
7474

7575
const { type, languageOptionsJSON } =
76-
/^\s*(?<type>\S+)(\s+(?<languageOptionsJSON>\S.*?))?\s*$/u.exec(
76+
/^\s*(?<type>\S+)(?:\s+(?<languageOptionsJSON>\S(?:.*\S)?))?/u.exec(
7777
tagToken.info,
7878
).groups;
7979
const languageOptions = languageOptionsJSON

lib/cli-engine/file-enumerator.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ const debug = require("debug")("eslint:file-enumerator");
5151
//------------------------------------------------------------------------------
5252

5353
const minimatchOpts = { dot: true, matchBase: true };
54-
const dotfilesPattern = /(?:(?:^\.)|(?:[/\\]\.))[^/\\.].*/u;
54+
const dotfilesPattern = /(?:^\.|[/\\]\.)[^/\\.].*/u;
5555
const NONE = 0;
5656
const IGNORED_SILENTLY = 1;
5757
const IGNORED = 2;

lib/config/flat-config-schema.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ function assertIsRuleSeverity(ruleId, value) {
230230
* @throws {TypeError} If the string isn't in the correct format.
231231
*/
232232
function assertIsPluginMemberName(value) {
233-
if (!/[@a-z0-9-_$]+(?:\/(?:[a-z0-9-_$]+))+$/iu.test(value)) {
233+
if (!/[\w\-@$]+(?:\/[\w\-$]+)+$/iu.test(value)) {
234234
throw new TypeError(
235235
`Expected string in the form "pluginName/objectName" but found "${value}".`,
236236
);

lib/languages/js/source-code/source-code.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1056,7 +1056,7 @@ class SourceCode extends TokenStore {
10561056
// only certain comment types are supported as line comments
10571057
return (
10581058
comment.type !== "Line" ||
1059-
!!/^eslint-disable-(next-)?line$/u.test(directive.label)
1059+
!!/^eslint-disable-(?:next-)?line$/u.test(directive.label)
10601060
);
10611061
});
10621062

@@ -1091,9 +1091,8 @@ class SourceCode extends TokenStore {
10911091
} = commentParser.parseDirective(comment.value);
10921092

10931093
// Step 2: Extract the directive value
1094-
const lineCommentSupported = /^eslint-disable-(next-)?line$/u.test(
1095-
label,
1096-
);
1094+
const lineCommentSupported =
1095+
/^eslint-disable-(?:next-)?line$/u.test(label);
10971096

10981097
if (comment.type === "Line" && !lineCommentSupported) {
10991098
return;

lib/linter/interpolate.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
* @returns {RegExp} Global regular expression matching placeholders
1515
*/
1616
function getPlaceholderMatcher() {
17-
return /\{\{([^{}]+?)\}\}/gu;
17+
return /\{\{([^{}]+)\}\}/gu;
1818
}
1919

2020
/**

lib/linter/linter.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -438,9 +438,8 @@ function getDirectiveComments(
438438
justification: justificationPart,
439439
} = directive;
440440

441-
const lineCommentSupported = /^eslint-disable-(next-)?line$/u.test(
442-
label,
443-
);
441+
const lineCommentSupported =
442+
/^eslint-disable-(?:next-)?line$/u.test(label);
444443

445444
if (comment.type === "Line" && !lineCommentSupported) {
446445
return;
@@ -739,7 +738,7 @@ function normalizeEcmaVersionForLanguageOptions(ecmaVersion) {
739738
return LATEST_ECMA_VERSION;
740739
}
741740

742-
const eslintEnvPattern = /\/\*\s*eslint-env\s(.+?)(?:\*\/|$)/gsu;
741+
const eslintEnvPattern = /\/\*\s*eslint-env\s.+?(?:\*\/|$)/gsu;
743742

744743
/**
745744
* Checks whether or not there is a comment which has "eslint-env *" in a given text.

lib/rules/dot-notation.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ const keywords = require("./utils/keywords");
1515
// Rule Definition
1616
//------------------------------------------------------------------------------
1717

18-
const validIdentifier = /^[a-zA-Z_$][a-zA-Z0-9_$]*$/u;
18+
const validIdentifier = /^[a-zA-Z_$][\w$]*$/u;
1919

2020
// `null` literal must be handled separately.
2121
const literalTypesToCheck = new Set(["string", "boolean"]);

lib/rules/indent-legacy.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1162,7 +1162,7 @@ module.exports = {
11621162
* @returns {boolean} the result
11631163
*/
11641164
function isWrappedInParenthesis(node) {
1165-
const regex = /^return\s*?\(\s*?\);*?/u;
1165+
const regex = /^return\s*\(\s*\)/u;
11661166

11671167
const statementWithoutArgument = sourceCode
11681168
.getText(node)

lib/rules/no-alert.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ const {
2424
* @returns {boolean} Whether or not the name is prohibited.
2525
*/
2626
function isProhibitedIdentifier(name) {
27-
return /^(alert|confirm|prompt)$/u.test(name);
27+
return /^(?:alert|confirm|prompt)$/u.test(name);
2828
}
2929

3030
/**

lib/rules/no-empty-function.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ module.exports = {
162162
}
163163
}
164164

165-
if (/(g|s)etters|methods$/iu.test(kind)) {
165+
if (/(?:g|s)etters|methods$/iu.test(kind)) {
166166
if (
167167
(node.parent.decorators?.length &&
168168
allow.includes("decoratedFunctions")) ||

0 commit comments

Comments
 (0)