From b18e5900d057c2c1e5843aa38cc3c12d4bba0a91 Mon Sep 17 00:00:00 2001 From: Guillaume Martigny Date: Fri, 12 Apr 2019 23:52:09 +0200 Subject: [PATCH 1/3] Allow use of `t.title` in `use-t-well` rule Fix #176 --- rules/use-t-well.js | 13 +++++++++++++ test/use-t-well.js | 8 ++++++++ 2 files changed, 21 insertions(+) diff --git a/rules/use-t-well.js b/rules/use-t-well.js index 6fa1af3b..5ab10fa7 100644 --- a/rules/use-t-well.js +++ b/rules/use-t-well.js @@ -70,6 +70,19 @@ const create = context => { return; } + if (members[0] === 'title') { + // Anything is fine when of the form `t.title...` + if (members.length === 1 && isCallExpression(node)) { + // Except `t.title()` + context.report({ + node, + message: 'Unknown assertion method `title`.' + }); + } + + return; + } + if (isCallExpression(node)) { if (stats.other.length > 0) { context.report({ diff --git a/test/use-t-well.js b/test/use-t-well.js index 771d749b..6e8037a0 100644 --- a/test/use-t-well.js +++ b/test/use-t-well.js @@ -53,6 +53,10 @@ ruleTester.run('use-t-well', rule, { testCase('t.skip.deepEqual(a, a);'), testCase('t.context.a = 1;'), testCase('t.context.foo.skip();'), + testCase('console.log(t.context);'), + testCase('t.true(t.context.title(foo));'), + testCase('console.log(t.title);'), + testCase('t.true(t.title.includes(\'Unicorns\'));'), testCase('setImmediate(t.end);'), testCase('t.deepEqual;'), testCase('t.plan(1);'), @@ -87,6 +91,10 @@ ruleTester.run('use-t-well', rule, { code: testCase('t.context();'), errors: [error('Unknown assertion method `context`.')] }, + { + code: testCase('t.title();'), + errors: [error('Unknown assertion method `title`.')] + }, { code: testCase('t.a = 1;'), errors: [error('Unknown member `a`. Use `context.a` instead.')] From a6726fcae9b39e86a34b267905069a049fee8fde Mon Sep 17 00:00:00 2001 From: Guillaume Martigny Date: Fri, 12 Apr 2019 23:54:33 +0200 Subject: [PATCH 2/3] Add `title` example in documentation --- docs/rules/use-t-well.md | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/rules/use-t-well.md b/docs/rules/use-t-well.md index 52a975ab..7cefe408 100644 --- a/docs/rules/use-t-well.md +++ b/docs/rules/use-t-well.md @@ -30,6 +30,7 @@ import test from 'ava'; test(t => { t.deepEqual(value, [2]); t.context.a = 100; + require('fixtures/' + t.title); t.deepEqual.skip(); }); ``` From cf826bec4750c91ed326d6f6bab032642b4efe90 Mon Sep 17 00:00:00 2001 From: Sindre Sorhus Date: Tue, 30 Apr 2019 16:02:43 +0700 Subject: [PATCH 3/3] Update use-t-well.md --- docs/rules/use-t-well.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/docs/rules/use-t-well.md b/docs/rules/use-t-well.md index 7cefe408..95f96a00 100644 --- a/docs/rules/use-t-well.md +++ b/docs/rules/use-t-well.md @@ -10,7 +10,7 @@ Prevent the use of unknown assertion methods and the access to members other tha ```js import test from 'ava'; -test(t => { +test('main', t => { t(value); // `t` is not a function t.depEqual(value, [2]); // Unknown assertion method `depEqual` t.contxt.foo = 100; // Unknown member `contxt`. Use `context.contxt` instead @@ -27,10 +27,10 @@ test(t => { ```js import test from 'ava'; -test(t => { +test('main', t => { t.deepEqual(value, [2]); t.context.a = 100; - require('fixtures/' + t.title); + require(`fixtures/${t.title}`); t.deepEqual.skip(); }); ```