From 3cbfd7748bc269e7c019e3e4f09192b5e650a4f7 Mon Sep 17 00:00:00 2001 From: Brett Zamir Date: Fri, 24 Apr 2020 00:53:30 +0800 Subject: [PATCH] add `meta.type` ("problem" or "suggestion") for use by `eslint --fix-type` or formatters and add missing "fixable: code" to `no-skipped-tests` --- docs/rules/no-nested-tests.md | 2 +- lib/rules/handle-done-callback.js | 3 +++ lib/rules/max-top-level-suites.js | 1 + lib/rules/no-async-describe.js | 1 + lib/rules/no-exclusive-tests.js | 3 +++ lib/rules/no-global-tests.js | 3 +++ lib/rules/no-hooks-for-single-case.js | 1 + lib/rules/no-hooks.js | 1 + lib/rules/no-identical-title.js | 3 +++ lib/rules/no-mocha-arrows.js | 1 + lib/rules/no-nested-tests.js | 3 +++ lib/rules/no-pending-tests.js | 3 +++ lib/rules/no-return-and-callback.js | 3 +++ lib/rules/no-return-from-async.js | 3 +++ lib/rules/no-setup-in-describe.js | 3 +++ lib/rules/no-sibling-hooks.js | 3 +++ lib/rules/no-skipped-tests.js | 4 ++++ lib/rules/no-synchronous-tests.js | 1 + lib/rules/no-top-level-hooks.js | 3 +++ lib/rules/prefer-arrow-callback.js | 2 ++ lib/rules/valid-suite-description.js | 1 + lib/rules/valid-test-description.js | 1 + 22 files changed, 48 insertions(+), 1 deletion(-) diff --git a/docs/rules/no-nested-tests.md b/docs/rules/no-nested-tests.md index 2c78aa6..7729fd4 100644 --- a/docs/rules/no-nested-tests.md +++ b/docs/rules/no-nested-tests.md @@ -9,7 +9,7 @@ it('something', function () { }); }); ``` -Something like this could be easily happen by accident where the outer test case was actually meant to be a suite instead of a test. +Something like this could easily happen by accident where the outer test case was actually meant to be a suite instead of a test. This rule reports such nested test cases in order to prevent problems where those nested tests are skipped silently. ## Rule Details diff --git a/lib/rules/handle-done-callback.js b/lib/rules/handle-done-callback.js index 9b881c4..670735f 100644 --- a/lib/rules/handle-done-callback.js +++ b/lib/rules/handle-done-callback.js @@ -4,6 +4,9 @@ const find = require('ramda/src/find'); const astUtils = require('../util/ast'); module.exports = { + meta: { + type: 'problem' + }, create(context) { function isAsyncFunction(functionExpression) { return functionExpression.params.length === 1; diff --git a/lib/rules/max-top-level-suites.js b/lib/rules/max-top-level-suites.js index b88b804..67fb352 100644 --- a/lib/rules/max-top-level-suites.js +++ b/lib/rules/max-top-level-suites.js @@ -13,6 +13,7 @@ const defaultSuiteLimit = 1; module.exports = { meta: { + type: 'suggestion', schema: [ { type: 'object', diff --git a/lib/rules/no-async-describe.js b/lib/rules/no-async-describe.js index 6ca5625..da71cc1 100644 --- a/lib/rules/no-async-describe.js +++ b/lib/rules/no-async-describe.js @@ -11,6 +11,7 @@ const { additionalSuiteNames } = require('../util/settings'); module.exports = { meta: { + type: 'problem', fixable: 'code' }, create(context) { diff --git a/lib/rules/no-exclusive-tests.js b/lib/rules/no-exclusive-tests.js index 2125b41..83dcc90 100644 --- a/lib/rules/no-exclusive-tests.js +++ b/lib/rules/no-exclusive-tests.js @@ -4,6 +4,9 @@ const { getAdditionalTestFunctions } = require('../util/settings'); const astUtils = require('../util/ast'); module.exports = { + meta: { + type: 'problem' + }, create(context) { let mochaTestFunctions = [ 'it', diff --git a/lib/rules/no-global-tests.js b/lib/rules/no-global-tests.js index d74824b..f081cf2 100644 --- a/lib/rules/no-global-tests.js +++ b/lib/rules/no-global-tests.js @@ -3,6 +3,9 @@ const astUtils = require('../util/ast'); module.exports = { + meta: { + type: 'suggestion' + }, create(context) { function isGlobalScope(scope) { return scope.type === 'global' || scope.type === 'module'; diff --git a/lib/rules/no-hooks-for-single-case.js b/lib/rules/no-hooks-for-single-case.js index c24a0c9..f2a9792 100644 --- a/lib/rules/no-hooks-for-single-case.js +++ b/lib/rules/no-hooks-for-single-case.js @@ -13,6 +13,7 @@ function newDescribeLayer(describeNode) { module.exports = { meta: { + type: 'suggestion', schema: [ { type: 'object', diff --git a/lib/rules/no-hooks.js b/lib/rules/no-hooks.js index f1ee203..15b88b1 100644 --- a/lib/rules/no-hooks.js +++ b/lib/rules/no-hooks.js @@ -4,6 +4,7 @@ const astUtil = require('../util/ast'); module.exports = { meta: { + type: 'suggestion', schema: [ { type: 'object', diff --git a/lib/rules/no-identical-title.js b/lib/rules/no-identical-title.js index c475a7f..e35c842 100644 --- a/lib/rules/no-identical-title.js +++ b/lib/rules/no-identical-title.js @@ -42,6 +42,9 @@ function isFirstArgLiteral(node) { } module.exports = { + meta: { + type: 'suggestion' + }, create(context) { const titleLayers = [ newLayer() ]; const settings = context.settings; diff --git a/lib/rules/no-mocha-arrows.js b/lib/rules/no-mocha-arrows.js index 4c98760..b45cf4e 100644 --- a/lib/rules/no-mocha-arrows.js +++ b/lib/rules/no-mocha-arrows.js @@ -10,6 +10,7 @@ const astUtils = require('../util/ast'); module.exports = { meta: { + type: 'suggestion', fixable: 'code' }, create(context) { diff --git a/lib/rules/no-nested-tests.js b/lib/rules/no-nested-tests.js index 19544b9..eff4475 100644 --- a/lib/rules/no-nested-tests.js +++ b/lib/rules/no-nested-tests.js @@ -6,6 +6,9 @@ const astUtils = require('../util/ast'); const { additionalSuiteNames } = require('../util/settings'); module.exports = { + meta: { + type: 'problem' + }, create(context) { const settings = context.settings; let testNestingLevel = 0; diff --git a/lib/rules/no-pending-tests.js b/lib/rules/no-pending-tests.js index f37f6f9..b2d2db7 100644 --- a/lib/rules/no-pending-tests.js +++ b/lib/rules/no-pending-tests.js @@ -3,6 +3,9 @@ const astUtils = require('../util/ast'); module.exports = { + meta: { + type: 'suggestion' + }, create(context) { function isPendingMochaTest(node) { return astUtils.isTestCase(node) && diff --git a/lib/rules/no-return-and-callback.js b/lib/rules/no-return-and-callback.js index b30a8c6..8c4822f 100644 --- a/lib/rules/no-return-and-callback.js +++ b/lib/rules/no-return-and-callback.js @@ -40,6 +40,9 @@ function reportIfFunctionWithBlock(context, node, doneName) { } module.exports = { + meta: { + type: 'problem' + }, create(context) { function check(node) { if (node.params.length === 0 || !astUtils.hasParentMochaFunctionCall(node)) { diff --git a/lib/rules/no-return-from-async.js b/lib/rules/no-return-from-async.js index c87097a..fcd4be6 100644 --- a/lib/rules/no-return-from-async.js +++ b/lib/rules/no-return-from-async.js @@ -34,6 +34,9 @@ function reportIfFunctionWithBlock(context, node) { } module.exports = { + meta: { + type: 'suggestion' + }, create(context) { function check(node) { if (!node.async || !astUtils.hasParentMochaFunctionCall(node)) { diff --git a/lib/rules/no-setup-in-describe.js b/lib/rules/no-setup-in-describe.js index f5d2698..3a872f1 100644 --- a/lib/rules/no-setup-in-describe.js +++ b/lib/rules/no-setup-in-describe.js @@ -9,6 +9,9 @@ const DESCRIBE = 2; const PURE = 3; module.exports = { + meta: { + type: 'suggestion' + }, create(context) { const nesting = []; const settings = context.settings; diff --git a/lib/rules/no-sibling-hooks.js b/lib/rules/no-sibling-hooks.js index fe89a27..fc8111a 100644 --- a/lib/rules/no-sibling-hooks.js +++ b/lib/rules/no-sibling-hooks.js @@ -14,6 +14,9 @@ function newDescribeLayer(describeNode) { } module.exports = { + meta: { + type: 'suggestion' + }, create(context) { const isUsed = []; const settings = context.settings; diff --git a/lib/rules/no-skipped-tests.js b/lib/rules/no-skipped-tests.js index 2c3fc2b..17c0e13 100644 --- a/lib/rules/no-skipped-tests.js +++ b/lib/rules/no-skipped-tests.js @@ -47,6 +47,10 @@ function isCallToMochaXFunction(callee) { } module.exports = { + meta: { + fixable: 'code', + type: 'problem' + }, create(context) { const settings = context.settings; const additionalTestFunctions = getAdditionalTestFunctions(settings); diff --git a/lib/rules/no-synchronous-tests.js b/lib/rules/no-synchronous-tests.js index d8d5e36..c95b360 100644 --- a/lib/rules/no-synchronous-tests.js +++ b/lib/rules/no-synchronous-tests.js @@ -37,6 +37,7 @@ function doesReturnPromise(functionExpression) { module.exports = { meta: { + type: 'suggestion', schema: [ { type: 'object', diff --git a/lib/rules/no-top-level-hooks.js b/lib/rules/no-top-level-hooks.js index 51aa5c7..776be6a 100644 --- a/lib/rules/no-top-level-hooks.js +++ b/lib/rules/no-top-level-hooks.js @@ -4,6 +4,9 @@ const astUtil = require('../util/ast'); const { additionalSuiteNames } = require('../util/settings'); module.exports = { + meta: { + type: 'problem' + }, create(context) { const settings = context.settings; const testSuiteStack = []; diff --git a/lib/rules/prefer-arrow-callback.js b/lib/rules/prefer-arrow-callback.js index 2d2793c..733e4ca 100644 --- a/lib/rules/prefer-arrow-callback.js +++ b/lib/rules/prefer-arrow-callback.js @@ -153,6 +153,8 @@ function hasDuplicateParams(paramsList) { module.exports = { meta: { + type: 'suggestion', + docs: { description: 'require using arrow functions for callbacks', category: 'ECMAScript 6', diff --git a/lib/rules/valid-suite-description.js b/lib/rules/valid-suite-description.js index 09987fc..e9012af 100644 --- a/lib/rules/valid-suite-description.js +++ b/lib/rules/valid-suite-description.js @@ -48,6 +48,7 @@ const messageSchema = { module.exports = { meta: { + type: 'suggestion', schema: [ { oneOf: [ patternSchema, { diff --git a/lib/rules/valid-test-description.js b/lib/rules/valid-test-description.js index a44532c..61b75db 100644 --- a/lib/rules/valid-test-description.js +++ b/lib/rules/valid-test-description.js @@ -47,6 +47,7 @@ const messageSchema = { module.exports = { meta: { + type: 'suggestion', schema: [ { oneOf: [ patternSchema, {