1 | 'use strict';
|
2 |
|
3 | const {visitIf} = require('enhance-visitors');
|
4 | const util = require('../util');
|
5 | const createAvaRule = require('../create-ava-rule');
|
6 |
|
7 | function sortByName(a, b) {
|
8 | if (a.name < b.name) {
|
9 | return -1;
|
10 | }
|
11 |
|
12 | if (a.name > b.name) {
|
13 | return 1;
|
14 | }
|
15 |
|
16 | return 0;
|
17 | }
|
18 |
|
19 | const create = context => {
|
20 | const ava = createAvaRule();
|
21 |
|
22 | return ava.merge({
|
23 | CallExpression: visitIf([
|
24 | ava.isInTestFile,
|
25 | ava.isTestNode,
|
26 | ])(node => {
|
27 | const testModifiers = util.getTestModifiers(node).sort(sortByName);
|
28 |
|
29 | if (testModifiers.length === 0) {
|
30 | return;
|
31 | }
|
32 |
|
33 |
|
34 |
|
35 | testModifiers.reduce((previous, current) => {
|
36 | if (previous.name === current.name) {
|
37 | context.report({
|
38 | node: current,
|
39 | message: `Duplicate test modifier \`.${current.name}\`.`,
|
40 | });
|
41 | }
|
42 |
|
43 | return current;
|
44 | });
|
45 | }),
|
46 | });
|
47 | };
|
48 |
|
49 | module.exports = {
|
50 | create,
|
51 | meta: {
|
52 | type: 'problem',
|
53 | docs: {
|
54 | description: 'Ensure tests do not have duplicate modifiers.',
|
55 | url: util.getDocsUrl(__filename),
|
56 | },
|
57 | schema: [],
|
58 | },
|
59 | };
|