Skip to content

Commit 1d6ecf0

Browse files
committed
feat: support flat config (and thus ESLint 9)
Also: - chore: use flat config internally - chore: update devDeps. - chore: prettify files
1 parent 7f135e3 commit 1d6ecf0

30 files changed

+4214
-3188
lines changed

.eslintrc.json

-23
This file was deleted.

.ncurc.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@ module.exports = {
22
// Whitelist all for checking besides `peer` which indicates
33
// somewhat older versions of `eslint` we still support even
44
// while our devDeps point to a more recent version
5-
"dep": "prod,dev,optional,bundle"
5+
dep: 'prod,dev,optional,bundle',
66
};

eslint.config.mjs

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// import standard from "eslint-config-standard"
2+
import eslintPluginPrettierRecommended from 'eslint-plugin-prettier/recommended';
3+
import globals from 'globals';
4+
5+
export default [
6+
{
7+
languageOptions: {
8+
globals: {
9+
...globals.browser,
10+
...globals.node,
11+
...globals.es2015,
12+
},
13+
},
14+
rules: {
15+
'no-var': [2],
16+
'prefer-destructuring': [2],
17+
'object-shorthand': [2],
18+
},
19+
},
20+
{
21+
files: ['tests/lib/utils/**'],
22+
languageOptions: {
23+
globals: globals.mocha,
24+
},
25+
},
26+
eslintPluginPrettierRecommended,
27+
];

lib/index.js

+46-36
Original file line numberDiff line numberDiff line change
@@ -19,42 +19,52 @@ const requireIndex = require('requireindex');
1919
// import all rules in lib/rules
2020
module.exports = {
2121
rules: requireIndex(path.resolve(__dirname, './rules')),
22-
configs: {
23-
recommended: {
24-
plugins: ['mocha-cleanup'],
25-
rules: {
26-
'mocha-cleanup/asserts-limit': 2,
27-
'mocha-cleanup/disallow-stub-spy-restore-in-it': 2,
28-
'mocha-cleanup/no-empty-title': 2,
29-
'mocha-cleanup/no-same-titles': 2,
30-
'mocha-cleanup/no-nested-it': 2,
31-
'mocha-cleanup/no-assertions-outside-it': 2,
32-
'mocha-cleanup/complexity-it': 2,
33-
'mocha-cleanup/no-eql-primitives': 2,
34-
'mocha-cleanup/no-assertions-in-loop': 2,
35-
'mocha-cleanup/no-empty-body': 2,
36-
'mocha-cleanup/invalid-assertions': 2,
37-
'mocha-cleanup/no-expressions-in-assertions': 2,
38-
'mocha-cleanup/no-outside-declaration': 2,
39-
},
22+
configs: {},
23+
};
24+
25+
for (const prefix of ['flat/', '']) {
26+
module.exports.configs[prefix + 'recommended'] = {
27+
rules: {
28+
'mocha-cleanup/asserts-limit': 2,
29+
'mocha-cleanup/disallow-stub-spy-restore-in-it': 2,
30+
'mocha-cleanup/no-empty-title': 2,
31+
'mocha-cleanup/no-same-titles': 2,
32+
'mocha-cleanup/no-nested-it': 2,
33+
'mocha-cleanup/no-assertions-outside-it': 2,
34+
'mocha-cleanup/complexity-it': 2,
35+
'mocha-cleanup/no-eql-primitives': 2,
36+
'mocha-cleanup/no-assertions-in-loop': 2,
37+
'mocha-cleanup/no-empty-body': 2,
38+
'mocha-cleanup/invalid-assertions': 2,
39+
'mocha-cleanup/no-expressions-in-assertions': 2,
40+
'mocha-cleanup/no-outside-declaration': 2,
4041
},
41-
'recommended-no-limits': {
42-
plugins: ['mocha-cleanup'],
43-
rules: {
44-
// "mocha-cleanup/asserts-limit": 0,
45-
'mocha-cleanup/disallow-stub-spy-restore-in-it': 2,
46-
'mocha-cleanup/no-empty-title': 2,
47-
'mocha-cleanup/no-same-titles': 2,
48-
'mocha-cleanup/no-nested-it': 2,
49-
'mocha-cleanup/no-assertions-outside-it': 2,
50-
// "mocha-cleanup/complexity-it": 0,
51-
'mocha-cleanup/no-eql-primitives': 2,
52-
'mocha-cleanup/no-assertions-in-loop': 2,
53-
'mocha-cleanup/no-empty-body': 2,
54-
'mocha-cleanup/invalid-assertions': 2,
55-
'mocha-cleanup/no-expressions-in-assertions': 2,
56-
'mocha-cleanup/no-outside-declaration': 2,
57-
},
42+
};
43+
44+
module.exports.configs[prefix + 'recommended-no-limits'] = {
45+
rules: {
46+
// "mocha-cleanup/asserts-limit": 0,
47+
'mocha-cleanup/disallow-stub-spy-restore-in-it': 2,
48+
'mocha-cleanup/no-empty-title': 2,
49+
'mocha-cleanup/no-same-titles': 2,
50+
'mocha-cleanup/no-nested-it': 2,
51+
'mocha-cleanup/no-assertions-outside-it': 2,
52+
// "mocha-cleanup/complexity-it": 0,
53+
'mocha-cleanup/no-eql-primitives': 2,
54+
'mocha-cleanup/no-assertions-in-loop': 2,
55+
'mocha-cleanup/no-empty-body': 2,
56+
'mocha-cleanup/invalid-assertions': 2,
57+
'mocha-cleanup/no-expressions-in-assertions': 2,
58+
'mocha-cleanup/no-outside-declaration': 2,
5859
},
59-
},
60+
};
61+
}
62+
63+
module.exports.configs.recommended.plugins = ['mocha-cleanup'];
64+
module.exports.configs['recommended-no-limits'].plugins = ['mocha-cleanup'];
65+
module.exports.configs['flat/recommended'].plugins = {
66+
'mocha-cleanup': module.exports,
67+
};
68+
module.exports.configs['flat/recommended-no-limits'].plugins = {
69+
'mocha-cleanup': module.exports,
6070
};

lib/rules/asserts-limit.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ module.exports = {
4848
const skipSkipped = isSkipSkipped(options, context);
4949
const ignoreZeroAssertionsIfDoneExists = hasOwnProperty.call(
5050
options,
51-
'ignoreZeroAssertionsIfDoneExists'
51+
'ignoreZeroAssertionsIfDoneExists',
5252
)
5353
? options.ignoreZeroAssertionsIfDoneExists
5454
: true;
@@ -83,7 +83,7 @@ module.exports = {
8383
{
8484
max: assertsLimit,
8585
num: assertsCounter,
86-
}
86+
},
8787
);
8888
}
8989
if (
@@ -93,7 +93,7 @@ module.exports = {
9393
) {
9494
context.report(
9595
node.parent,
96-
'Test without assertions is not allowed.'
96+
'Test without assertions is not allowed.',
9797
);
9898
}
9999
insideIt = false;

lib/rules/complexity-it.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ module.exports = {
4343
const options = context.options[0] || {};
4444
const maxAllowedComplexity = hasOwnProperty.call(
4545
options,
46-
'maxAllowedComplexity'
46+
'maxAllowedComplexity',
4747
)
4848
? options.maxAllowedComplexity
4949
: 40;
@@ -79,7 +79,7 @@ module.exports = {
7979
max: maxAllowedComplexity,
8080
num: currentComplexityCount,
8181
name: n.getCaller(node.parent),
82-
}
82+
},
8383
);
8484
}
8585
insideIt = false;

