-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #10 from levibuzolic/config-blocks-and-focus
Allow users to configure their own block/focus matchers in their eslint config
- Loading branch information
Showing
7 changed files
with
862 additions
and
17 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
arrowParens: avoid | ||
bracketSpacing: false | ||
jsxBracketSameLine: false | ||
parser: babel-flow | ||
printWidth: 120 | ||
semi: true | ||
singleQuote: true | ||
trailingComma: es5 | ||
useTabs: false |
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
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 |
---|---|---|
@@ -1,31 +1,63 @@ | ||
/** | ||
* @fileoverview Rule to flag use of .only blocks in tests | ||
* @fileoverview Rule to flag use of .only in tests, preventing focused tests being committed accidentally | ||
* @author Levi Buzolic | ||
*/ | ||
|
||
"use strict"; | ||
'use strict'; | ||
|
||
//------------------------------------------------------------------------------ | ||
// Rule Definition | ||
//------------------------------------------------------------------------------ | ||
|
||
const BLOCK_DEFAULTS = ['describe', 'it', 'context', 'test', 'tape', 'fixture', 'serial']; | ||
const FOCUS_DEFAULTS = ['only']; | ||
|
||
module.exports = { | ||
meta: { | ||
docs: { | ||
description: "disallow .only blocks in tests", | ||
category: "Possible Errors", | ||
} | ||
description: 'disallow .only blocks in tests', | ||
category: 'Possible Errors', | ||
recommended: true, | ||
url: 'https://github.com/levibuzolic/eslint-plugin-no-only-tests', | ||
}, | ||
schema: [ | ||
{ | ||
type: 'object', | ||
properties: { | ||
block: { | ||
type: 'array', | ||
items: { | ||
type: 'string', | ||
}, | ||
uniqueItems: true, | ||
}, | ||
focus: { | ||
type: 'array', | ||
items: { | ||
type: 'string', | ||
}, | ||
uniqueItems: true, | ||
}, | ||
}, | ||
additionalProperties: false, | ||
}, | ||
], | ||
}, | ||
|
||
create(context) { | ||
const regex = /^(describe|it|context|test|tape|fixture|serial)$/; | ||
var block = (context.options[0] || {}).block || BLOCK_DEFAULTS; | ||
var focus = (context.options[0] || {}).focus || FOCUS_DEFAULTS; | ||
|
||
return { | ||
Identifier: function(node) { | ||
if (node.name === 'only' && node.parent && node.parent.object && regex.test(node.parent.object.name)) { | ||
context.report(node, node.parent.object.name + '.only not permitted'); | ||
Identifier(node) { | ||
if ( | ||
focus.indexOf(node.name) != -1 && | ||
node.parent && | ||
node.parent.object && | ||
block.indexOf(node.parent.object.name) != -1 | ||
) { | ||
context.report(node, node.parent.object.name + '.' + node.name + ' not permitted'); | ||
} | ||
} | ||
} | ||
} | ||
}, | ||
}; | ||
}, | ||
}; |
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
Oops, something went wrong.