Skip to content

Commit

Permalink
Add eslint-plugin-eslint-plugin and rule documentation URLs
Browse files Browse the repository at this point in the history
[eslint-plugin-eslint-plugin](https://github.com/not-an-aardvark/eslint-plugin-eslint-plugin) is a popular plugin for enforcing best practices for eslint plugins.

The main reason I added this is because I noticed that the mocha rules did not have URLs specified. URLs are necessary so that IDEs/editors can provide a convenient link to rule documentation when showing violations so that developers can better understand the rules. So I enabled the fully-autofixable rule [eslint-plugin/require-meta-docs-url](https://github.com/not-an-aardvark/eslint-plugin-eslint-plugin/blob/master/docs/rules/require-meta-docs-url.md).

A few other violations were autofixed including [duplicate test cases](https://github.com/not-an-aardvark/eslint-plugin-eslint-plugin/blob/master/docs/rules/no-identical-tests.md) and the use of the [deprecated report API](https://github.com/not-an-aardvark/eslint-plugin-eslint-plugin/blob/master/docs/rules/no-deprecated-report-api.md).
  • Loading branch information
bmish committed Oct 10, 2021
1 parent f954020 commit e1b7863
Show file tree
Hide file tree
Showing 27 changed files with 4,808 additions and 36 deletions.
16 changes: 14 additions & 2 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
{
"extends": "holidaycheck/es2015",
"plugins": [ "node", "unicorn" ],
"extends": [
"holidaycheck/es2015",
"plugin:eslint-plugin/recommended"
],
"plugins": [
"eslint-plugin",
"node",
"unicorn"
],

"env": {
"node": true
Expand All @@ -12,6 +19,11 @@
},

"rules": {
"eslint-plugin/require-meta-docs-url": [
"error",
{ "pattern": "https://github.com/lo1tuma/eslint-plugin-mocha/blob/master/docs/rules/{{name}}.md" }
],

"node/no-unsupported-features": "error",
"unicorn/prefer-includes": "error"
},
Expand Down
8 changes: 6 additions & 2 deletions lib/rules/handle-done-callback.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ module.exports = {
meta: {
type: 'problem',
docs: {
description: 'Enforces handling of callbacks for async tests'
description: 'Enforces handling of callbacks for async tests',
url: 'https://github.com/lo1tuma/eslint-plugin-mocha/blob/master/docs/rules/handle-done-callback.md'
},
schema: [
{
Expand Down Expand Up @@ -54,7 +55,10 @@ module.exports = {
const callbackVariable = findParamInScope(callbackName, scope);

if (callbackVariable && !hasHandledReferences(callbackVariable.references)) {
context.report(callback, 'Expected "{{name}}" callback to be handled.', { name: callbackName });
context.report({
node: callback,
message: 'Expected "{{name}}" callback to be handled.', data: { name: callbackName }
});
}
}

Expand Down
3 changes: 2 additions & 1 deletion lib/rules/max-top-level-suites.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ module.exports = {
meta: {
type: 'suggestion',
docs: {
description: 'Limit the number of top-level suites in a single file'
description: 'Limit the number of top-level suites in a single file',
url: 'https://github.com/lo1tuma/eslint-plugin-mocha/blob/master/docs/rules/max-top-level-suites.md'
},
schema: [
{
Expand Down
3 changes: 2 additions & 1 deletion lib/rules/no-async-describe.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ module.exports = {
meta: {
type: 'problem',
docs: {
description: 'Disallow async functions passed to describe'
description: 'Disallow async functions passed to describe',
url: 'https://github.com/lo1tuma/eslint-plugin-mocha/blob/master/docs/rules/no-async-describe.md'
},
fixable: 'code'
},
Expand Down
3 changes: 2 additions & 1 deletion lib/rules/no-exclusive-tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ module.exports = {
meta: {
type: 'problem',
docs: {
description: 'Disallow exclusive tests'
description: 'Disallow exclusive tests',
url: 'https://github.com/lo1tuma/eslint-plugin-mocha/blob/master/docs/rules/no-exclusive-tests.md'
}
},
create(context) {
Expand Down
3 changes: 2 additions & 1 deletion lib/rules/no-exports.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ const createAstUtils = require('../util/ast');
module.exports = {
meta: {
docs: {
description: 'Disallow exports from test files'
description: 'Disallow exports from test files',
url: 'https://github.com/lo1tuma/eslint-plugin-mocha/blob/master/docs/rules/no-exports.md'
},
messages: {
unexpectedExport: 'Unexpected export from a test file'
Expand Down
5 changes: 3 additions & 2 deletions lib/rules/no-global-tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ module.exports = {
meta: {
type: 'suggestion',
docs: {
description: 'Disallow global tests'
description: 'Disallow global tests',
url: 'https://github.com/lo1tuma/eslint-plugin-mocha/blob/master/docs/rules/no-global-tests.md'
}
},
create(context) {
Expand All @@ -22,7 +23,7 @@ module.exports = {
const scope = context.getScope();

if (astUtils.isTestCase(node) && isGlobalScope(scope)) {
context.report(callee, 'Unexpected global mocha test.');
context.report({ node: callee, message: 'Unexpected global mocha test.' });
}
}
};
Expand Down
3 changes: 2 additions & 1 deletion lib/rules/no-hooks-for-single-case.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ module.exports = {
meta: {
type: 'suggestion',
docs: {
description: 'Disallow hooks for a single test or test suite'
description: 'Disallow hooks for a single test or test suite',
url: 'https://github.com/lo1tuma/eslint-plugin-mocha/blob/master/docs/rules/no-hooks-for-single-case.md'
},
schema: [
{
Expand Down
3 changes: 2 additions & 1 deletion lib/rules/no-hooks.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ module.exports = {
meta: {
type: 'suggestion',
docs: {
description: 'Disallow hooks'
description: 'Disallow hooks',
url: 'https://github.com/lo1tuma/eslint-plugin-mocha/blob/master/docs/rules/no-hooks.md'
},
schema: [
{
Expand Down
3 changes: 2 additions & 1 deletion lib/rules/no-identical-title.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ module.exports = {
meta: {
type: 'suggestion',
docs: {
description: 'Disallow identical titles'
description: 'Disallow identical titles',
url: 'https://github.com/lo1tuma/eslint-plugin-mocha/blob/master/docs/rules/no-identical-title.md'
}
},
create(context) {
Expand Down
3 changes: 2 additions & 1 deletion lib/rules/no-mocha-arrows.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,8 @@ module.exports = {
type: 'suggestion',
docs: {
description:
'Disallow arrow functions as arguments to mocha functions'
'Disallow arrow functions as arguments to mocha functions',
url: 'https://github.com/lo1tuma/eslint-plugin-mocha/blob/master/docs/rules/no-mocha-arrows.md'
},
fixable: 'code'
},
Expand Down
3 changes: 2 additions & 1 deletion lib/rules/no-nested-tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ module.exports = {
meta: {
type: 'problem',
docs: {
description: 'Disallow tests to be nested within other tests '
description: 'Disallow tests to be nested within other tests ',
url: 'https://github.com/lo1tuma/eslint-plugin-mocha/blob/master/docs/rules/no-nested-tests.md'
}
},
create(context) {
Expand Down
3 changes: 2 additions & 1 deletion lib/rules/no-pending-tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ module.exports = {
meta: {
type: 'suggestion',
docs: {
description: 'Disallow pending tests'
description: 'Disallow pending tests',
url: 'https://github.com/lo1tuma/eslint-plugin-mocha/blob/master/docs/rules/no-pending-tests.md'
}
},
create(context) {
Expand Down
3 changes: 2 additions & 1 deletion lib/rules/no-return-and-callback.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ module.exports = {
meta: {
type: 'problem',
docs: {
description: 'Disallow returning in a test or hook function that uses a callback'
description: 'Disallow returning in a test or hook function that uses a callback',
url: 'https://github.com/lo1tuma/eslint-plugin-mocha/blob/master/docs/rules/no-return-and-callback.md'
}
},
create(context) {
Expand Down
3 changes: 2 additions & 1 deletion lib/rules/no-return-from-async.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ module.exports = {
meta: {
type: 'suggestion',
docs: {
description: 'Disallow returning from an async test or hook'
description: 'Disallow returning from an async test or hook',
url: 'https://github.com/lo1tuma/eslint-plugin-mocha/blob/master/docs/rules/no-return-from-async.md'
}
},
create(context) {
Expand Down
3 changes: 2 additions & 1 deletion lib/rules/no-setup-in-describe.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ module.exports = {
meta: {
type: 'suggestion',
docs: {
description: 'Disallow setup in describe blocks'
description: 'Disallow setup in describe blocks',
url: 'https://github.com/lo1tuma/eslint-plugin-mocha/blob/master/docs/rules/no-setup-in-describe.md'
}
},
create(context) {
Expand Down
3 changes: 2 additions & 1 deletion lib/rules/no-sibling-hooks.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ module.exports = {
meta: {
type: 'suggestion',
docs: {
description: 'Disallow duplicate uses of a hook at the same level inside a describe'
description: 'Disallow duplicate uses of a hook at the same level inside a describe',
url: 'https://github.com/lo1tuma/eslint-plugin-mocha/blob/master/docs/rules/no-sibling-hooks.md'
}
},
create(context) {
Expand Down
3 changes: 2 additions & 1 deletion lib/rules/no-skipped-tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ const createAstUtils = require('../util/ast');
module.exports = {
meta: {
docs: {
description: 'Disallow skipped tests'
description: 'Disallow skipped tests',
url: 'https://github.com/lo1tuma/eslint-plugin-mocha/blob/master/docs/rules/no-skipped-tests.md'
},
type: 'problem'
},
Expand Down
5 changes: 3 additions & 2 deletions lib/rules/no-synchronous-tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ module.exports = {
meta: {
type: 'suggestion',
docs: {
description: 'Disallow synchronous tests'
description: 'Disallow synchronous tests',
url: 'https://github.com/lo1tuma/eslint-plugin-mocha/blob/master/docs/rules/no-synchronous-tests.md'
},
schema: [
{
Expand Down Expand Up @@ -92,7 +93,7 @@ module.exports = {
const isAsyncTest = testAsyncMethods.includes(true);

if (!isAsyncTest) {
context.report(node, 'Unexpected synchronous test.');
context.report({ node, message: 'Unexpected synchronous test.' });
}
}
}
Expand Down
3 changes: 2 additions & 1 deletion lib/rules/no-top-level-hooks.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ module.exports = {
meta: {
type: 'problem',
docs: {
description: 'Disallow top-level hooks'
description: 'Disallow top-level hooks',
url: 'https://github.com/lo1tuma/eslint-plugin-mocha/blob/master/docs/rules/no-top-level-hooks.md'
}
},
create(context) {
Expand Down
2 changes: 1 addition & 1 deletion lib/rules/prefer-arrow-callback.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ module.exports = {
description: 'Require using arrow functions for callbacks',
category: 'ECMAScript 6',
recommended: false,
url: 'https://eslint.org/docs/rules/prefer-arrow-callback'
url: 'https://github.com/lo1tuma/eslint-plugin-mocha/blob/master/docs/rules/prefer-arrow-callback.md'
},

schema: [
Expand Down
5 changes: 3 additions & 2 deletions lib/rules/valid-suite-description.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@ module.exports = {
meta: {
type: 'suggestion',
docs: {
description: 'Match suite descriptions against a pre-configured regular expression'
description: 'Match suite descriptions against a pre-configured regular expression',
url: 'https://github.com/lo1tuma/eslint-plugin-mocha/blob/master/docs/rules/valid-suite-description.md'
},
schema: [
{
Expand Down Expand Up @@ -104,7 +105,7 @@ module.exports = {

if (isSuite(node)) {
if (!hasValidOrNoSuiteDescription(node)) {
context.report(node, message || `Invalid "${ callee.name }()" description found.`);
context.report({ node, message: message || `Invalid "${ callee.name }()" description found.` });
}
}
}
Expand Down
5 changes: 3 additions & 2 deletions lib/rules/valid-test-description.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ module.exports = {
meta: {
type: 'suggestion',
docs: {
description: 'Match test descriptions against a pre-configured regular expression'
description: 'Match test descriptions against a pre-configured regular expression',
url: 'https://github.com/lo1tuma/eslint-plugin-mocha/blob/master/docs/rules/valid-test-description.md'
},
schema: [
{
Expand Down Expand Up @@ -103,7 +104,7 @@ module.exports = {

if (isTest(node)) {
if (!hasValidOrNoTestDescription(node)) {
context.report(node, message || `Invalid "${ callee.name }()" description found.`);
context.report({ node, message: message || `Invalid "${ callee.name }()" description found.` });
}
}
}
Expand Down
Loading

0 comments on commit e1b7863

Please sign in to comment.