Skip to content

Commit 0ded4b5

Browse files
GMartignysindresorhus
authored andcommitted
Allow the use of t.title with the use-t-well rule (#233)
Fixes #176
1 parent 4173078 commit 0ded4b5

File tree

3 files changed

+24
-2
lines changed

3 files changed

+24
-2
lines changed

docs/rules/use-t-well.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ Prevent the use of unknown assertion methods and the access to members other tha
1010
```js
1111
import test from 'ava';
1212

13-
test(t => {
13+
test('main', t => {
1414
t(value); // `t` is not a function
1515
t.depEqual(value, [2]); // Unknown assertion method `depEqual`
1616
t.contxt.foo = 100; // Unknown member `contxt`. Use `context.contxt` instead
@@ -27,9 +27,10 @@ test(t => {
2727
```js
2828
import test from 'ava';
2929

30-
test(t => {
30+
test('main', t => {
3131
t.deepEqual(value, [2]);
3232
t.context.a = 100;
33+
require(`fixtures/${t.title}`);
3334
t.deepEqual.skip();
3435
});
3536
```

rules/use-t-well.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,19 @@ const create = context => {
7070
return;
7171
}
7272

73+
if (members[0] === 'title') {
74+
// Anything is fine when of the form `t.title...`
75+
if (members.length === 1 && isCallExpression(node)) {
76+
// Except `t.title()`
77+
context.report({
78+
node,
79+
message: 'Unknown assertion method `title`.'
80+
});
81+
}
82+
83+
return;
84+
}
85+
7386
if (isCallExpression(node)) {
7487
if (stats.other.length > 0) {
7588
context.report({

test/use-t-well.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,10 @@ ruleTester.run('use-t-well', rule, {
5353
testCase('t.skip.deepEqual(a, a);'),
5454
testCase('t.context.a = 1;'),
5555
testCase('t.context.foo.skip();'),
56+
testCase('console.log(t.context);'),
57+
testCase('t.true(t.context.title(foo));'),
58+
testCase('console.log(t.title);'),
59+
testCase('t.true(t.title.includes(\'Unicorns\'));'),
5660
testCase('setImmediate(t.end);'),
5761
testCase('t.deepEqual;'),
5862
testCase('t.plan(1);'),
@@ -87,6 +91,10 @@ ruleTester.run('use-t-well', rule, {
8791
code: testCase('t.context();'),
8892
errors: [error('Unknown assertion method `context`.')]
8993
},
94+
{
95+
code: testCase('t.title();'),
96+
errors: [error('Unknown assertion method `title`.')]
97+
},
9098
{
9199
code: testCase('t.a = 1;'),
92100
errors: [error('Unknown member `a`. Use `context.a` instead.')]

0 commit comments

Comments
 (0)