Skip to content
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

Adds fix option to rule #19

Merged
merged 1 commit into from
Apr 7, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 15 additions & 2 deletions rules/no-only-tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ module.exports = {
recommended: true,
url: 'https://github.com/levibuzolic/eslint-plugin-no-only-tests',
},
fixable: true,
schema: [
{
type: 'object',
Expand Down Expand Up @@ -55,14 +56,26 @@ module.exports = {

var parentName = parentObject.name;

function fix(fixer) {
return fixer.removeRange([node.range[0] - 1, node.range[1]]);
}

if (parentName != null && block.indexOf(parentName) != -1) {
context.report(node, parentName + '.' + node.name + ' not permitted');
context.report({
node,
message: parentName + '.' + node.name + ' not permitted',
fix
});
}

var parentParentName = dotName(parentObject);

if (parentParentName != null && block.indexOf(parentParentName) != -1) {
context.report(node, parentParentName + '.' + node.name + ' not permitted');
context.report({
node,
message: parentParentName + '.' + node.name + ' not permitted',
fix
});
}
},
};
Expand Down
10 changes: 10 additions & 0 deletions tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,44 +29,54 @@ ruleTester.run('no-only-tests', rules['no-only-tests'], {
{
code: 'describe.only("Some describe block", function() {});',
errors: [{message: 'describe.only not permitted'}],
output: 'describe("Some describe block", function() {});'
},
{
code: 'it.only("Some assertion", function() {});',
output: 'it("Some assertion", function() {});',
errors: [{message: 'it.only not permitted'}],
},
{
code: 'context.only("Some context", function() {});',
output: 'context("Some context", function() {});',
errors: [{message: 'context.only not permitted'}],
},
{
code: 'test.only("Some test", function() {});',
output: 'test("Some test", function() {});',
errors: [{message: 'test.only not permitted'}],
},
{
code: 'tape.only("A tape", function() {});',
output: 'tape("A tape", function() {});',
errors: [{message: 'tape.only not permitted'}],
},
{
code: 'fixture.only("A fixture", function() {});',
output: 'fixture("A fixture", function() {});',
errors: [{message: 'fixture.only not permitted'}],
},
{
code: 'serial.only("A serial test", function() {});',
output: 'serial("A serial test", function() {});',
errors: [{message: 'serial.only not permitted'}],
},
{
options: [{block: ['obscureTestBlock']}],
code: 'obscureTestBlock.only("An obscure testing library test", function() {});',
output: 'obscureTestBlock("An obscure testing library test", function() {});',
errors: [{message: 'obscureTestBlock.only not permitted'}],
},
{
options: [{block: ['ava.default']}],
code: 'ava.default.only("Block with dot", function() {});',
output: 'ava.default("Block with dot", function() {});',
errors: [{message: 'ava.default.only not permitted'}],
},
{
options: [{focus: ['focus']}],
code: 'test.focus("An alternative focus function", function() {});',
output: 'test("An alternative focus function", function() {});',
errors: [{message: 'test.focus not permitted'}],
},
],
Expand Down