1 | 'use strict';
|
2 |
|
3 | const {visitIf} = require('enhance-visitors');
|
4 | const createAvaRule = require('../create-ava-rule');
|
5 | const util = require('../util');
|
6 |
|
7 | const create = context => {
|
8 | const ava = createAvaRule();
|
9 | let nestedCount = 0;
|
10 |
|
11 | return ava.merge({
|
12 | CallExpression: visitIf([
|
13 | ava.isInTestFile,
|
14 | ava.isTestNode,
|
15 | ])(node => {
|
16 | nestedCount++;
|
17 | if (nestedCount >= 2) {
|
18 | context.report({
|
19 | node,
|
20 | message: 'Tests should not be nested.',
|
21 | });
|
22 | }
|
23 | }),
|
24 |
|
25 | 'CallExpression:exit': visitIf([
|
26 | ava.isInTestFile,
|
27 | ava.isTestNode,
|
28 | ])(() => {
|
29 | nestedCount--;
|
30 | }),
|
31 | });
|
32 | };
|
33 |
|
34 | module.exports = {
|
35 | create,
|
36 | meta: {
|
37 | type: 'problem',
|
38 | docs: {
|
39 | description: 'Ensure no tests are nested.',
|
40 | url: util.getDocsUrl(__filename),
|
41 | },
|
42 | schema: [],
|
43 | },
|
44 | };
|