-
-
Notifications
You must be signed in to change notification settings - Fork 30
add --fix to no-identical-tests. #13
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 4 commits
735f228
d683339
fed45da
c576e82
626eeff
312178c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,7 +18,7 @@ module.exports = { | |
category: 'Tests', | ||
recommended: false, | ||
}, | ||
fixable: null, // or "code" or "whitespace" | ||
fixable: 'code', | ||
schema: [], | ||
}, | ||
|
||
|
@@ -41,6 +41,14 @@ module.exports = { | |
context.report({ | ||
node: test, | ||
message, | ||
fix (fixer) { | ||
const start = sourceCode.getTokenBefore(test); | ||
const end = sourceCode.getTokenAfter(test); | ||
return fixer.replaceTextRange( | ||
// should remove test's trailing comma | ||
[start.range[1], end.range[end.value === ',' ? 1 : 0]] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this will handle whitespace differently depending on whether there is a comma. If there is no comma, then all the whitespace up to the next test will be removed. If there is a comma, the whitespace up to the next test will be preserved. Maybe it would be better to be consistent about handling whitespace. |
||
, ''); | ||
}, | ||
}); | ||
} else { | ||
cache[testCode] = true; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,7 +25,7 @@ ruleTester.run('no-identical-tests', rule, { | |
new RuleTester().run('foo', bar, { | ||
valid: [ | ||
{ code: 'foo' }, | ||
{ code: 'bar' } | ||
{ code: 'bar' }, | ||
], | ||
invalid: [] | ||
}); | ||
|
@@ -38,12 +38,20 @@ ruleTester.run('no-identical-tests', rule, { | |
new RuleTester().run('foo', bar, { | ||
valid: [ | ||
{ code: 'foo' }, | ||
{ code: 'foo' } | ||
{ code: 'foo' }, | ||
], | ||
invalid: [] | ||
}); | ||
`, | ||
errors: [ERROR], | ||
output: ` | ||
new RuleTester().run('foo', bar, { | ||
valid: [ | ||
{ code: 'foo' }, | ||
], | ||
invalid: [] | ||
}); | ||
`, | ||
}, | ||
{ | ||
code: ` | ||
|
@@ -59,6 +67,16 @@ ruleTester.run('no-identical-tests', rule, { | |
}); | ||
`, | ||
errors: [ERROR, ERROR], | ||
output: ` | ||
new RuleTester().run('foo', bar, { | ||
valid: [ | ||
{ code: 'foo' }, | ||
], | ||
invalid: [ | ||
{ code: 'foo', errors: ['bar'] }, | ||
] | ||
}); | ||
`, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you add a test where there is no trailing comma? valid: [
{ code: 'foo' }
] |
||
}, | ||
], | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nitpick: This can be
fixer.removeRange
instead offixer.replaceTextRange
.Actually, maybe that would be a good rule to add to this plugin. 😄