UNPKG

993 BJavaScriptView Raw
1'use strict';
2
3const {visitIf} = require('enhance-visitors');
4const util = require('../util');
5const createAvaRule = require('../create-ava-rule');
6
7const modifiers = new Set([
8 'after',
9 'afterEach',
10 'always',
11 'before',
12 'beforeEach',
13 'default',
14 'only',
15 'serial',
16 'skip',
17 'todo',
18 'failing',
19 'macro',
20]);
21
22const unknownModifiers = node => util.getTestModifiers(node)
23 .filter(modifier => !modifiers.has(modifier.name));
24
25const create = context => {
26 const ava = createAvaRule();
27
28 return ava.merge({
29 CallExpression: visitIf([
30 ava.isInTestFile,
31 ava.isTestNode,
32 ])(node => {
33 const unknown = unknownModifiers(node);
34
35 if (unknown.length > 0) {
36 context.report({
37 node: unknown[0],
38 message: `Unknown test modifier \`.${unknown[0].name}\`.`,
39 });
40 }
41 }),
42 });
43};
44
45module.exports = {
46 create,
47 meta: {
48 type: 'problem',
49 docs: {
50 description: 'Disallow the use of unknown test modifiers.',
51 url: util.getDocsUrl(__filename),
52 },
53 schema: [],
54 },
55};