lib/rules/disallow-stub-spy-restore-in-it.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ module.exports = {
7171
context.report(
7272
node,
7373
'`{{name}}` is not allowed to use inside `{{caller}}`.',
74-
{ name: _c, caller }
74+
{ name: _c, caller },
7575
);
7676
}
7777
},

lib/rules/no-assertions-in-loop.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ module.exports = {
5151
const skipSkipped = isSkipSkipped(options, context);
5252
const extraMemberExpression = hasOwnProperty.call(
5353
options,
54-
'extraMemberExpression'
54+
'extraMemberExpression',
5555
)
5656
? options.extraMemberExpression
5757
: [];

lib/rules/no-eql-primitives.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ module.exports = {
7777
context.report(
7878
node,
7979
'`{{caller}}` should not be used with primitives.',
80-
{ caller }
80+
{ caller },
8181
);
8282
}
8383
}
@@ -103,7 +103,7 @@ module.exports = {
103103
context.report(
104104
node,
105105
'`{{caller}}` should not be used with primitives.',
106-
{ caller: _caller }
106+
{ caller: _caller },
107107
);
108108
}
109109
}

lib/rules/no-nested-it.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ module.exports = {
4141
if (insideIt && !(skipSkipped && n.tryDetectSkipInParent(node))) {
4242
context.report(
4343
node.parent,
44-
'Nested tests are not allowed. Only nested suites are allowed.'
44+
'Nested tests are not allowed. Only nested suites are allowed.',
4545
);
4646
} else {
4747
insideIt = true;

lib/rules/top-level-assertions.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ module.exports = {
7777
const nodeSourceCode = context.getSourceCode().getText(node);
7878
if (assertionsCheckExpression) {
7979
assertionsCheckExists = RegExp(assertionsCheckExpression, 'gm').test(
80-
nodeSourceCode
80+
nodeSourceCode,
8181
);
8282
}
8383
insideIt = true;

lib/utils/node.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ function isBlockBody(node, type) {
176176
if (parentType === 'MemberExpression') {
177177
return (
178178
types.includes(
179-
parent.callee.object.name + '.' + parent.callee.property.name
179+
parent.callee.object.name + '.' + parent.callee.property.name,
180180
) && obj.get(parent, 'arguments.1') === node
181181
);
182182
}

0 commit comments

Comments
 (0)