Skip to content

Commit

Permalink
Simplify use-t to only check the first parameter
Browse files Browse the repository at this point in the history
  • Loading branch information
novemberborn committed Sep 18, 2021
1 parent dee1802 commit c1cd7da
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 32 deletions.
8 changes: 0 additions & 8 deletions docs/rules/use-t.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,6 @@ const test = require('ava');
test('foo', foo => { // Incorrect name
t.pass();
});

test('bar', (t, bar) => { // too many arguments
t.pass();
});

test('baz', (bar, t) => { // too many arguments
t.pass();
});
```

### Pass
Expand Down
9 changes: 2 additions & 7 deletions rules/use-t.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,11 @@ const create = context => {

const functionArg = node.arguments[functionArgIndex];

if (!(functionArg && functionArg.params && functionArg.params.length > 0)) {
if (!functionArg || !functionArg.params || functionArg.params.length === 0) {
return;
}

if (functionArg.params.length > 1) {
context.report({
node,
message: 'Test should only have one parameter named `t`.'
});
} else if (functionArg.params[0].name !== 't') {
if (functionArg.params[0].name !== 't') {
context.report({
node,
message: 'Test parameter should be named `t`.'
Expand Down
19 changes: 2 additions & 17 deletions test/use-t.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,6 @@ const parameterNotNamedTErrors = [{
message: 'Test parameter should be named `t`.'
}];

const tooManyParametersErrors = [{
message: 'Test should only have one parameter named `t`.'
}];

const header = 'const test = require(\'ava\');\n';

ruleTester.run('use-t', rule, {
Expand All @@ -27,7 +23,8 @@ ruleTester.run('use-t', rule, {
header + 'test(() => {});',
header + 'test(t => {});',
header + 'test.cb(t => {});',
// Header + 'test("test name", t => {});',
header + 'test("test name", t => {});',
header + 'test((t, foo) => {});',
header + 'test(function (t) {});',
header + 'test(testFunction);',
header + 'test.todo("test name");',
Expand All @@ -53,18 +50,6 @@ ruleTester.run('use-t', rule, {
{
code: header + 'test(function (foo) {});',
errors: parameterNotNamedTErrors
},
{
code: header + 'test((t, foo) => {});',
errors: tooManyParametersErrors
},
{
code: header + 'test((foo, t) => {});',
errors: tooManyParametersErrors
},
{
code: header + 'test("test name", (t, foo) => {});',
errors: tooManyParametersErrors
}
]
});

0 comments on commit c1cd7da

Please sign in to comment.