Skip to content

Commit 5018378

Browse files
Chore: enable require-unicode-regexp on ESLint codebase (#11422)
1 parent f6ba633 commit 5018378

114 files changed

Lines changed: 310 additions & 308 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

Makefile.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ const { cat, cd, cp, echo, exec, exit, find, ls, mkdir, pwd, rm, test } = requir
4242
const PERF_MULTIPLIER = 13e6;
4343

4444
const OPEN_SOURCE_LICENSES = [
45-
/MIT/, /BSD/, /Apache/, /ISC/, /WTF/, /Public Domain/, /LGPL/
45+
/MIT/u, /BSD/u, /Apache/u, /ISC/u, /WTF/u, /Public Domain/u, /LGPL/u
4646
];
4747

4848
//------------------------------------------------------------------------------
@@ -135,7 +135,7 @@ function generateBlogPost(releaseInfo, prereleaseMajorVersion) {
135135
const ruleList = ls("lib/rules")
136136

137137
// Strip the .js extension
138-
.map(ruleFileName => ruleFileName.replace(/\.js$/, ""))
138+
.map(ruleFileName => ruleFileName.replace(/\.js$/u, ""))
139139

140140
/*
141141
* Sort by length descending. This ensures that rule names which are substrings of other rule names are not
@@ -699,7 +699,7 @@ target.gensite = function(prereleaseVersion) {
699699
} else {
700700

701701
// extract the title from the file itself
702-
title = text.match(/#([^#].+)\n/);
702+
title = text.match(/#([^#].+)\n/u);
703703
if (title) {
704704
title = title[1].trim();
705705
} else {
@@ -720,10 +720,10 @@ target.gensite = function(prereleaseVersion) {
720720
].join("\n");
721721

722722
// 6. Remove .md extension for relative links and change README to empty string
723-
text = text.replace(/\((?!https?:\/\/)([^)]*?)\.md(.*?)\)/g, "($1$2)").replace("README.html", "");
723+
text = text.replace(/\((?!https?:\/\/)([^)]*?)\.md(.*?)\)/gu, "($1$2)").replace("README.html", "");
724724

725725
// 7. Check if there's a trailing white line at the end of the file, if there isn't one, add it
726-
if (!/\n$/.test(text)) {
726+
if (!/\n$/u.test(text)) {
727727
text = `${text}\n`;
728728
}
729729

@@ -827,8 +827,8 @@ target.checkRuleFiles = function() {
827827
*/
828828
function hasIdInTitle(id) {
829829
const docText = cat(docFilename);
830-
const idOldAtEndOfTitleRegExp = new RegExp(`^# (.*?) \\(${id}\\)`); // original format
831-
const idNewAtBeginningOfTitleRegExp = new RegExp(`^# ${id}: `); // new format is same as rules index
830+
const idOldAtEndOfTitleRegExp = new RegExp(`^# (.*?) \\(${id}\\)`, "u"); // original format
831+
const idNewAtBeginningOfTitleRegExp = new RegExp(`^# ${id}: `, "u"); // new format is same as rules index
832832
/*
833833
* 1. Added support for new format.
834834
* 2. Will remove support for old format after all docs files have new format.

lib/cli-engine.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,7 @@ function processFile(filename, configHelper, options, linter) {
258258
*/
259259
function createIgnoreResult(filePath, baseDir) {
260260
let message;
261-
const isHidden = /^\./.test(path.basename(filePath));
261+
const isHidden = /^\./u.test(path.basename(filePath));
262262
const isInNodeModules = baseDir && path.relative(baseDir, filePath).startsWith("node_modules");
263263
const isInBowerComponents = baseDir && path.relative(baseDir, filePath).startsWith("bower_components");
264264

@@ -757,7 +757,7 @@ class CLIEngine {
757757
if (typeof resolvedFormatName === "string") {
758758

759759
// replace \ with / for Windows compatibility
760-
const normalizedFormatName = resolvedFormatName.replace(/\\/g, "/");
760+
const normalizedFormatName = resolvedFormatName.replace(/\\/gu, "/");
761761

762762
const cwd = this.options ? this.options.cwd : process.cwd();
763763
const namespace = naming.getNamespaceFromTerm(normalizedFormatName);

lib/config/config-file.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ const resolver = new ModuleResolver();
6161
* @private
6262
*/
6363
function readFile(filePath) {
64-
return fs.readFileSync(filePath, "utf8").replace(/^\ufeff/, "");
64+
return fs.readFileSync(filePath, "utf8").replace(/^\ufeff/u, "");
6565
}
6666

6767
/**
@@ -73,7 +73,7 @@ function readFile(filePath) {
7373
* @private
7474
*/
7575
function isFilePath(filePath) {
76-
return path.isAbsolute(filePath) || !/\w|@/.test(filePath.charAt(0));
76+
return path.isAbsolute(filePath) || !/\w|@/u.test(filePath.charAt(0));
7777
}
7878

7979
/**

lib/config/config-initializer.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ function configureRules(answers, config) {
152152
bar.tick(0); // Shows the progress bar
153153

154154
// Get the SourceCode of all chosen files
155-
const patterns = answers.patterns.split(/[\s]+/);
155+
const patterns = answers.patterns.split(/[\s]+/u);
156156

157157
try {
158158
sourceCodes = getSourceCodeOfFiles(patterns, { baseConfig: newConfig, useEslintrc: false }, total => {

lib/config/config-validator.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ function validateRuleSeverity(options) {
7676
return normSeverity;
7777
}
7878

79-
throw new Error(`\tSeverity should be one of the following: 0 = off, 1 = warn, 2 = error (you passed '${util.inspect(severity).replace(/'/g, "\"").replace(/\n/g, "")}').\n`);
79+
throw new Error(`\tSeverity should be one of the following: 0 = off, 1 = warn, 2 = error (you passed '${util.inspect(severity).replace(/'/gu, "\"").replace(/\n/gu, "")}').\n`);
8080

8181
}
8282

lib/config/plugins.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ class Plugins {
8484
const shortName = naming.getShorthandName(longName, "eslint-plugin");
8585
let plugin = null;
8686

87-
if (pluginName.match(/\s+/)) {
87+
if (pluginName.match(/\s+/u)) {
8888
const whitespaceError = new Error(`Whitespace found in plugin name '${pluginName}'`);
8989

9090
whitespaceError.messageTemplate = "whitespace-found";

lib/formatters/codeframe.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ function formatFilePath(filePath, line, column) {
4747
*/
4848
function formatMessage(message, parentResult) {
4949
const type = (message.fatal || message.severity === 2) ? chalk.red("error") : chalk.yellow("warning");
50-
const msg = `${chalk.bold(message.message.replace(/([^ ])\.$/, "$1"))}`;
50+
const msg = `${chalk.bold(message.message.replace(/([^ ])\.$/u, "$1"))}`;
5151
const ruleId = message.fatal ? "" : chalk.dim(`(${message.ruleId})`);
5252
const filePath = formatFilePath(parentResult.filePath, message.line, message.column);
5353
const sourceCode = parentResult.output ? parentResult.output : parentResult.source;

lib/formatters/stylish.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ module.exports = function(results) {
6565
message.line || 0,
6666
message.column || 0,
6767
messageType,
68-
message.message.replace(/([^ ])\.$/, "$1"),
68+
message.message.replace(/([^ ])\.$/u, "$1"),
6969
chalk.dim(message.ruleId || "")
7070
];
7171
}),
@@ -75,7 +75,7 @@ module.exports = function(results) {
7575
return stripAnsi(str).length;
7676
}
7777
}
78-
).split("\n").map(el => el.replace(/(\d+)\s+(\d+)/, (m, p1, p2) => chalk.dim(`${p1}:${p2}`))).join("\n")}\n\n`;
78+
).split("\n").map(el => el.replace(/(\d+)\s+(\d+)/u, (m, p1, p2) => chalk.dim(`${p1}:${p2}`))).join("\n")}\n\n`;
7979
});
8080

