Repository: lo1tuma/eslint-plugin-mocha
Pull request #368 (2025-01-23 12:43:18)

Rename no-async-describe to no-async-suite


Patch:
diff --git a/README.md b/README.md
index 7156618..5b9fb3e 100644
--- a/README.md
+++ b/README.md
@@ -121,11 +121,10 @@ See [Configuring Eslint](http://eslint.org/docs/user-guide/configuring) on [esli
 
 | Name                                                                                 | Description                                                             | 💼 | ⚠️ | 🚫 | 🔧 |
 | :----------------------------------------------------------------------------------- | :---------------------------------------------------------------------- | :- | :- | :- | :- |
-| [consistent-interface](docs/rules/consistent-interface.md)                           | Enforces consistent use of mocha interfaces                             |    |    |    |    |
 | [consistent-spacing-between-blocks](docs/rules/consistent-spacing-between-blocks.md) | Require consistent spacing between blocks                               | ✅  |    |    | 🔧 |
 | [handle-done-callback](docs/rules/handle-done-callback.md)                           | Enforces handling of callbacks for async tests                          | ✅  |    |    |    |
 | [max-top-level-suites](docs/rules/max-top-level-suites.md)                           | Enforce the number of top-level suites in a single file                 | ✅  |    |    |    |
-| [no-async-describe](docs/rules/no-async-describe.md)                                 | Disallow async functions passed to a suite                              | ✅  |    |    | 🔧 |
+| [no-async-suite](docs/rules/no-async-suite.md)                                       | Disallow async functions passed to a suite                              | ✅  |    |    | 🔧 |
 | [no-empty-description](docs/rules/no-empty-description.md)                           | Disallow empty test descriptions                                        | ✅  |    |    |    |
 | [no-exclusive-tests](docs/rules/no-exclusive-tests.md)                               | Disallow exclusive tests                                                |    | ✅  |    |    |
 | [no-exports](docs/rules/no-exports.md)                                               | Disallow exports from test files                                        | ✅  |    |    |    |
diff --git a/docs/rules/consistent-interface.md b/docs/rules/consistent-interface.md
deleted file mode 100644
index b47ef3e..0000000
--- a/docs/rules/consistent-interface.md
+++ /dev/null
@@ -1,23 +0,0 @@
-# Enforces consistent use of mocha interfaces (`mocha/consistent-interface`)
-
-<!-- end auto-generated rule header -->
-
-Mocha has several interfaces such as `BDD`, `TDD`, `Exports`, `QUnit` etc. Usually mocha works by injecting the variables and functions of the selected interface into the global scope. However when using the `Exports` interface one can import functions of any interface. This rule helps to enforce a consistent use of the same interface when using `Exports`.
-
-## Options
-
-Example of a custom rule configuration:
-
-```js
-rules: {
-    "mocha/consistent-interface": ["error", { interface: 'BDD' }]
-},
-```
-
-where:
-
-- `interface` can be set to either `TDD` or `BDD`
-
-## When Not To Use It
-
-If you are not using the `Exports` interface then this rule doesn’t provide any value.
diff --git a/docs/rules/no-async-describe.md b/docs/rules/no-async-suite.md
similarity index 96%
rename from docs/rules/no-async-describe.md
rename to docs/rules/no-async-suite.md
index 4130a0f..a2fd28f 100644
--- a/docs/rules/no-async-describe.md
+++ b/docs/rules/no-async-suite.md
@@ -1,4 +1,4 @@
-# Disallow async functions passed to a suite (`mocha/no-async-describe`)
+# Disallow async functions passed to a suite (`mocha/no-async-suite`)
 
 💼 This rule is enabled in the ✅ `recommended` [config](https://github.com/lo1tuma/eslint-plugin-mocha#configs).
 
diff --git a/index.js b/index.js
index 10ab8eb..6efa6b9 100644
--- a/index.js
+++ b/index.js
@@ -1,9 +1,8 @@
 import globals from 'globals';
-import { consistentInterfaceRule } from './lib/rules/consistent-interface.js';
 import { consistentSpacingBetweenBlocksRule } from './lib/rules/consistent-spacing-between-blocks.js';
 import { handleDoneCallbackRule } from './lib/rules/handle-done-callback.js';
 import { maxTopLevelSuitesRule } from './lib/rules/max-top-level-suites.js';
-import { noAsyncDescribeRule } from './lib/rules/no-async-describe.js';
+import { noAsyncSuiteRule } from './lib/rules/no-async-suite.js';
 import { noEmptyDescriptionRule } from './lib/rules/no-empty-description.js';
 import { noExclusiveTestsRule } from './lib/rules/no-exclusive-tests.js';
 import { noExportsRule } from './lib/rules/no-exports.js';
@@ -27,7 +26,7 @@ import { validTestDescriptionRule } from './lib/rules/valid-test-description.js'
 const allRules = {
     'mocha/handle-done-callback': 'error',
     'mocha/max-top-level-suites': 'error',
-    'mocha/no-async-describe': 'error',
+    'mocha/no-async-suite': 'error',
     'mocha/no-exclusive-tests': 'error',
     'mocha/no-exports': 'error',
     'mocha/no-global-tests': 'error',
@@ -47,14 +46,13 @@ const allRules = {
     'mocha/valid-suite-description': 'error',
     'mocha/valid-test-description': 'error',
     'mocha/no-empty-description': 'error',
-    'mocha/consistent-spacing-between-blocks': 'error',
-    'mocha/consistent-interface': ['error', { interface: 'BDD' }]
+    'mocha/consistent-spacing-between-blocks': 'error'
 };
 
 const recommendedRules = {
     'mocha/handle-done-callback': 'error',
     'mocha/max-top-level-suites': ['error', { limit: 1 }],
-    'mocha/no-async-describe': 'error',
+    'mocha/no-async-suite': 'error',
     'mocha/no-exclusive-tests': 'warn',
     'mocha/no-exports': 'error',
     'mocha/no-global-tests': 'error',
@@ -81,7 +79,7 @@ const mochaPlugin = {
     rules: {
         'handle-done-callback': handleDoneCallbackRule,
         'max-top-level-suites': maxTopLevelSuitesRule,
-        'no-async-describe': noAsyncDescribeRule,
+        'no-async-suite': noAsyncSuiteRule,
         'no-exclusive-tests': noExclusiveTestsRule,
         'no-exports': noExportsRule,
         'no-global-tests': noGlobalTestsRule,
@@ -101,8 +99,7 @@ const mochaPlugin = {
         'valid-suite-description': validSuiteDescriptionRule,
         'valid-test-description': validTestDescriptionRule,
         'no-empty-description': noEmptyDescriptionRule,
-        'consistent-spacing-between-blocks': consistentSpacingBetweenBlocksRule,
-        'consistent-interface': consistentInterfaceRule
+        'consistent-spacing-between-blocks': consistentSpacingBetweenBlocksRule
     },
     configs: {
         all: {
diff --git a/lib/ast/mochaVisitors.js b/lib/ast/mochaVisitors.js
index 15e4092..857a68e 100755
--- a/lib/ast/mochaVisitors.js
+++ b/lib/ast/mochaVisitors.js
@@ -39,8 +39,7 @@ function createContext(reference) {
         name: reference.resolvedPath.join('.'),
         node: reference.node,
         type: reference.nameDetails.type,
-        modifier: reference.nameDetails.modifier,
-        interface: reference.nameDetails.interface
+        modifier: reference.nameDetails.modifier
     };
 }
 
diff --git a/lib/rules/consistent-interface.js b/lib/rules/consistent-interface.js
deleted file mode 100644
index 6220e22..0000000
--- a/lib/rules/consistent-interface.js
+++ /dev/null
@@ -1,38 +0,0 @@
-import { createMochaVisitors } from '../ast/mochaVisitors.js';
-
-export const consistentInterfaceRule = {
-    meta: {
-        type: 'problem',
-        docs: {
-            description: 'Enforces consistent use of mocha interfaces',
-            url: 'https://github.com/lo1tuma/eslint-plugin-mocha/blob/main/docs/rules/consistent-interface.md'
-        },
-        schema: [
-            {
-                type: 'object',
-                properties: {
-                    interface: {
-                        type: 'string',
-                        enum: ['BDD', 'TDD'],
-                        default: 'BDD'
-                    }
-                },
-                additionalProperties: false
-            }
-        ]
-    },
-    create(context) {
-        const interfaceToUse = context.options[0].interface;
-
-        return createMochaVisitors(context, {
-            anyTestEntity(visitorContext) {
-                if (visitorContext.interface !== interfaceToUse) {
-                    context.report({
-                        node: visitorContext.node,
-                        message: `Unexpected use of ${visitorContext.interface} interface instead of ${interfaceToUse}`
-                    });
-                }
-            }
-        });
-    }
-};
diff --git a/lib/rules/no-async-describe.js b/lib/rules/no-async-suite.js
similarity index 96%
rename from lib/rules/no-async-describe.js
rename to lib/rules/no-async-suite.js
index a938fbd..81adaa8 100644
--- a/lib/rules/no-async-describe.js
+++ b/lib/rules/no-async-suite.js
@@ -42,12 +42,12 @@ function fixAsyncFunction(sourceCode, fixer, fn) {
     return undefined;
 }
 
-export const noAsyncDescribeRule = {
+export const noAsyncSuiteRule = {
     meta: {
         type: 'problem',
         docs: {
             description: 'Disallow async functions passed to a suite',
-            url: 'https://github.com/lo1tuma/eslint-plugin-mocha/blob/main/docs/rules/no-async-describe.md'
+            url: 'https://github.com/lo1tuma/eslint-plugin-mocha/blob/main/docs/rules/no-async-suite.md'
         },
         fixable: 'code',
         schema: []


Test patch:
diff --git a/test/rules/consistent-interface.js b/test/rules/consistent-interface.js
deleted file mode 100644
index 7de6890..0000000
--- a/test/rules/consistent-interface.js
+++ /dev/null
@@ -1,85 +0,0 @@
-import { RuleTester } from 'eslint';
-import { consistentInterfaceRule } from '../../lib/rules/consistent-interface.js';
-
-const ruleTester = new RuleTester({ languageOptions: { ecmaVersion: 2020, sourceType: 'module' } });
-
-ruleTester.run('consistent-interface', consistentInterfaceRule, {
-    valid: [
-        {
-            code: `describe('foo', () => {
-                it('bar', () => {});
-            });`,
-            options: [{ interface: 'BDD' }],
-            settings: { mocha: { interface: 'BDD' } }
-        },
-        {
-            code: `suite('foo', () => {
-                test('bar', () => {});
-            });`,
-            options: [{ interface: 'TDD' }],
-            settings: { mocha: { interface: 'TDD' } }
-        },
-        {
-            code: `import {suite, test} from 'mocha'; suite('foo', () => {
-                test('bar', () => {});
-            });`,
-            options: [{ interface: 'TDD' }],
-            settings: { mocha: { interface: 'exports' } }
-        },
-        {
-            code: `import {describe, it} from 'mocha'; describe('foo', () => {
-                it('bar', () => {});
-            });`,
-            options: [{ interface: 'BDD' }],
-            settings: { mocha: { interface: 'exports' } }
-        },
-        {
-            code: `import {describe as foo, it as bar} from 'mocha'; foo('foo', () => {
-                bar('bar', () => {});
-            });`,
-            options: [{ interface: 'BDD' }],
-            settings: { mocha: { interface: 'exports' } }
-        }
-    ],
-
-    invalid: [
-        {
-            code: `describe('foo', () => {
-                test('bar', () => {});
-            });`,
-            options: [{ interface: 'BDD' }],
-            settings: { mocha: { interface: 'BDD' } },
-            errors: [{ line: 2, column: 17, message: 'Unexpected use of TDD interface instead of BDD' }]
-        },
-        {
-            code: `describe('foo', () => {
-                test('bar', () => {});
-            });`,
-            options: [{ interface: 'TDD' }],
-            settings: { mocha: { interface: 'TDD' } },
-            errors: [{ line: 1, column: 1, message: 'Unexpected use of BDD interface instead of TDD' }]
-        },
-        {
-            code: `import {suite, test} from 'mocha'; suite('foo', () => {
-                test('bar', () => {});
-            });`,
-            options: [{ interface: 'BDD' }],
-            settings: { mocha: { interface: 'exports' } },
-            errors: [
-                { line: 1, column: 36, message: 'Unexpected use of TDD interface instead of BDD' },
-                { line: 2, column: 17, message: 'Unexpected use of TDD interface instead of BDD' }
-            ]
-        },
-        {
-            code: `import {describe, it} from 'mocha'; describe('foo', () => {
-                it('bar', () => {});
-            });`,
-            options: [{ interface: 'TDD' }],
-            settings: { mocha: { interface: 'exports' } },
-            errors: [
-                { line: 1, column: 37, message: 'Unexpected use of BDD interface instead of TDD' },
-                { line: 2, column: 17, message: 'Unexpected use of BDD interface instead of TDD' }
-            ]
-        }
-    ]
-});
diff --git a/test/rules/no-async-describe.js b/test/rules/no-async-suite.js
similarity index 96%
rename from test/rules/no-async-describe.js
rename to test/rules/no-async-suite.js
index 217be5d..edd9fcf 100644
--- a/test/rules/no-async-describe.js
+++ b/test/rules/no-async-suite.js
@@ -1,8 +1,8 @@
 import { RuleTester } from 'eslint';
-import { noAsyncDescribeRule } from '../../lib/rules/no-async-describe.js';
+import { noAsyncSuiteRule } from '../../lib/rules/no-async-suite.js';
 const ruleTester = new RuleTester({ languageOptions: { sourceType: 'script' } });
 
-ruleTester.run('no-async-describe', noAsyncDescribeRule, {
+ruleTester.run('no-async-suite', noAsyncSuiteRule, {
     valid: [
         'describe()',
         'describe("hello")',