UNPKG

eslint-plugin-mocha

Version:

Eslint rules for mocha.

42 lines 1.57 kB
import { collectCodeAfterCallbackHandlingNodes } from "../callback-handling-paths.js"; import { createTrackedCallbackVisitors } from "./callback-tracking.js"; function reportCodeAfterDone(context, trackedFunction) { const reportedNodes = collectCodeAfterCallbackHandlingNodes({ callbackBinding: trackedFunction.callbackBinding, codePath: trackedFunction.codePath, operationsBySegmentId: trackedFunction.operationsBySegmentId, sourceCode: context.sourceCode }); for (const node of reportedNodes) { context.report({ node, messageId: 'unexpectedCodeAfterDone' }); } } export const noCodeAfterDoneRule = { meta: { type: 'problem', docs: { description: 'Disallow executing code after calling a Mocha callback', recommended: true, url: 'https://github.com/lo1tuma/eslint-plugin-mocha/blob/main/documentation/rules/no-code-after-done.md' }, schema: [], messages: { unexpectedCodeAfterDone: 'Do not execute code after calling the Mocha callback' }, languages: ['js/js'] }, create(context) { return createTrackedCallbackVisitors(context, { ignorePending: false, includeInheritedCallbackBinding: true, onTrackedFunctionEnd(trackedFunction) { reportCodeAfterDone(context, trackedFunction); }, trackHandledCallbackArguments: false }); } }; //# sourceMappingURL=no-code-after-done.js.map