Skip to content

Commit

Permalink
Use suggestions API for no-only-test, no-skip-test
Browse files Browse the repository at this point in the history
  • Loading branch information
edbrannin committed Mar 19, 2021
1 parent 8afafdc commit 6aeafdb
Show file tree
Hide file tree
Showing 4 changed files with 90 additions and 42 deletions.
17 changes: 10 additions & 7 deletions rules/no-only-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
}));
}
}]
});
}
})
Expand Down
17 changes: 10 additions & 7 deletions rules/no-skip-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
}));
}
}]
});
}
})
Expand Down
63 changes: 45 additions & 18 deletions test/no-only-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(); });'
}]
}]
}
]
Expand Down
35 changes: 25 additions & 10 deletions test/no-skip-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(); });'
}]
}]
}
]
Expand Down

0 comments on commit 6aeafdb

Please sign in to comment.