8181
const total = errorCount + warningCount;

lib/linter.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -164,15 +164,15 @@ function getDirectiveComments(filename, ast, ruleMapper) {
164164

165165
ast.comments.filter(token => token.type !== "Shebang").forEach(comment => {
166166
const trimmedCommentText = comment.value.trim();
167-
const match = /^(eslint(-\w+){0,3}|exported|globals?)(\s|$)/.exec(trimmedCommentText);
167+
const match = /^(eslint(-\w+){0,3}|exported|globals?)(\s|$)/u.exec(trimmedCommentText);
168168

169169
if (!match) {
170170
return;
171171
}
172172

173173
const directiveValue = trimmedCommentText.slice(match.index + match[1].length);
174174

175-
if (/^eslint-disable-(next-)?line$/.test(match[1])) {
175+
if (/^eslint-disable-(next-)?line$/u.test(match[1])) {
176176
if (comment.loc.start.line === comment.loc.end.line) {
177177
const directiveType = match[1].slice("eslint-".length);
178178

@@ -276,7 +276,7 @@ function normalizeEcmaVersion(ecmaVersion, isModule) {
276276
return ecmaVersion;
277277
}
278278

279-
const eslintEnvPattern = /\/\*\s*eslint-env\s(.+?)\*\//g;
279+
const eslintEnvPattern = /\/\*\s*eslint-env\s(.+?)\*\//gu;
280280

281281
/**
282282
* Checks whether or not there is a comment which has "eslint-env *" in a given text.
@@ -498,7 +498,7 @@ function parse(text, providedParserOptions, parserName, parserMap, filePath) {
498498
} catch (ex) {
499499

500500
// If the message includes a leading line number, strip it:
501-
const message = `Parsing error: ${ex.message.replace(/^line \d+:/i, "").trim()}`;
501+
const message = `Parsing error: ${ex.message.replace(/^line \d+:/iu, "").trim()}`;
502502

503503
return {
504504
success: false,

lib/rules/array-callback-return.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ const astUtils = require("../util/ast-utils");
1717
// Helpers
1818
//------------------------------------------------------------------------------
1919

20-
const TARGET_NODE_TYPE = /^(?:Arrow)?FunctionExpression$/;
21-
const TARGET_METHODS = /^(?:every|filter|find(?:Index)?|map|reduce(?:Right)?|some|sort)$/;
20+
const TARGET_NODE_TYPE = /^(?:Arrow)?FunctionExpression$/u;
21+
const TARGET_METHODS = /^(?:every|filter|find(?:Index)?|map|reduce(?:Right)?|some|sort)$/u;
2222

2323
/**
2424
* Checks a given code path segment is reachable.

0 commit comments

Comments
 (0)