blob: 86fdf63d7283f8e640b74e42d178c5509ba7b40c [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: {
9 description: 'Disallow hooks'
10 },
11 schema: [
12 {
13 type: 'object',
14 properties: {
15 allow: {
16 type: 'array',
17 items: {
18 type: 'string'
19 }
20 }
21 },
22 additionalProperties: false
Jack Franklin8b9aa2f2020-02-12 16:35:15 +000023 }
Tim van der Lippe16aca392020-11-13 11:37:13 +000024 ]
25 },
26
27 create(context) {
28 const astUtils = createAstUtils(context.settings);
29 const [ config = {} ] = context.options;
30 const { allow = [] } = config;
31
32 return {
33 CallExpression(node) {
34 const isHookAllowed = allow.includes(node.callee.name);
35
36 if (astUtils.isHookIdentifier(node.callee) && !isHookAllowed) {
37 context.report({
38 node: node.callee,
39 message: `Unexpected use of Mocha \`${ node.callee.name }\` hook`
40 });
41 }
42 }
43 };
44 }
Jack Franklin8b9aa2f2020-02-12 16:35:15 +000045};