Skip to content

Commit 7648500

Browse files
test: run js tests with @babel/eslint-parser (#569)
1 parent dce4c01 commit 7648500

File tree

10 files changed

+135
-6
lines changed

10 files changed

+135
-6
lines changed

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,8 @@
7676
},
7777
"devDependencies": {
7878
"@ava/typescript": "3.0.1",
79+
"@babel/core": "^7.21.0",
80+
"@babel/eslint-parser": "^7.19.1",
7981
"@commitlint/cli": "17.4.4",
8082
"@commitlint/config-conventional": "17.4.4",
8183
"@cspell/dict-cryptocurrencies": "3.0.1",

pnpm-lock.yaml

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

tests/helpers/configs.ts

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import type { Linter } from "eslint";
55
export const filename = path.join(__dirname, "file.ts");
66

77
const typescriptParser = "@typescript-eslint/parser";
8-
const babelParser = typescriptParser; // Switch to "babel-eslint" once https://github.com/babel/babel/issues/13712 is fixed;
8+
const babelParser = "@babel/eslint-parser";
99
const espreeParser = "espree";
1010

1111
export const configs = {
@@ -21,41 +21,71 @@ export const configs = {
2121
parser: require.resolve(babelParser),
2222
parserOptions: {
2323
ecmaVersion: 11,
24+
requireConfigFile: false,
25+
babelOptions: {
26+
babelrc: false,
27+
configFile: false,
28+
},
2429
},
2530
} as Linter.Config,
2631

2732
es10: {
2833
parser: require.resolve(babelParser),
2934
parserOptions: {
3035
ecmaVersion: 10,
36+
requireConfigFile: false,
37+
babelOptions: {
38+
babelrc: false,
39+
configFile: false,
40+
},
3141
},
3242
} as Linter.Config,
3343

3444
es9: {
3545
parser: require.resolve(babelParser),
3646
parserOptions: {
3747
ecmaVersion: 9,
48+
requireConfigFile: false,
49+
babelOptions: {
50+
babelrc: false,
51+
configFile: false,
52+
},
3853
},
3954
} as Linter.Config,
4055

4156
es8: {
4257
parser: require.resolve(babelParser),
4358
parserOptions: {
4459
ecmaVersion: 8,
60+
requireConfigFile: false,
61+
babelOptions: {
62+
babelrc: false,
63+
configFile: false,
64+
},
4565
},
4666
} as Linter.Config,
4767

4868
es7: {
4969
parser: require.resolve(babelParser),
5070
parserOptions: {
5171
ecmaVersion: 7,
72+
requireConfigFile: false,
73+
babelOptions: {
74+
babelrc: false,
75+
configFile: false,
76+
},
5277
},
5378
} as Linter.Config,
5479

5580
es6: {
5681
parser: require.resolve(babelParser),
5782
parserOptions: {
5883
ecmaVersion: 6,
84+
requireConfigFile: false,
85+
babelOptions: {
86+
babelrc: false,
87+
configFile: false,
88+
},
5989
},
6090
} as Linter.Config,
6191

tests/rules/immutable-data/es6/object/invalid.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ const tests: InvalidTestCase[] = [
2323
code: dedent`
2424
class Klass {
2525
bar = 1;
26-
baz: string;
2726
2827
constructor() {
2928
this.baz = "hello";
@@ -40,13 +39,13 @@ const tests: InvalidTestCase[] = [
4039
{
4140
messageId: "generic",
4241
type: "AssignmentExpression",
43-
line: 10,
42+
line: 9,
4443
column: 5,
4544
},
4645
{
4746
messageId: "generic",
4847
type: "AssignmentExpression",
49-
line: 11,
48+
line: 10,
5049
column: 5,
5150
},
5251
],

tests/rules/immutable-data/es6/object/valid.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ const tests: ValidTestCase[] = [
88
code: dedent`
99
class Klass {
1010
bar = 1;
11-
baz: string;
1211
constructor() {
1312
this.baz = "hello";
1413
}
@@ -35,7 +34,6 @@ const tests: ValidTestCase[] = [
3534
{
3635
code: dedent`
3736
class Klass {
38-
baz: string;
3937
mutate() {
4038
this.baz = "hello";
4139
}

tests/rules/immutable-data/index.test.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@ import { testUsing } from "~/tests/helpers/testers";
33

44
import es3Tests from "./es3";
55
import es6Tests from "./es6";
6+
import tsTests from "./ts";
67

8+
testUsing.typescript(name, rule, tsTests);
79
testUsing.typescript(name, rule, es6Tests);
810
testUsing.typescript(name, rule, es3Tests);
911

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import object from "./object";
2+
3+
export default {
4+
valid: [...object.valid],
5+
invalid: [...object.invalid],
6+
};
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import invalid from "./invalid";
2+
import valid from "./valid";
3+
4+
export default {
5+
valid,
6+
invalid,
7+
};
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import dedent from "dedent";
2+
3+
import type { InvalidTestCase } from "~/tests/helpers/util";
4+
5+
const tests: InvalidTestCase[] = [
6+
{
7+
code: dedent`
8+
class Klass {
9+
bar = 1;
10+
baz: string;
11+
12+
constructor() {
13+
this.baz = "hello";
14+
}
15+
16+
zoo() {
17+
this.bar = 2;
18+
this.baz = 3;
19+
}
20+
}
21+
`,
22+
optionsSet: [[]],
23+
errors: [
24+
{
25+
messageId: "generic",
26+
type: "AssignmentExpression",
27+
line: 10,
28+
column: 5,
29+
},
30+
{
31+
messageId: "generic",
32+
type: "AssignmentExpression",
33+
line: 11,
34+
column: 5,
35+
},
36+
],
37+
},
38+
];
39+
40+
export default tests;
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import dedent from "dedent";
2+
3+
import type { ValidTestCase } from "~/tests/helpers/util";
4+
5+
const tests: ValidTestCase[] = [
6+
// Allow initialization of class members in constructor
7+
{
8+
code: dedent`
9+
class Klass {
10+
bar = 1;
11+
baz: string;
12+
constructor() {
13+
this.baz = "hello";
14+
}
15+
}
16+
`,
17+
optionsSet: [[]],
18+
},
19+
];
20+
21+
export default tests;

0 commit comments

Comments
 (0)