Skip to content

Commit ac449cc

Browse files
authored
Merge pull request #400 from mdmower-csnw/mdm-plugintype
Improve exported plugin type
2 parents dde1511 + e97396e commit ac449cc

File tree

2 files changed

+22
-19
lines changed

2 files changed

+22
-19
lines changed

source/plugin.test.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,14 +37,15 @@ describe('eslint-plugin-mocha', function () {
3737
const ruleFiles = await determineAllRuleFiles();
3838

3939
for (const file of ruleFiles) {
40-
const ruleName = path.basename(file, '.js');
40+
const ruleName = path.basename(file, '.js') as keyof typeof plugin.rules;
41+
assert.ok(ruleName in plugin.rules);
4142
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment -- ok
4243
const importedRuleModule = await import(path.join(rulesDir, file));
4344
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-member-access -- ok
4445
const importedRule = importedRuleModule[`${camelCase(ruleName)}Rule`];
4546

4647
assert.notStrictEqual(importedRule, undefined);
47-
assert.strictEqual(plugin.rules?.[ruleName], importedRule);
48+
assert.strictEqual(plugin.rules[ruleName], importedRule);
4849
}
4950
});
5051

source/plugin.ts

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -76,9 +76,9 @@ const recommendedRules: Linter.RulesRecord = {
7676
'mocha/valid-test-title': 'off',
7777
'mocha/no-empty-title': 'error',
7878
'mocha/consistent-spacing-between-blocks': 'error'
79-
} as const;
79+
};
8080

81-
const mochaPlugin: ESLint.Plugin = {
81+
const mochaPlugin = {
8282
rules: {
8383
'handle-done-callback': handleDoneCallbackRule,
8484
'max-top-level-suites': maxTopLevelSuitesRule,
@@ -104,22 +104,24 @@ const mochaPlugin: ESLint.Plugin = {
104104
'valid-suite-title': validSuiteTitleRule,
105105
'valid-test-title': validTestTitleRule,
106106
'no-empty-title': noEmptyTitleRule
107-
}
108-
};
109-
110-
mochaPlugin.configs = {
111-
all: {
112-
name: 'mocha/all',
113-
plugins: { mocha: mochaPlugin },
114-
languageOptions: { globals: globals.mocha },
115-
rules: allRules
116107
},
117-
recommended: {
118-
name: 'mocha/recommended',
119-
plugins: { mocha: mochaPlugin },
120-
languageOptions: { globals: globals.mocha },
121-
rules: recommendedRules
108+
configs: {
109+
all: {
110+
name: 'mocha/all',
111+
plugins: { mocha: {} },
112+
languageOptions: { globals: globals.mocha },
113+
rules: allRules
114+
},
115+
recommended: {
116+
name: 'mocha/recommended',
117+
plugins: { mocha: {} },
118+
languageOptions: { globals: globals.mocha },
119+
rules: recommendedRules
120+
}
122121
}
123-
};
122+
} satisfies ESLint.Plugin;
123+
124+
mochaPlugin.configs.all.plugins.mocha = mochaPlugin;
125+
mochaPlugin.configs.recommended.plugins.mocha = mochaPlugin;
124126

125127
export default mochaPlugin;

0 commit comments

Comments
 (0)