eslint-plugin-mocha
Version:
Eslint rules for mocha.
57 lines • 2.17 kB
JavaScript
import { builtinRules } from 'eslint/use-at-your-own-risk';
import { createMochaVisitors } from "../ast/mocha-visitors.js";
import { isMochaCallbackReport } from "./prefer-arrow-callback-report.js";
const coreRule = builtinRules.get('prefer-arrow-callback');
const docsUrl = 'https://github.com/lo1tuma/eslint-plugin-mocha/blob/main/documentation/rules/prefer-arrow-callback.md';
if (coreRule === undefined) {
throw new Error('Unable to load the ESLint core "prefer-arrow-callback" rule.');
}
function createCoreContext(context, mochaCallbacks) {
return {
cwd: context.cwd,
filename: context.filename,
physicalFilename: context.physicalFilename,
sourceCode: context.sourceCode,
settings: context.settings,
languageOptions: context.languageOptions,
id: context.id,
options: context.options,
report(descriptor) {
if (!isMochaCallbackReport(mochaCallbacks, descriptor)) {
context.report(descriptor);
}
}
};
}
export const preferArrowCallbackRule = {
meta: {
type: coreRule.meta?.type ?? 'suggestion',
docs: {
description: coreRule.meta?.docs?.description ?? 'Require using arrow functions for callbacks',
recommended: false,
url: docsUrl
},
fixable: coreRule.meta?.fixable,
hasSuggestions: coreRule.meta?.hasSuggestions,
schema: coreRule.meta?.schema ?? [],
defaultOptions: [{
allowNamedFunctions: false,
allowUnboundThis: true
}],
messages: coreRule.meta?.messages ?? {
preferArrowCallback: 'Unexpected function expression.'
},
languages: ['js/js']
},
create(context) {
const mochaCallbacks = new WeakSet();
const coreListeners = coreRule.create(createCoreContext(context, mochaCallbacks));
return createMochaVisitors(context, {
mochaFunctionExpression(node) {
mochaCallbacks.add(node);
},
...coreListeners
});
}
};
//# sourceMappingURL=prefer-arrow-callback.js.map