Skip to content

Commit

Permalink
remove autofix from no-skipped-tests rule, fix #242
Browse files Browse the repository at this point in the history
  • Loading branch information
Luka Prebil Grintal committed Jul 28, 2020
1 parent 09eb3b6 commit eb19eb6
Show file tree
Hide file tree
Showing 4 changed files with 3 additions and 48 deletions.
2 changes: 1 addition & 1 deletion docs/rules/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
||| [no-return-from-async](no-return-from-async.md) | disallow returning from an async test or hook
|:heavy_check_mark:|| [no-setup-in-describe](no-setup-in-describe.md) | disallow calling functions and dot operators directly in describe blocks
|:heavy_check_mark:|| [no-sibling-hooks](no-sibling-hooks.md) | disallow duplicate uses of a hook at the same level inside a describe
|:heavy_check_mark:|:wrench:| [no-skipped-tests](no-skipped-tests.md) | disallow skipped mocha tests
|:heavy_check_mark:|| [no-skipped-tests](no-skipped-tests.md) | disallow skipped mocha tests
||| [no-synchronous-tests](no-synchronous-tests.md) | disallow synchronous tests
|:heavy_check_mark:|| [no-top-level-hooks](no-top-level-hooks.md) | disallow top-level hooks
||:wrench:| [prefer-arrow-callback](prefer-arrow-callback.md) | prefer arrow function callbacks (mocha-aware)
Expand Down
2 changes: 0 additions & 2 deletions docs/rules/no-skipped-tests.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
Mocha has a feature that allows you to skip tests by appending `.skip` to a test-suite or a test-case, or by prepending it with an `x` (e.g., `xdescribe(...)` instead of `describe(...)`).
Sometimes tests are skipped as part of a debugging process, and aren't intended to be committed. This rule reminds you to remove `.skip` or the `x` prefix from your tests.

**Fixable:** Problems detected by this rule are automatically fixable using the `--fix` flag on the command line.

## Rule Details

This rule looks for `describe.skip`, `it.skip`, `suite.skip`, `test.skip`, `context.skip`, `specify.skip`, `xdescribe`, `xit`, `xcontext` and `xspecify` occurrences within the source code.
Expand Down
26 changes: 2 additions & 24 deletions lib/rules/no-skipped-tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,25 +19,6 @@ function isCallToMochasSkipFunction(callee) {
isPropertyNamedSkip(callee.property);
}

function createSkipAutofixFunction(callee) {
const [ , endRangeOfMemberExpression ] = callee.range;
const [ , endRangeOfMemberExpressionObject ] = callee.object.range;

const rangeToRemove = [ endRangeOfMemberExpressionObject, endRangeOfMemberExpression ];

return function removeSkipProperty(fixer) {
return fixer.removeRange(rangeToRemove);
};
}

function createXAutofixFunction(callee) {
const rangeToRemove = [ callee.range[0], callee.range[0] + 1 ];

return function removeXPrefix(fixer) {
return fixer.removeRange(rangeToRemove);
};
}

