Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/tools/markdown-it-rule-example.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ function markdownItRuleExample({ open, close }) {
}

const { type, languageOptionsJSON } =
/^\s*(?<type>\S+)(\s+(?<languageOptionsJSON>\S.*?))?\s*$/u.exec(
/^\s*(?<type>\S+)(?:\s+(?<languageOptionsJSON>\S(?:.*\S)?))?/u.exec(
tagToken.info,
).groups;
const languageOptions = languageOptionsJSON
Expand Down
2 changes: 1 addition & 1 deletion lib/cli-engine/file-enumerator.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ const debug = require("debug")("eslint:file-enumerator");
//------------------------------------------------------------------------------

const minimatchOpts = { dot: true, matchBase: true };
const dotfilesPattern = /(?:(?:^\.)|(?:[/\\]\.))[^/\\.].*/u;
const dotfilesPattern = /(?:^\.|[/\\]\.)[^/\\.].*/u;
const NONE = 0;
const IGNORED_SILENTLY = 1;
const IGNORED = 2;
Expand Down
2 changes: 1 addition & 1 deletion lib/config/flat-config-schema.js
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ function assertIsRuleSeverity(ruleId, value) {
* @throws {TypeError} If the string isn't in the correct format.
*/
function assertIsPluginMemberName(value) {
if (!/[@a-z0-9-_$]+(?:\/(?:[a-z0-9-_$]+))+$/iu.test(value)) {
if (!/[\w\-@$]+(?:\/[\w\-$]+)+$/iu.test(value)) {
throw new TypeError(
`Expected string in the form "pluginName/objectName" but found "${value}".`,
);
Expand Down
7 changes: 3 additions & 4 deletions lib/languages/js/source-code/source-code.js
Original file line number Diff line number Diff line change
Expand Up @@ -1056,7 +1056,7 @@ class SourceCode extends TokenStore {
// only certain comment types are supported as line comments
return (
comment.type !== "Line" ||
!!/^eslint-disable-(next-)?line$/u.test(directive.label)
!!/^eslint-disable-(?:next-)?line$/u.test(directive.label)
);
});

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

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

if (comment.type === "Line" && !lineCommentSupported) {
return;
Expand Down
2 changes: 1 addition & 1 deletion lib/linter/interpolate.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* @returns {RegExp} Global regular expression matching placeholders
*/
function getPlaceholderMatcher() {
return /\{\{([^{}]+?)\}\}/gu;
return /\{\{([^{}]+)\}\}/gu;
}

/**
Expand Down
7 changes: 3 additions & 4 deletions lib/linter/linter.js
Original file line number Diff line number Diff line change
Expand Up @@ -528,9 +528,8 @@ function getDirectiveComments(
justification: justificationPart,
} = directive;

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

if (comment.type === "Line" && !lineCommentSupported) {
return;
Expand Down Expand Up @@ -853,7 +852,7 @@ function normalizeEcmaVersionForLanguageOptions(ecmaVersion) {
return LATEST_ECMA_VERSION;
}

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

/**
* Checks whether or not there is a comment which has "eslint-env *" in a given text.
Expand Down
2 changes: 1 addition & 1 deletion lib/rules/dot-notation.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const keywords = require("./utils/keywords");
// Rule Definition
//------------------------------------------------------------------------------

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

// `null` literal must be handled separately.
const literalTypesToCheck = new Set(["string", "boolean"]);
Expand Down
2 changes: 1 addition & 1 deletion lib/rules/indent-legacy.js
Original file line number Diff line number Diff line change
Expand Up @@ -1162,7 +1162,7 @@ module.exports = {
* @returns {boolean} the result
*/
function isWrappedInParenthesis(node) {
const regex = /^return\s*?\(\s*?\);*?/u;
const regex = /^return\s*\(\s*\)/u;

const statementWithoutArgument = sourceCode
.getText(node)
Expand Down
2 changes: 1 addition & 1 deletion lib/rules/no-alert.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ const {
* @returns {boolean} Whether or not the name is prohibited.
*/
function isProhibitedIdentifier(name) {
return /^(alert|confirm|prompt)$/u.test(name);
return /^(?:alert|confirm|prompt)$/u.test(name);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion lib/rules/no-empty-function.js
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ module.exports = {
}
}

if (/(g|s)etters|methods$/iu.test(kind)) {
if (/(?:g|s)etters|methods$/iu.test(kind)) {
if (
(node.parent.decorators?.length &&
allow.includes("decoratedFunctions")) ||
Expand Down
4 changes: 2 additions & 2 deletions lib/rules/no-irregular-whitespace.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ const astUtils = require("./utils/ast-utils");
const ALL_IRREGULARS =
/[\f\v\u0085\ufeff\u00a0\u1680\u180e\u2000\u2001\u2002\u2003\u2004\u2005\u2006\u2007\u2008\u2009\u200a\u200b\u202f\u205f\u3000\u2028\u2029]/u;
const IRREGULAR_WHITESPACE =
/[\f\v\u0085\ufeff\u00a0\u1680\u180e\u2000\u2001\u2002\u2003\u2004\u2005\u2006\u2007\u2008\u2009\u200a\u200b\u202f\u205f\u3000]+/gmu;
const IRREGULAR_LINE_TERMINATORS = /[\u2028\u2029]/gmu;
/[\f\v\u0085\ufeff\u00a0\u1680\u180e\u2000\u2001\u2002\u2003\u2004\u2005\u2006\u2007\u2008\u2009\u200a\u200b\u202f\u205f\u3000]+/gu;
const IRREGULAR_LINE_TERMINATORS = /[\u2028\u2029]/gu;
const LINE_BREAK = astUtils.createGlobalLinebreakMatcher();

//------------------------------------------------------------------------------
Expand Down
1 change: 1 addition & 0 deletions lib/rules/no-mixed-spaces-and-tabs.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ module.exports = {
* At least one space followed by a tab
* before non-tab/-space characters begin.
*/
// eslint-disable-next-line regexp/no-empty-lookarounds-assertion -- False positive
regex = /^(?=(\t*))\1(?=( +))\2\t/u;
}

Expand Down
5 changes: 1 addition & 4 deletions lib/rules/no-octal.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,7 @@ module.exports = {
create(context) {
return {
Literal(node) {
if (
typeof node.value === "number" &&
/^0[0-9]/u.test(node.raw)
) {
if (typeof node.value === "number" && /^0\d/u.test(node.raw)) {
context.report({
node,
messageId: "noOctal",
Expand Down
3 changes: 2 additions & 1 deletion lib/rules/no-trailing-spaces.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,8 @@ module.exports = {
create(context) {
const sourceCode = context.sourceCode;

const BLANK_CLASS = "[ \t\u00a0\u2000-\u200b\u3000]",
const BLANK_CLASS =
"[ \t\u00a0\u2000\u2001\u2002\u2003\u2004\u2005\u2006\u2007\u2008\u2009\u200a\u200b\u3000]",
SKIP_BLANK = `^${BLANK_CLASS}*$`,
NONBLANK = `${BLANK_CLASS}+$`;

Expand Down
2 changes: 1 addition & 1 deletion lib/rules/no-useless-escape.js
Original file line number Diff line number Diff line change
Expand Up @@ -387,7 +387,7 @@ module.exports = {
const value = isTemplateElement
? sourceCode.getText(node)
: node.raw;
const pattern = /\\[^\d]/gu;
const pattern = /\\\D/gu;
let match;

while ((match = pattern.exec(value))) {
Expand Down
2 changes: 1 addition & 1 deletion lib/rules/prefer-regex-literals.js
Original file line number Diff line number Diff line change
Expand Up @@ -522,7 +522,7 @@ module.exports = {
}

if (
!/^[-a-zA-Z0-9\\[\](){} \t\r\n\v\f!@#$%^&*+^_=/~`.><?,'"|:;]*$/u.test(
!/^[-\w\\[\](){} \t\r\n\v\f!@#$%^&*+=/~`.><?,'"|:;]*$/u.test(
regexContent,
)
) {
Expand Down
2 changes: 1 addition & 1 deletion lib/rules/utils/ast-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ const DECIMAL_INTEGER_PATTERN = /^(?:0|0[0-7]*[89]\d*|[1-9](?:_?\d)*)$/u;

// Tests the presence of at least one LegacyOctalEscapeSequence or NonOctalDecimalEscapeSequence in a raw string
const OCTAL_OR_NON_OCTAL_DECIMAL_ESCAPE_PATTERN =
/^(?:[^\\]|\\.)*\\(?:[1-9]|0[0-9])/su;
/^(?:[^\\]|\\.)*\\(?:[1-9]|0\d)/su;

const LOGICAL_ASSIGNMENT_OPERATORS = new Set(["&&=", "||=", "??="]);

Expand Down
2 changes: 1 addition & 1 deletion lib/rules/utils/char-source.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ function readHexSequence(reader, length) {
* @returns {string} A code unit.
*/
function readUnicodeSequence(reader) {
const regExp = /\{(?<hexDigits>[\dA-Fa-f]+)\}/uy;
const regExp = /\{(?<hexDigits>[\dA-F]+)\}/iuy;

regExp.lastIndex = reader.pos;
const match = regExp.exec(reader.source);
Expand Down
4 changes: 2 additions & 2 deletions lib/rules/yoda.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const astUtils = require("./utils/ast-utils");
* @returns {boolean} Whether or not it is a comparison operator.
*/
function isComparisonOperator(operator) {
return /^(==|===|!=|!==|<|>|<=|>=)$/u.test(operator);
return /^(?:==|===|!=|!==|<|>|<=|>=)$/u.test(operator);
}

/**
Expand All @@ -29,7 +29,7 @@ function isComparisonOperator(operator) {
* @returns {boolean} Whether or not it is an equality operator.
*/
function isEqualityOperator(operator) {
return /^(==|===)$/u.test(operator);
return /^(?:==|===)$/u.test(operator);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion lib/shared/naming.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

"use strict";

const NAMESPACE_REGEX = /^@.*\//iu;
const NAMESPACE_REGEX = /^@.*\//u;

/**
* Brings package name to correct format based on prefix
Expand Down
10 changes: 9 additions & 1 deletion packages/eslint-config-eslint/base.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ const js = require("@eslint/js");
const jsdoc = require("eslint-plugin-jsdoc");
const eslintCommentsPluginConfigs = require("@eslint-community/eslint-plugin-eslint-comments/configs");
const unicorn = require("eslint-plugin-unicorn");
const regexp = require("eslint-plugin-regexp");

// extends eslint recommended config
/**
Expand Down Expand Up @@ -294,6 +295,12 @@ const eslintCommentsConfigs = [
},
];

// extends eslint-plugin-regexp's recommended config
/**
* @type {import("eslint").Linter.Config[]}
*/
const regexpConfigs = [regexp.configs["flat/recommended"]];

/**
* @type {import("eslint").Linter.Config[]}
*/
Expand All @@ -305,8 +312,9 @@ module.exports = [
reportUnusedInlineConfigs: "error",
},
},
...jsConfigs,
...unicornConfigs,
...jsdocConfigs,
...eslintCommentsConfigs,
...regexpConfigs,
...jsConfigs,
];
1 change: 1 addition & 0 deletions packages/eslint-config-eslint/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@
"@eslint/js": "^9.0.0",
"eslint-plugin-jsdoc": "^48.2.3",
"eslint-plugin-n": "^17.11.1",
"eslint-plugin-regexp": "^2.10.0",
"eslint-plugin-unicorn": "^52.0.0"
},
"devDependencies": {
Expand Down
6 changes: 3 additions & 3 deletions tests/lib/linter/code-path-analysis/code-path-analyzer.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ const assert = require("node:assert"),
// Helpers
//------------------------------------------------------------------------------

const expectedPattern = /\/\*expected\s+((?:.|[\r\n])+?)\s*\*\//gu;
const languageOptionsPattern = /\/\*languageOptions\s+((?:.|[\r\n])+?)\s*\*\//u;
const expectedPattern = /\/\*expected\s((?:.|[\r\n])+?)\*\//gu;
const languageOptionsPattern = /\/\*languageOptions\s((?:.|[\r\n])+?)\*\//u;
const lineEndingPattern = /\r?\n/gu;
const linter = new Linter();

Expand All @@ -39,7 +39,7 @@ function getExpectedDotArrows(source) {
let m;

while ((m = expectedPattern.exec(source)) !== null) {
retv.push(m[1].replace(lineEndingPattern, "\n"));
retv.push(m[1].trim().replace(lineEndingPattern, "\n"));
}

return retv;
Expand Down
6 changes: 3 additions & 3 deletions tests/lib/rules/utils/ast-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -2152,12 +2152,12 @@ describe("ast-utils", () => {
{
nodeA: {
type: "Literal",
value: /(?:)/u,
value: /(?:)/u, // eslint-disable-line regexp/no-empty-group -- Test data for regex comparison
regex: { pattern: "(?:)", flags: "u" },
},
nodeB: {
type: "Literal",
value: /(?:)/u,
value: /(?:)/u, // eslint-disable-line regexp/no-empty-group -- Test data for regex comparison
regex: { pattern: "(?:)", flags: "u" },
},
expected: true,
Expand All @@ -2183,7 +2183,7 @@ describe("ast-utils", () => {
},
nodeB: {
type: "Literal",
value: /(?:)/, // eslint-disable-line require-unicode-regexp -- Checking non-Unicode regex
value: /(?:)/, // eslint-disable-line require-unicode-regexp, regexp/no-empty-group -- Checking non-Unicode regex
regex: { pattern: "(?:)", flags: "" },
},
expected: false,
Expand Down
4 changes: 2 additions & 2 deletions tests/lib/shared/runtime-info.js
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ describe("RuntimeInfo", () => {

assert.throws(
RuntimeInfo.environment,
/^Unexpected token .*T.* JSON/u,
/^Unexpected token [^\n\rT\u2028\u2029]*T.* JSON/u,
);
assert.strictEqual(
logErrorStub.args[0][0],
Expand All @@ -236,7 +236,7 @@ describe("RuntimeInfo", () => {

assert.throws(
RuntimeInfo.environment,
/^Unexpected token .*T.* JSON/u,
/^Unexpected token [^\n\rT\u2028\u2029]*T.* JSON/u,
);
assert.strictEqual(
logErrorStub.args[0][0],
Expand Down
4 changes: 2 additions & 2 deletions tools/update-readme.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,15 +122,15 @@ const HTML_TEMPLATE = stripIndents`

// replace all of the section
let newReadme = readme.replace(
/<!--teamstart-->[\w\W]*?<!--teamend-->/u,
/<!--teamstart-->[\s\S]*?<!--teamend-->/u,
ejs.render(HTML_TEMPLATE, {
team,
formatTeamMembers,
}),
);

newReadme = newReadme.replace(
/<!--sponsorsstart-->[\w\W]*?<!--sponsorsend-->/u,
/<!--sponsorsstart-->[\s\S]*?<!--sponsorsend-->/u,
`<!--sponsorsstart-->\n\n${allSponsors}\n\n<!--sponsorsend-->`,
);

Expand Down
2 changes: 1 addition & 1 deletion tools/update-rule-type-headers.js
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ function getTextPositionsMap(sourceText, consideredRuleIds) {
*/
function paraphraseDescription(description) {
let newDescription;
const match = /^(Disallow|Enforce|Require) /u.exec(description);
const match = /^(?:Disallow|Enforce|Require) /u.exec(description);

if (match) {
newDescription = `Rule to ${description[0].toLowerCase()}${description.slice(1)}`;
Expand Down
Loading