Skip to content

Commit b23b0eb

Browse files
authored
Fix eslint-plugin-jest config (#15826)
* extend eslint-plugin-jest rules only when it is defined * fix linting errors * enable jest/no-identical-title
1 parent 078d59a commit b23b0eb

File tree

15 files changed

+85
-79
lines changed

15 files changed

+85
-79
lines changed

eslint.config.js

+19-16
Original file line numberDiff line numberDiff line change
@@ -177,22 +177,25 @@ module.exports = [
177177
},
178178
},
179179
...compat.extends("plugin:jest/recommended").map(config => {
180-
config.files = [
181-
...testFiles,
182-
"packages/babel-helper-transform-fixture-test-runner/src/helpers.{ts,js}",
183-
"test/**/*.js",
184-
];
185-
config.rules = {
186-
...config.rules,
187-
"jest/expect-expect": "off",
188-
"jest/no-identical-title": "off",
189-
"jest/no-standalone-expect": "off",
190-
"jest/no-test-callback": "off",
191-
"jest/valid-describe": "off",
192-
"import/extensions": ["error", "always"],
193-
"import/no-extraneous-dependencies": "off",
194-
"no-restricted-imports": ["error", { patterns: ["**/src/**"] }],
195-
};
180+
if (config.files == null) {
181+
config.files = [
182+
...testFiles,
183+
"packages/babel-helper-transform-fixture-test-runner/src/helpers.{ts,js}",
184+
"test/**/*.js",
185+
];
186+
}
187+
if (config.rules != null) {
188+
config.rules = {
189+
...config.rules,
190+
"jest/expect-expect": "off",
191+
"jest/no-standalone-expect": "off",
192+
"jest/no-test-callback": "off",
193+
"jest/valid-describe": "off",
194+
"import/extensions": ["error", "always"],
195+
"import/no-extraneous-dependencies": "off",
196+
"no-restricted-imports": ["error", { patterns: ["**/src/**"] }],
197+
};
198+
}
196199
return config;
197200
}),
198201
{

eslint/babel-eslint-parser/test/index.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -699,7 +699,7 @@ describe("Babel and Espree", () => {
699699
parseAndAssertSame("/affix-top|affix-bottom|affix|[a-z]/");
700700
});
701701

702-
it("regexp", () => {
702+
it("regexp without flag", () => {
703703
parseAndAssertSame("const foo = /foo/;");
704704
});
705705

@@ -893,7 +893,7 @@ describe("Babel and Espree", () => {
893893
}).not.toThrow();
894894
});
895895
} else {
896-
it("super outside method", () => {
896+
it("super outside method in Babel 7", () => {
897897
expect(() => {
898898
parseForESLint("function F() { super(); }", {
899899
babelOptions: BABEL_OPTIONS,

eslint/babel-eslint-tests/test/integration/eslint/verify.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -1282,14 +1282,14 @@ describe("verify", () => {
12821282
);
12831283
});
12841284

1285-
it("does not mark spread variables false-positive", () => {
1285+
it("does not mark spread variables false-positive: multiple destructuring bindings", () => {
12861286
verifyAndAssertMessages(
12871287
"var originalObject = {}; var {field1, field2, ...clone} = originalObject;",
12881288
{ "no-undef": 1, "no-redeclare": 1 },
12891289
);
12901290
});
12911291

1292-
it("does not mark spread variables false-positive", () => {
1292+
it("does not mark spread variables false-positive: single destructuring binding", () => {
12931293
verifyAndAssertMessages(
12941294
"const props = { yo: 'yo' }; const { ...otherProps } = props;",
12951295
{ "no-undef": 1, "no-redeclare": 1 },

packages/babel-code-frame/test/index.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ describe("@babel/code-frame", function () {
3939
chalk.enabled = originalChalkEnabled;
4040
babelHighlightChalk.supportsColor = originalHighlightChalkSupportsColor;
4141
babelHighlightChalk.level = originalHighlightChalkLevel;
42-
babelHighlightChalk.enabled = originalChalkEnabled;
42+
babelHighlightChalk.enabled = originalHighlightChalkEnabled;
4343
});
4444
}
4545

packages/babel-core/test/option-manager.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -205,15 +205,15 @@ describe("option-manager", () => {
205205
});
206206

207207
describe("mergeOptions", () => {
208-
it("throws for removed babel 5 options", () => {
208+
it("throws for removed babel 5 options: randomOption", () => {
209209
return expect(() => {
210210
loadOptions({
211211
randomOption: true,
212212
});
213213
}).toThrow(/Unknown option: .randomOption/);
214214
});
215215

216-
it("throws for removed babel 5 options", () => {
216+
it("throws for removed babel 5 options: auxiliaryComment", () => {
217217
return expect(() => {
218218
loadOptions({
219219
auxiliaryComment: true,

packages/babel-core/test/resolution.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ describe("addon resolution", function () {
109109
});
110110
});
111111

112-
it("should find @babel scoped plugins", function () {
112+
it("should find @babel scoped plugins with an existing prefix", function () {
113113
process.chdir("babel-org-paths");
114114

115115
babel.transformSync("", {

packages/babel-highlight/test/index.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -95,8 +95,8 @@ describe("@babel/highlight", function () {
9595
});
9696

9797
describeBabel7NoESM("getChalk", function () {
98-
let getChalk;
99-
beforeAll(() => {
98+
let getChalk;
99+
beforeAll(() => {
100100
({ getChalk } = require("../lib/index.js"));
101101
});
102102

packages/babel-plugin-syntax-decorators/test/index.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ const babel8 = process.env.BABEL_8_BREAKING ? test : test.skip;
1414
const babel7describe = process.env.BABEL_8_BREAKING ? describe.skip : describe;
1515

1616
babel7describe("'legacy' option", function () {
17-
test("must be boolean", function () {
17+
test("legacy must be boolean", function () {
1818
expect(makeParser("", { legacy: "legacy" })).toThrow();
1919
});
2020

@@ -32,7 +32,7 @@ babel7describe("'legacy' option", function () {
3232
});
3333

3434
babel7describe("'decoratorsBeforeExport' option", function () {
35-
test("must be boolean", function () {
35+
test("decoratorsBeforeExport must be boolean", function () {
3636
expect(
3737
makeParser("", { version: "2021-12", decoratorsBeforeExport: "before" }),
3838
).toThrow();

packages/babel-preset-env/test/index.skip-bundled.js

+37-40
Original file line numberDiff line numberDiff line change
@@ -110,17 +110,17 @@ describe("babel-preset-env", () => {
110110
shouldTransformDynamicImport: false,
111111
shouldTransformExportNamespaceFrom: false,
112112
});
113-
if (process.env.BABEL_8_BREAKING) {
114-
expect(names).toEqual(["transform-modules-commonjs"]);
115-
} else {
116-
expect(names).toEqual([
117-
"transform-modules-commonjs",
118-
"syntax-dynamic-import",
119-
"syntax-export-namespace-from",
120-
"syntax-top-level-await",
121-
"syntax-import-meta",
122-
]);
123-
}
113+
expect(names).toEqual(
114+
process.env.BABEL_8_BREAKING
115+
? ["transform-modules-commonjs"]
116+
: [
117+
"transform-modules-commonjs",
118+
"syntax-dynamic-import",
119+
"syntax-export-namespace-from",
120+
"syntax-top-level-await",
121+
"syntax-import-meta",
122+
],
123+
);
124124
});
125125
});
126126
describe("dynamic imports should be transformed", () => {
@@ -132,20 +132,17 @@ describe("babel-preset-env", () => {
132132
shouldTransformDynamicImport: true,
133133
shouldTransformExportNamespaceFrom: false,
134134
});
135-
if (process.env.BABEL_8_BREAKING) {
136-
expect(names).toEqual([
137-
"transform-modules-systemjs",
138-
"transform-dynamic-import",
139-
]);
140-
} else {
141-
expect(names).toEqual([
142-
"transform-modules-systemjs",
143-
"transform-dynamic-import",
144-
"syntax-export-namespace-from",
145-
"syntax-top-level-await",
146-
"syntax-import-meta",
147-
]);
148-
}
135+
expect(names).toEqual(
136+
process.env.BABEL_8_BREAKING
137+
? ["transform-modules-systemjs", "transform-dynamic-import"]
138+
: [
139+
"transform-modules-systemjs",
140+
"transform-dynamic-import",
141+
"syntax-export-namespace-from",
142+
"syntax-top-level-await",
143+
"syntax-import-meta",
144+
],
145+
);
149146
});
150147
describe("export namespace from should be transformed", () => {
151148
it("works", () => {
@@ -156,21 +153,21 @@ describe("babel-preset-env", () => {
156153
shouldTransformDynamicImport: true,
157154
shouldTransformExportNamespaceFrom: true,
158155
});
159-
if (process.env.BABEL_8_BREAKING) {
160-
expect(names).toEqual([
161-
"transform-modules-systemjs",
162-
"transform-dynamic-import",
163-
"transform-export-namespace-from",
164-
]);
165-
} else {
166-
expect(names).toEqual([
167-
"transform-modules-systemjs",
168-
"transform-dynamic-import",
169-
"transform-export-namespace-from",
170-
"syntax-top-level-await",
171-
"syntax-import-meta",
172-
]);
173-
}
156+
expect(names).toEqual(
157+
process.env.BABEL_8_BREAKING
158+
? [
159+
"transform-modules-systemjs",
160+
"transform-dynamic-import",
161+
"transform-export-namespace-from",
162+
]
163+
: [
164+
"transform-modules-systemjs",
165+
"transform-dynamic-import",
166+
"transform-export-namespace-from",
167+
"syntax-top-level-await",
168+
"syntax-import-meta",
169+
],
170+
);
174171
});
175172
});
176173
});

packages/babel-preset-env/test/normalize-options.skip-bundled.js

+10-4
Original file line numberDiff line numberDiff line change
@@ -113,15 +113,21 @@ describe("normalize-options", () => {
113113

114114
describe("RegExp include/exclude", () => {
115115
it("should not allow invalid plugins in `include` and `exclude`", () => {
116-
const normalizeWithNonExistingPlugin = () => {
116+
const normalizeIncludeWithNonExistingPlugin = () => {
117117
normalizeOptions({
118118
include: ["non-existing-plugin"],
119119
});
120120
};
121-
expect(normalizeWithNonExistingPlugin).toThrow(Error);
121+
const normalizeExcludeWithNonExistingPlugin = () => {
122+
normalizeOptions({
123+
exclude: ["non-existing-plugin"],
124+
});
125+
};
126+
expect(normalizeIncludeWithNonExistingPlugin).toThrow(Error);
127+
expect(normalizeExcludeWithNonExistingPlugin).toThrow(Error);
122128
});
123129

124-
it("should expand regular expressions in `include` and `exclude`", () => {
130+
it("should expand regular expressions in `include`", () => {
125131
const normalized = normalizeOptions({
126132
include: ["^[a-z]*-spread", "babel-plugin-transform-classes"],
127133
});
@@ -131,7 +137,7 @@ describe("normalize-options", () => {
131137
]);
132138
});
133139

134-
it("should expand regular expressions in `include` and `exclude`", () => {
140+
it("should expand regular expressions in `exclude`", () => {
135141
const normalized = normalizeOptions({
136142
useBuiltIns: "entry",
137143
corejs: 3,

packages/babel-preset-flow/test/normalize-options.skip-bundled.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ describe("normalize options", () => {
4444
expect(() => normalizeOptions({ [optionName]: 0 })).not.toThrow();
4545
},
4646
);
47-
it("default values", () => {
47+
it("default values in Babel 7", () => {
4848
expect(normalizeOptions({})).toMatchInlineSnapshot(`
4949
Object {
5050
"all": undefined,

packages/babel-preset-react/test/normalize-options.skip-bundled.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ describe("normalize options", () => {
9696
expect(() => normalizeOptions({ [optionName]: 0 })).not.toThrow();
9797
},
9898
);
99-
it("default values", () => {
99+
it("default values in Babel 7", () => {
100100
expect(normalizeOptions({})).toMatchInlineSnapshot(`
101101
Object {
102102
"development": false,

packages/babel-preset-typescript/test/normalize-options.skip-bundled.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ describe("normalize options", () => {
8383
);
8484
},
8585
);
86-
it("default values", () => {
86+
it("default values in Babel 7", () => {
8787
expect(normalizeOptions({})).toMatchInlineSnapshot(`
8888
Object {
8989
"allExtensions": false,

packages/babel-traverse/test/conversion.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -46,15 +46,15 @@ describe("conversion", function () {
4646
expect(generateCode(rootPath)).toBe("() => {\n return true;\n};");
4747
});
4848

49-
it("preserves arrow function body's context", function () {
49+
it("preserves arrow function body's context when replaced with a boolean literal", function () {
5050
const rootPath = getPath("() => true").get("expression");
5151
const body = rootPath.get("body");
5252
rootPath.ensureBlock();
5353
body.replaceWith(t.booleanLiteral(false));
5454
expect(generateCode(rootPath)).toBe("() => {\n return false;\n};");
5555
});
5656

57-
it("preserves arrow function body's context", function () {
57+
it("preserves arrow function body's context when replace with multiple nodes", function () {
5858
const rootPath = getPath("() => true").get("expression");
5959
const body = rootPath.get("body");
6060
rootPath.ensureBlock();

packages/babel-types/test/builders/typescript/tsTypeParameter.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ describe("builders", function () {
5252
(process.env.BABEL_8_BREAKING ? describe.skip : describe)(
5353
"tsTypeParameter - Babel 7",
5454
function () {
55-
it("accept name as argument for tsTypeParameter", function () {
55+
it("accept name as argument for tsTypeParameter in Babel 7", function () {
5656
const tsTypeParameter = t.tsTypeParameter(
5757
t.tsTypeReference(t.identifier("bar")),
5858
t.tsTypeReference(t.identifier("baz")),
@@ -81,7 +81,7 @@ describe("builders", function () {
8181
}
8282
`);
8383
});
84-
it("throws when name is missing", function () {
84+
it("throws when name is missing in Babel 7", function () {
8585
expect(() => {
8686
t.tsTypeParameter(
8787
t.tsTypeReference(t.identifier("bar")),

0 commit comments

Comments
 (0)