blob: a85229924c959ced995893e038eb84a9c7d2a3c3 [file] [log] [blame]
Jack Franklin8b9aa2f2020-02-12 16:35:15 +00001'use strict';
2
Tim van der Lippe16aca392020-11-13 11:37:13 +00003const createAstUtils = require('../util/ast');
Jack Franklin8b9aa2f2020-02-12 16:35:15 +00004
Tim van der Lippe16aca392020-11-13 11:37:13 +00005module.exports = {
6 meta: {
7 type: 'suggestion',
8 docs: {
Tim van der Lippe0ceb4652022-01-06 14:23:36 +01009 description: 'Disallow hooks',
10 url: 'https://github.com/lo1tuma/eslint-plugin-mocha/blob/master/docs/rules/no-hooks.md'
Tim van der Lippe16aca392020-11-13 11:37:13 +000011 },
12 schema: [
13 {
14 type: 'object',
15 properties: {
16 allow: {
17 type: 'array',
18 items: {
19 type: 'string'
20 }
21 }
22 },
23 additionalProperties: false
Jack Franklin8b9aa2f2020-02-12 16:35:15 +000024 }
Tim van der Lippe16aca392020-11-13 11:37:13 +000025 ]
26 },
27
28 create(context) {
29 const astUtils = createAstUtils(context.settings);
30 const [ config = {} ] = context.options;
31 const { allow = [] } = config;
32
33 return {
34 CallExpression(node) {
35 const isHookAllowed = allow.includes(node.callee.name);
36
37 if (astUtils.isHookIdentifier(node.callee) && !isHookAllowed) {
38 context.report({
39 node: node.callee,
40 message: `Unexpected use of Mocha \`${ node.callee.name }\` hook`
41 });
42 }
43 }
44 };
45 }
Jack Franklin8b9aa2f2020-02-12 16:35:15 +000046};