1 | 'use strict';
|
2 |
|
3 | const {visitIf} = require('enhance-visitors');
|
4 | const util = require('../util');
|
5 | const createAvaRule = require('../create-ava-rule');
|
6 |
|
7 | const create = context => {
|
8 | const filename = context.getFilename();
|
9 | const [overrides] = context.options;
|
10 |
|
11 | if (filename === '<input>' || filename === '<text>') {
|
12 | return {};
|
13 | }
|
14 |
|
15 | let hasTestCall = false;
|
16 |
|
17 | const ava = createAvaRule();
|
18 | return ava.merge({
|
19 | CallExpression: visitIf([
|
20 | ava.isInTestFile,
|
21 | ava.isTestNode,
|
22 | ])(() => {
|
23 | hasTestCall = true;
|
24 | }),
|
25 | 'Program:exit'(node) {
|
26 | if (!hasTestCall) {
|
27 | return;
|
28 | }
|
29 |
|
30 | const avaHelper = util.loadAvaHelper(filename, overrides);
|
31 | if (!avaHelper) {
|
32 | return {};
|
33 | }
|
34 |
|
35 | const {isHelper, isTest} = avaHelper.classifyFile(filename);
|
36 |
|
37 | if (!isTest) {
|
38 | if (isHelper) {
|
39 | context.report({node, message: 'AVA treats this as a helper file.'});
|
40 | } else {
|
41 | context.report({node, message: 'AVA ignores this file.'});
|
42 | }
|
43 | }
|
44 |
|
45 | hasTestCall = false;
|
46 | },
|
47 | });
|
48 | };
|
49 |
|
50 | const schema = [{
|
51 | type: 'object',
|
52 | properties: {
|
53 | extensions: {
|
54 | type: 'array',
|
55 | },
|
56 | files: {
|
57 | type: 'array',
|
58 | },
|
59 | helpers: {
|
60 | type: 'array',
|
61 | },
|
62 | },
|
63 | }];
|
64 |
|
65 | module.exports = {
|
66 | create,
|
67 | meta: {
|
68 | type: 'suggestion',
|
69 | docs: {
|
70 | description: 'Ensure no tests are written in ignored files.',
|
71 | url: util.getDocsUrl(__filename),
|
72 | },
|
73 | schema,
|
74 | },
|
75 | };
|