Skip to content

Commit 5cd2faa

Browse files
committed
[Tests] strip 'type:' from RuleTester errors on eslint >= 10 via helper
Instead of removing `type:` from each test file, wrapping the invalid test cases in `tests/helpers/ruleTester.js` to strip `type` when the running ESLint is >= 10. On older versions the function does nothing, keeping all `type:` assertions intact.
1 parent 450930b commit 5cd2faa

1 file changed

Lines changed: 21 additions & 1 deletion

File tree

tests/helpers/ruleTester.js

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,24 @@ function convertToFlat(item, plugins) {
4747
return newItem;
4848
}
4949

50+
const stripTypeOnEslint10 = semver.major(eslintPkg.version) >= 10
51+
? (test) => {
52+
if (!test || typeof test !== 'object' || !Array.isArray(test.errors)) {
53+
return test;
54+
}
55+
return Object.assign({}, test, {
56+
errors: test.errors.map((err) => {
57+
if (!err || typeof err !== 'object' || !('type' in err)) {
58+
return err;
59+
}
60+
const next = Object.assign({}, err);
61+
delete next.type;
62+
return next;
63+
}),
64+
});
65+
}
66+
: (test) => test;
67+
5068
let RuleTester = ESLintRuleTester;
5169

5270
if (semver.major(eslintPkg.version) >= 9) {
@@ -98,7 +116,9 @@ if (semver.major(eslintPkg.version) >= 9) {
98116
run(ruleName, rule, tests) {
99117
const newTests = {
100118
valid: tests.valid.map((test) => convertToFlat(test, this[PLUGINS])),
101-
invalid: tests.invalid.map((test) => convertToFlat(test, this[PLUGINS])),
119+
invalid: tests.invalid
120+
.map(stripTypeOnEslint10)
121+
.map((test) => convertToFlat(test, this[PLUGINS])),
102122
};
103123

104124
super.run(ruleName, rule, newTests);

0 commit comments

Comments
 (0)