Skip to content

Commit

Permalink
feat: support flat config (and thus ESLint 9)
Browse files Browse the repository at this point in the history
Also:
- chore: use flat config internally
- chore: update devDeps.
- chore: prettify files
  • Loading branch information
brettz9 committed Jul 3, 2024
1 parent 7f135e3 commit 1d6ecf0
Show file tree
Hide file tree
Showing 30 changed files with 4,214 additions and 3,188 deletions.
23 changes: 0 additions & 23 deletions .eslintrc.json

This file was deleted.

2 changes: 1 addition & 1 deletion .ncurc.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ module.exports = {
// Whitelist all for checking besides `peer` which indicates
// somewhat older versions of `eslint` we still support even
// while our devDeps point to a more recent version
"dep": "prod,dev,optional,bundle"
dep: 'prod,dev,optional,bundle',
};
27 changes: 27 additions & 0 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// import standard from "eslint-config-standard"
import eslintPluginPrettierRecommended from 'eslint-plugin-prettier/recommended';
import globals from 'globals';

export default [
{
languageOptions: {
globals: {
...globals.browser,
...globals.node,
...globals.es2015,
},
},
rules: {
'no-var': [2],
'prefer-destructuring': [2],
'object-shorthand': [2],
},
},
{
files: ['tests/lib/utils/**'],
languageOptions: {
globals: globals.mocha,
},
},
eslintPluginPrettierRecommended,
];
82 changes: 46 additions & 36 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,42 +19,52 @@ const requireIndex = require('requireindex');
// import all rules in lib/rules
module.exports = {
rules: requireIndex(path.resolve(__dirname, './rules')),
configs: {
recommended: {
plugins: ['mocha-cleanup'],
rules: {
'mocha-cleanup/asserts-limit': 2,
'mocha-cleanup/disallow-stub-spy-restore-in-it': 2,
'mocha-cleanup/no-empty-title': 2,
'mocha-cleanup/no-same-titles': 2,
'mocha-cleanup/no-nested-it': 2,
'mocha-cleanup/no-assertions-outside-it': 2,
'mocha-cleanup/complexity-it': 2,
'mocha-cleanup/no-eql-primitives': 2,
'mocha-cleanup/no-assertions-in-loop': 2,
'mocha-cleanup/no-empty-body': 2,
'mocha-cleanup/invalid-assertions': 2,
'mocha-cleanup/no-expressions-in-assertions': 2,
'mocha-cleanup/no-outside-declaration': 2,
},
configs: {},
};

for (const prefix of ['flat/', '']) {
module.exports.configs[prefix + 'recommended'] = {
rules: {
'mocha-cleanup/asserts-limit': 2,
'mocha-cleanup/disallow-stub-spy-restore-in-it': 2,
'mocha-cleanup/no-empty-title': 2,
'mocha-cleanup/no-same-titles': 2,
'mocha-cleanup/no-nested-it': 2,
'mocha-cleanup/no-assertions-outside-it': 2,
'mocha-cleanup/complexity-it': 2,
'mocha-cleanup/no-eql-primitives': 2,
'mocha-cleanup/no-assertions-in-loop': 2,
'mocha-cleanup/no-empty-body': 2,
'mocha-cleanup/invalid-assertions': 2,
'mocha-cleanup/no-expressions-in-assertions': 2,
'mocha-cleanup/no-outside-declaration': 2,
},
'recommended-no-limits': {
plugins: ['mocha-cleanup'],
rules: {
// "mocha-cleanup/asserts-limit": 0,
'mocha-cleanup/disallow-stub-spy-restore-in-it': 2,
'mocha-cleanup/no-empty-title': 2,
'mocha-cleanup/no-same-titles': 2,
'mocha-cleanup/no-nested-it': 2,
'mocha-cleanup/no-assertions-outside-it': 2,
// "mocha-cleanup/complexity-it": 0,
'mocha-cleanup/no-eql-primitives': 2,
'mocha-cleanup/no-assertions-in-loop': 2,
'mocha-cleanup/no-empty-body': 2,
'mocha-cleanup/invalid-assertions': 2,
'mocha-cleanup/no-expressions-in-assertions': 2,
'mocha-cleanup/no-outside-declaration': 2,
},
};

module.exports.configs[prefix + 'recommended-no-limits'] = {
rules: {
// "mocha-cleanup/asserts-limit": 0,
'mocha-cleanup/disallow-stub-spy-restore-in-it': 2,
'mocha-cleanup/no-empty-title': 2,
'mocha-cleanup/no-same-titles': 2,
'mocha-cleanup/no-nested-it': 2,
'mocha-cleanup/no-assertions-outside-it': 2,
// "mocha-cleanup/complexity-it": 0,
'mocha-cleanup/no-eql-primitives': 2,
'mocha-cleanup/no-assertions-in-loop': 2,
'mocha-cleanup/no-empty-body': 2,
'mocha-cleanup/invalid-assertions': 2,
'mocha-cleanup/no-expressions-in-assertions': 2,
'mocha-cleanup/no-outside-declaration': 2,
},
},
};
}

module.exports.configs.recommended.plugins = ['mocha-cleanup'];
module.exports.configs['recommended-no-limits'].plugins = ['mocha-cleanup'];
module.exports.configs['flat/recommended'].plugins = {
'mocha-cleanup': module.exports,
};
module.exports.configs['flat/recommended-no-limits'].plugins = {
'mocha-cleanup': module.exports,
};
6 changes: 3 additions & 3 deletions lib/rules/asserts-limit.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ module.exports = {
const skipSkipped = isSkipSkipped(options, context);
const ignoreZeroAssertionsIfDoneExists = hasOwnProperty.call(
options,
'ignoreZeroAssertionsIfDoneExists'
'ignoreZeroAssertionsIfDoneExists',
)
? options.ignoreZeroAssertionsIfDoneExists
: true;
Expand Down Expand Up @@ -83,7 +83,7 @@ module.exports = {
{
max: assertsLimit,
num: assertsCounter,
}
},
);
}
if (
Expand All @@ -93,7 +93,7 @@ module.exports = {
) {
context.report(
node.parent,
'Test without assertions is not allowed.'
'Test without assertions is not allowed.',
);
}
insideIt = false;
Expand Down
4 changes: 2 additions & 2 deletions lib/rules/complexity-it.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ module.exports = {
const options = context.options[0] || {};
const maxAllowedComplexity = hasOwnProperty.call(
options,
'maxAllowedComplexity'
'maxAllowedComplexity',
)
? options.maxAllowedComplexity
: 40;
Expand Down Expand Up @@ -79,7 +79,7 @@ module.exports = {
max: maxAllowedComplexity,
num: currentComplexityCount,
name: n.getCaller(node.parent),
}
},
);
}
insideIt = false;
Expand Down
2 changes: 1 addition & 1 deletion lib/rules/disallow-stub-spy-restore-in-it.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ module.exports = {
context.report(
node,
'`{{name}}` is not allowed to use inside `{{caller}}`.',
{ name: _c, caller }
{ name: _c, caller },
);
}
},
Expand Down
2 changes: 1 addition & 1 deletion lib/rules/no-assertions-in-loop.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ module.exports = {
const skipSkipped = isSkipSkipped(options, context);
const extraMemberExpression = hasOwnProperty.call(
options,
'extraMemberExpression'
'extraMemberExpression',
)
? options.extraMemberExpression
: [];
Expand Down
4 changes: 2 additions & 2 deletions lib/rules/no-eql-primitives.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ module.exports = {
context.report(
node,
'`{{caller}}` should not be used with primitives.',
{ caller }
{ caller },
);
}
}
Expand All @@ -103,7 +103,7 @@ module.exports = {
context.report(
node,
'`{{caller}}` should not be used with primitives.',
{ caller: _caller }
{ caller: _caller },
);
}
}
Expand Down
2 changes: 1 addition & 1 deletion lib/rules/no-nested-it.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ module.exports = {
if (insideIt && !(skipSkipped && n.tryDetectSkipInParent(node))) {
context.report(
node.parent,
'Nested tests are not allowed. Only nested suites are allowed.'
'Nested tests are not allowed. Only nested suites are allowed.',
);
} else {
insideIt = true;
Expand Down
2 changes: 1 addition & 1 deletion lib/rules/top-level-assertions.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ module.exports = {
const nodeSourceCode = context.getSourceCode().getText(node);
if (assertionsCheckExpression) {
assertionsCheckExists = RegExp(assertionsCheckExpression, 'gm').test(
nodeSourceCode
nodeSourceCode,
);
}
insideIt = true;
Expand Down
2 changes: 1 addition & 1 deletion lib/utils/node.js
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ function isBlockBody(node, type) {
if (parentType === 'MemberExpression') {
return (
types.includes(
parent.callee.object.name + '.' + parent.callee.property.name
parent.callee.object.name + '.' + parent.callee.property.name,
) && obj.get(parent, 'arguments.1') === node
);
}
Expand Down
Loading

0 comments on commit 1d6ecf0

Please sign in to comment.