diff --git a/rules/no-only-tests.js b/rules/no-only-tests.js index 85fcb56..16173db 100644 --- a/rules/no-only-tests.js +++ b/rules/no-only-tests.js @@ -20,6 +20,7 @@ module.exports = { recommended: true, url: 'https://github.com/levibuzolic/eslint-plugin-no-only-tests', }, + fixable: true, schema: [ { type: 'object', @@ -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 + }); } }, }; diff --git a/tests.js b/tests.js index d760cd9..2023f45 100644 --- a/tests.js +++ b/tests.js @@ -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'}], }, ],