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 |
|
10 | return ava.merge({
|
11 | CallExpression: visitIf([
|
12 | ava.isInTestFile,
|
13 | ava.isTestNode,
|
14 | ])(node => {
|
15 | const index = node.arguments.length - 1;
|
16 | if (index > 1) {
|
17 | return;
|
18 | }
|
19 |
|
20 | let implementationArgument = node.arguments[index];
|
21 | if (ava.hasTestModifier('macro') && implementationArgument.type === 'ObjectExpression') {
|
22 | const execProperty = implementationArgument.properties.find(p => p.key.name === 'exec');
|
23 | implementationArgument = execProperty?.value;
|
24 | }
|
25 |
|
26 | if (!implementationArgument || !implementationArgument.params || implementationArgument.params.length === 0) {
|
27 | return;
|
28 | }
|
29 |
|
30 | if (implementationArgument.params[0].name !== 't') {
|
31 | context.report({
|
32 | node,
|
33 | message: 'Test parameter should be named `t`.',
|
34 | });
|
35 | }
|
36 | }),
|
37 | });
|
38 | };
|
39 |
|
40 | module.exports = {
|
41 | create,
|
42 | meta: {
|
43 | type: 'suggestion',
|
44 | docs: {
|
45 | description: 'Ensure test functions use `t` as their parameter.',
|
46 | url: util.getDocsUrl(__filename),
|
47 | },
|
48 | schema: [],
|
49 | },
|
50 | };
|