Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: support flat config (and thus ESLint 9) #46

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 0 additions & 23 deletions .eslintrc.json

This file was deleted.

4 changes: 2 additions & 2 deletions .github/workflows/nodejs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
- name: Setup node.js
uses: actions/setup-node@v1
with:
node-version: 12
node-version: 18.18.0
- name: Install dependencies
uses: bahmutov/npm-install@v1
- name: Lint
Expand All @@ -22,4 +22,4 @@ jobs:
- name: Publish report
uses: coverallsapp/github-action@master
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
github-token: ${{ secrets.GITHUB_TOKEN }}
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,
];
88 changes: 52 additions & 36 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,42 +19,58 @@ 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'].name =
'mocha-cleanup/flat/recommended';
module.exports.configs['flat/recommended-no-limits'].name =
'mocha-cleanup/flat/recommended-no-limits';

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
Loading