-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
69 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
'use strict'; | ||
|
||
function isOnlyMethodCall(callee) { | ||
return callee.type === 'MemberExpression' && | ||
callee.object.name === 'Scenario' && | ||
callee.property.name === 'only'; | ||
} | ||
|
||
module.exports = { | ||
meta: { | ||
docs: { | ||
description: '', | ||
category: 'Best Practices', | ||
recommended: true | ||
}, | ||
fixable: 'code', | ||
messages: { | ||
exclusiveTest: 'Unexpected exclusive test' | ||
}, | ||
schema: [] | ||
}, | ||
create: function (context) { | ||
return { | ||
CallExpression: function (node) { | ||
if (isOnlyMethodCall(node.callee)) { | ||
context.report({ | ||
node: node, | ||
messageId: 'exclusiveTest', | ||
fix: function (fixer) { | ||
var start = node.callee.object.range[1]; | ||
var end = node.callee.range[1]; | ||
return fixer.removeRange([start, end]) | ||
} | ||
}); | ||
} | ||
} | ||
}; | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
'use strict'; | ||
|
||
var RuleTester = require('eslint').RuleTester; | ||
|
||
var rule = require('../../../lib/rules/no-exclusive-tests'); | ||
|
||
var ruleTester = new RuleTester(); | ||
|
||
function invalidScenario (code) { | ||
return { | ||
code: code, | ||
parserOptions: { ecmaVersion: 6 }, | ||
errors: [ | ||
{ message: 'Unexpected exclusive test' } | ||
] | ||
}; | ||
} | ||
|
||
ruleTester.run('no-exclusive-tests', rule, { | ||
valid: [ | ||
'Scenario("this is cool", function () {});' | ||
], | ||
invalid: [ | ||
invalidScenario('Scenario.only("this is not", function () {});') | ||
], | ||
}); |