function isMochaXFunction(name) {
return mochaXFunctions.indexOf(name) !== -1;
}
Expand All @@ -48,7 +29,6 @@ function isCallToMochaXFunction(callee) {

module.exports = {
meta: {
fixable: 'code',
docs: {
description: 'Disallow skipped tests'
},
Expand Down Expand Up @@ -81,14 +61,12 @@ module.exports = {
if (isCallToMochasSkipFunction(callee)) {
context.report({
node: callee.property,
message: 'Unexpected skipped mocha test.',
fix: createSkipAutofixFunction(callee)
message: 'Unexpected skipped mocha test.'
});
} else if (isCallToMochaXFunction(callee)) {
context.report({
node: callee,
message: 'Unexpected skipped mocha test.',
fix: createXAutofixFunction(callee)
message: 'Unexpected skipped mocha test.'
});
}
}
Expand Down
21 changes: 0 additions & 21 deletions test/rules/no-skipped-tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,101 +27,83 @@ ruleTester.run('no-skipped-tests', rules['no-skipped-tests'], {
{
code: 'describe.skip()',
errors: [ { message: expectedErrorMessage, column: 10, line: 1 } ],
output: 'describe()'
},
{
code: 'describe["skip"]()',
errors: [ { message: expectedErrorMessage, column: 10, line: 1 } ],
output: 'describe()'
},
{
code: 'xdescribe()',
errors: [ { message: expectedErrorMessage, column: 1, line: 1 } ],
output: 'describe()'
},
{
code: 'it.skip()',
errors: [ { message: expectedErrorMessage, column: 4, line: 1 } ],
output: 'it()'
},
{
code: 'it["skip"]()',
errors: [ { message: expectedErrorMessage, column: 4, line: 1 } ],
output: 'it()'
},
{
code: 'xit()',
errors: [ { message: expectedErrorMessage, column: 1, line: 1 } ],
output: 'it()'
},
{
code: 'suite.skip()',
errors: [ { message: expectedErrorMessage, column: 7, line: 1 } ],
output: 'suite()'
},
{
code: 'suite["skip"]()',
errors: [ { message: expectedErrorMessage, column: 7, line: 1 } ],
output: 'suite()'
},
{
code: 'test.skip()',
errors: [ { message: expectedErrorMessage, column: 6, line: 1 } ],
output: 'test()'
},
{
code: 'test["skip"]()',
errors: [ { message: expectedErrorMessage, column: 6, line: 1 } ],
output: 'test()'
},
{
code: 'context.skip()',
errors: [ { message: expectedErrorMessage, column: 9, line: 1 } ],
output: 'context()'
},
{
code: 'context["skip"]()',
errors: [ { message: expectedErrorMessage, column: 9, line: 1 } ],
output: 'context()'
},
{
code: 'xcontext()',
errors: [ { message: expectedErrorMessage, column: 1, line: 1 } ],
output: 'context()'
},
{
code: 'specify.skip()',
errors: [ { message: expectedErrorMessage, column: 9, line: 1 } ],
output: 'specify()'
},
{
code: 'xspecify()',
errors: [ { message: expectedErrorMessage, column: 1, line: 1 } ],
output: 'specify()'
},
{
code: 'custom.skip()',
settings: {
'mocha/additionalTestFunctions': [ 'custom' ]
},
errors: [ { message: expectedErrorMessage, column: 8, line: 1 } ],
output: 'custom()'
},
{
code: 'custom["skip"]()',
settings: {
'mocha/additionalTestFunctions': [ 'custom' ]
},
errors: [ { message: expectedErrorMessage, column: 8, line: 1 } ],
output: 'custom()'
},
{
code: 'xcustom()',
settings: {
'mocha/additionalXFunctions': [ 'xcustom' ]
},
errors: [ { message: expectedErrorMessage, column: 1, line: 1 } ],
output: 'custom()'
},
{
code: 'custom.skip()',
Expand All @@ -131,7 +113,6 @@ ruleTester.run('no-skipped-tests', rules['no-skipped-tests'], {
}
},
errors: [ { message: expectedErrorMessage, column: 8, line: 1 } ],
output: 'custom()'
},
{
code: 'custom["skip"]()',
Expand All @@ -141,7 +122,6 @@ ruleTester.run('no-skipped-tests', rules['no-skipped-tests'], {
}
},
errors: [ { message: expectedErrorMessage, column: 8, line: 1 } ],
output: 'custom()'
},
{
code: 'xcustom()',
Expand All @@ -151,7 +131,6 @@ ruleTester.run('no-skipped-tests', rules['no-skipped-tests'], {
}
},
errors: [ { message: expectedErrorMessage, column: 1, line: 1 } ],
output: 'custom()'
}

]
Expand Down

0 comments on commit eb19eb6

Please sign in to comment.