From 6aeafdb641443de0fee8fadb5ff54244725f3193 Mon Sep 17 00:00:00 2001 From: Ed Brannin Date: Fri, 19 Mar 2021 08:16:47 -0400 Subject: [PATCH] Use suggestions API for no-only-test, no-skip-test https://github.com/avajs/eslint-plugin-ava/pull/324 https://github.com/avajs/eslint-plugin-ava/issues/281#issuecomment-587137623 --- rules/no-only-test.js | 17 +++++++----- rules/no-skip-test.js | 17 +++++++----- test/no-only-test.js | 63 ++++++++++++++++++++++++++++++------------- test/no-skip-test.js | 35 +++++++++++++++++------- 4 files changed, 90 insertions(+), 42 deletions(-) diff --git a/rules/no-only-test.js b/rules/no-only-test.js index 57edd26d..f0a0dc67 100644 --- a/rules/no-only-test.js +++ b/rules/no-only-test.js @@ -16,13 +16,16 @@ const create = context => { context.report({ node: propertyNode, message: '`test.only()` should not be used.', - fix: fixer => { - return fixer.replaceTextRange.apply(null, util.removeTestModifier({ - modifier: 'only', - node, - context - })); - } + suggest: [{ + desc: 'Remove the `.only`', + fix: fixer => { + return fixer.replaceTextRange.apply(null, util.removeTestModifier({ + modifier: 'only', + node, + context + })); + } + }] }); } }) diff --git a/rules/no-skip-test.js b/rules/no-skip-test.js index b32e0a7b..ae9379bf 100644 --- a/rules/no-skip-test.js +++ b/rules/no-skip-test.js @@ -16,13 +16,16 @@ const create = context => { context.report({ node: propertyNode, message: 'No tests should be skipped.', - fix: fixer => { - return fixer.replaceTextRange.apply(null, util.removeTestModifier({ - modifier: 'skip', - node, - context - })); - } + suggest: [{ + desc: 'Remove the `.skip`', + fix: fixer => { + return fixer.replaceTextRange.apply(null, util.removeTestModifier({ + modifier: 'skip', + node, + context + })); + } + }] }); } }) diff --git a/test/no-only-test.js b/test/no-only-test.js index 2ec5c5b8..cecf9d38 100644 --- a/test/no-only-test.js +++ b/test/no-only-test.js @@ -26,92 +26,119 @@ ruleTester.run('no-only-test', rule, { invalid: [ { code: header + 'test\n\t.only(t => { t.pass(); });', - output: header + 'test\n\t(t => { t.pass(); });', errors: [{ message, type: 'Identifier', line: 3, - column: 3 + column: 3, + suggestions: [{ + desc: 'Remove the `.only`', + output: header + 'test\n\t(t => { t.pass(); });' + }] }] }, { code: header + 'test\n .only(t => { t.pass(); });', - output: header + 'test\n (t => { t.pass(); });', errors: [{ message, type: 'Identifier', line: 3, - column: 4 + column: 4, + suggestions: [{ + desc: 'Remove the `.only`', + output: header + 'test\n (t => { t.pass(); });' + }] }] }, { code: header + 'test\t.only(t => { t.pass(); });', - output: header + 'test\t(t => { t.pass(); });', errors: [{ message, type: 'Identifier', line: 2, - column: 7 + column: 7, + suggestions: [{ + desc: 'Remove the `.only`', + output: header + 'test\t(t => { t.pass(); });' + }] }] }, { code: header + 'test .only(t => { t.pass(); });', - output: header + 'test (t => { t.pass(); });', errors: [{ message, type: 'Identifier', line: 2, - column: 8 + column: 8, + suggestions: [{ + desc: 'Remove the `.only`', + output: header + 'test (t => { t.pass(); });' + }] }] }, { code: header + 'test.\n\tonly(t => { t.pass(); });', - output: header + 'test\n\t(t => { t.pass(); });', errors: [{ message, type: 'Identifier', line: 3, - column: 2 + column: 2, + suggestions: [{ + desc: 'Remove the `.only`', + output: header + 'test\n\t(t => { t.pass(); });' + }] }] }, { code: header + 'test.\n only(t => { t.pass(); });', - output: header + 'test\n (t => { t.pass(); });', errors: [{ message, type: 'Identifier', line: 3, - column: 3 + column: 3, + suggestions: [{ + desc: 'Remove the `.only`', + output: header + 'test\n (t => { t.pass(); });' + }] }] }, { code: header + 'test.only(t => { t.pass(); });', - output: header + 'test(t => { t.pass(); });', errors: [{ message, type: 'Identifier', line: 2, - column: 6 + column: 6, + suggestions: [{ + desc: 'Remove the `.only`', + output: header + 'test(t => { t.pass(); });' + }] }] }, { code: header + 'test.cb.only(t => { t.pass(); t.end(); });', - output: header + 'test.cb(t => { t.pass(); t.end(); });', errors: [{ message, type: 'Identifier', line: 2, - column: 9 + column: 9, + suggestions: [{ + desc: 'Remove the `.only`', + output: header + 'test.cb(t => { t.pass(); t.end(); });' + }] }] }, { code: header + 'test.only.cb(t => { t.pass(); t.end(); });', - output: header + 'test.cb(t => { t.pass(); t.end(); });', errors: [{ message, type: 'Identifier', line: 2, - column: 6 + column: 6, + suggestions: [{ + desc: 'Remove the `.only`', + output: header + 'test.cb(t => { t.pass(); t.end(); });' + }] }] } ] diff --git a/test/no-skip-test.js b/test/no-skip-test.js index f3de151c..cd6e60a3 100644 --- a/test/no-skip-test.js +++ b/test/no-skip-test.js @@ -24,52 +24,67 @@ ruleTester.run('no-skip-test', rule, { invalid: [ { code: header + 'test.skip(t => { t.pass(); });', - output: header + 'test(t => { t.pass(); });', errors: [{ message, type: 'Identifier', line: 2, - column: 6 + column: 6, + suggestions: [{ + desc: 'Remove the `.skip`', + output: header + 'test(t => { t.pass(); });' + }] }] }, { code: header + 'test.cb.skip(t => { t.pass(); t.end(); });', - output: header + 'test.cb(t => { t.pass(); t.end(); });', errors: [{ message, type: 'Identifier', line: 2, - column: 9 + column: 9, + suggestions: [{ + desc: 'Remove the `.skip`', + output: header + 'test.cb(t => { t.pass(); t.end(); });' + }] }] }, { code: header + 'test.skip.cb(t => { t.pass(); t.end(); });', - output: header + 'test.cb(t => { t.pass(); t.end(); });', errors: [{ message, type: 'Identifier', line: 2, - column: 6 + column: 6, + suggestions: [{ + desc: 'Remove the `.skip`', + output: header + 'test.cb(t => { t.pass(); t.end(); });' + }] }] }, { code: header + 'test.\n\tskip.cb(t => { t.pass(); t.end(); });', - output: header + 'test\n\t.cb(t => { t.pass(); t.end(); });', errors: [{ message, type: 'Identifier', line: 3, - column: 2 + column: 2, + suggestions: [{ + desc: 'Remove the `.skip`', + output: header + 'test\n\t.cb(t => { t.pass(); t.end(); });' + }] }] }, { code: header + 'test .skip .cb(t => { t.pass(); t.end(); });', - output: header + 'test .cb(t => { t.pass(); t.end(); });', errors: [{ message, type: 'Identifier', line: 2, - column: 8 + column: 8, + suggestions: [{ + desc: 'Remove the `.skip`', + output: header + 'test .cb(t => { t.pass(); t.end(); });' + }] }] } ]