Skip to content

Commit 2413d1a

Browse files
Add eslint-plugin-regexp (#16680)
1 parent e03e37f commit 2413d1a

32 files changed

Lines changed: 135 additions & 57 deletions

File tree

Gulpfile.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -837,7 +837,7 @@ gulp.task("build-vendor", async () => {
837837
{
838838
// Remove the node: prefix from imports, so that it works in old Node.js version
839839
// TODO(Babel 8): This can be removed.
840-
transform: code => code.replace(/(?<=from ["'"])node:/g, ""),
840+
transform: code => code.replace(/(?<=from ["'])node:/g, ""),
841841
},
842842
],
843843
});

Makefile.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Makefile.source.mjs

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ function print(...msgs) {
3636
console.log.apply(console, msgs);
3737
}
3838

39-
function exec(executable, args, cwd, inheritStdio = true) {
39+
function exec(executable, args, cwd, inheritStdio = true, noExit = false) {
4040
print(
4141
`${executable
4242
.replaceAll(YARN_PATH, "yarn")
@@ -56,15 +56,17 @@ function exec(executable, args, cwd, inheritStdio = true) {
5656
`\ncommand: ${executable} ${args.join(" ")}\ncode: ${error.exitCode}`
5757
)
5858
);
59-
// eslint-disable-next-line no-process-exit
60-
process.exit(error.exitCode);
59+
if (!noExit) {
60+
// eslint-disable-next-line no-process-exit
61+
process.exit(error.exitCode);
62+
}
6163
}
6264
throw error;
6365
}
6466
}
6567

66-
function yarn(args, cwd, inheritStdio) {
67-
return exec(YARN_PATH, args, cwd, inheritStdio);
68+
function yarn(args, cwd, inheritStdio, noExit) {
69+
return exec(YARN_PATH, args, cwd, inheritStdio, noExit);
6870
}
6971

7072
function node(args, cwd, inheritStdio) {
@@ -382,11 +384,25 @@ function eslint(...extraArgs) {
382384
NODE_OPTIONS: "--max-old-space-size=16384",
383385
});
384386
} else {
387+
let err = null;
385388
for (const chunk of chunks) {
386-
env(() => yarn(["eslint", ...chunk, ...eslintArgs]), {
387-
BABEL_ENV: "test",
388-
});
389+
try {
390+
env(
391+
() =>
392+
yarn(
393+
["eslint", ...chunk, ...eslintArgs],
394+
undefined,
395+
undefined,
396+
true
397+
),
398+
{ BABEL_ENV: "test" }
399+
);
400+
} catch (e) {
401+
err = e;
402+
}
389403
}
404+
// eslint-disable-next-line no-process-exit
405+
if (err) process.exit(err.exitCode);
390406
}
391407
}
392408

eslint.config.mjs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import configInternal from "@babel/eslint-config-internal";
55
import pluginImport from "eslint-plugin-import";
66
import pluginN from "eslint-plugin-n";
77
import pluginPrettier from "eslint-plugin-prettier";
8+
import pluginRegexp from "eslint-plugin-regexp";
89
import pluginBabelDevelopment from "@babel/eslint-plugin-development";
910
import pluginBabelDevelopmentInternal from "@babel/eslint-plugin-development-internal";
1011
import typescriptEslint from "typescript-eslint";
@@ -33,6 +34,7 @@ const sourceFiles = exts => [
3334

3435
export default [
3536
...configInternal,
37+
pluginRegexp.configs["flat/recommended"],
3638
{
3739
ignores: [
3840
"/lib",
@@ -76,6 +78,7 @@ export default [
7678
rules: {
7779
"prettier/prettier": "error",
7880
"import/no-extraneous-dependencies": "error",
81+
"regexp/match-any": ["error", { allows: ["[^]", "dotAll"] }],
7982
},
8083
},
8184
...typescriptEslint.config({

eslint/babel-eslint-plugin-development-internal/src/rules/report-error-message-format.cjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
const messageId = "mustMatchPattern";
22

3-
const pattern = /(('.*')|(`.*`)|[A-Z]).*(\.|\?)$/s;
3+
const pattern = /(?:('|`)[^'`]*\1|[A-Z]).*[.?]$/s;
44

55
module.exports = {
66
meta: {

eslint/babel-eslint-plugin-development-internal/src/rules/require-default-import-fallback.cjs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@ module.exports = {
2121
// This will not become an ESM file.
2222
src.endsWith(".cjs") ||
2323
// @babel/core automatically unwraps .default from plugins/presets.
24-
/^@babel\/(plugin|preset)-/.test(src) ||
24+
/^@babel\/(?:plugin|preset)-/.test(src) ||
2525
(src.endsWith("./lib/index.js") &&
26-
/babel-(plugin|preset)-/.test(filename))
26+
/babel-(?:plugin|preset)-/.test(filename))
2727
) {
2828
return;
2929
}

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@
5959
"eslint-plugin-jest": "^27.9.0",
6060
"eslint-plugin-n": "^17.9.0",
6161
"eslint-plugin-prettier": "^5.1.3",
62+
"eslint-plugin-regexp": "^2.6.0",
6263
"execa": "^9.0.0",
6364
"glob": "^10.3.10",
6465
"gulp": "^5.0.0",

packages/babel-core/src/config/files/configuration.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ const readIgnoreConfig = makeStaticFileCache((filepath, content) => {
188188
const ignoreDir = path.dirname(filepath);
189189
const ignorePatterns = content
190190
.split("\n")
191-
.map<string>(line => line.replace(/#(.*?)$/, "").trim())
191+
.map<string>(line => line.replace(/#.*$/, "").trim())
192192
.filter(line => !!line);
193193

194194
for (const pattern of ignorePatterns) {

packages/babel-core/src/transformation/normalize-file.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ const debug = buildDebug("babel:transform:file");
1717
// but without // or /* at the beginning of the comment.
1818

1919
const INLINE_SOURCEMAP_REGEX =
20-
/^[@#]\s+sourceMappingURL=data:(?:application|text)\/json;(?:charset[:=]\S+?;)?base64,(?:.*)$/;
20+
/^[@#]\s+sourceMappingURL=data:(?:application|text)\/json;(?:charset[:=]\S+?;)?base64,.*$/;
2121
const EXTERNAL_SOURCEMAP_REGEX =
2222
/^[@#][ \t]+sourceMappingURL=([^\s'"`]+)[ \t]*$/;
2323

packages/babel-core/test/errors-stacks.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ function expectError(run) {
2727
// visible when using --run-in-band, comes from inside jest but doesn't have an
2828
// associated file path.
2929
stack = stack.replace(
30-
/(?:\n\s*at [^\n]+?node_modules\/(?:@?jest|tinypool|piscina)[^\n]+|\n\s*at async Promise.all[^\n]+)+/g,
30+
/(?:\n\s*at (?:[^\n]+?node_modules\/(?:@?jest|tinypool|piscina)|\n\s*at async Promise.all)[^\n]+)+/g,
3131
"\n at ... internal jest frames ...",
3232
);
3333
// Remove node internal frames, since they change by version

0 commit comments

Comments
 (0)