-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
New: no-global-stop-start rule (refs #20)
- Loading branch information
1 parent
8af3dbf
commit fb9ef12
Showing
5 changed files
with
131 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
# Forbid use of global stop()/start() (no-global-stop-start) | ||
|
||
QUnit 2.0 is deprecating and removing all of its global exports, including | ||
`stop()` and `start()`. | ||
|
||
## Rule Details | ||
|
||
The following patterns are considered warnings: | ||
|
||
```js | ||
|
||
stop(); | ||
|
||
start(); | ||
|
||
``` | ||
|
||
The following patterns are not warnings: | ||
|
||
```js | ||
|
||
QUnit.stop(); | ||
|
||
QUnit.start(); | ||
|
||
var done = assert.async(); | ||
done(); | ||
|
||
``` | ||
|
||
## When Not To Use It | ||
|
||
If you are working in a codebase that will not use QUnit 2.0, this rule can be | ||
safely disabled. | ||
|
||
## Further Reading | ||
|
||
* [QUnit 2.0 Migration Guide: Stop using stop/start](http://qunitjs.com/upgrade-guide-2.x/#replace-stop-and-start-with-assert-async) |
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,45 @@ | ||
/** | ||
* @fileoverview Forbid use of global stop()/start(). | ||
* @author Kevin Partington | ||
* @copyright 2016 Kevin Partington. All rights reserved. | ||
* See LICENSE file in root directory for full license. | ||
*/ | ||
"use strict"; | ||
|
||
var utils = require("../utils"); | ||
|
||
//------------------------------------------------------------------------------ | ||
// Rule Definition | ||
//------------------------------------------------------------------------------ | ||
|
||
module.exports = function (context) { | ||
var MESSAGE = "Unexpected global {{callee}}() call."; | ||
|
||
function isGlobalStop(calleeNode) { | ||
return calleeNode.type === "Identifier" && utils.isStop(calleeNode); | ||
} | ||
|
||
function isGlobalStart(calleeNode) { | ||
return calleeNode.type === "Identifier" && utils.isStart(calleeNode); | ||
} | ||
|
||
//-------------------------------------------------------------------------- | ||
// Public | ||
//-------------------------------------------------------------------------- | ||
|
||
return { | ||
"CallExpression": function (node) { | ||
if (isGlobalStop(node.callee) || isGlobalStart(node.callee)) { | ||
context.report({ | ||
node: node, | ||
message: MESSAGE, | ||
data: { | ||
callee: node.callee.name | ||
} | ||
}); | ||
} | ||
} | ||
}; | ||
}; | ||
|
||
module.exports.schema = []; |
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,45 @@ | ||
/** | ||
* @fileoverview Forbid use of global stop()/start(). | ||
* @author Kevin Partington | ||
* @copyright 2016 Kevin Partington. All rights reserved. | ||
* See LICENSE file in root directory for full license. | ||
*/ | ||
"use strict"; | ||
|
||
//------------------------------------------------------------------------------ | ||
// Requirements | ||
//------------------------------------------------------------------------------ | ||
|
||
var rule = require("../../../lib/rules/no-global-stop-start"), | ||
RuleTester = require("eslint").RuleTester; | ||
|
||
|
||
//------------------------------------------------------------------------------ | ||
// Tests | ||
//------------------------------------------------------------------------------ | ||
|
||
var ruleTester = new RuleTester(); | ||
ruleTester.run("no-global-stop-start", rule, { | ||
|
||
valid: [ | ||
"QUnit.stop();", | ||
"QUnit.start();" | ||
], | ||
|
||
invalid: [ | ||
{ | ||
code: "stop();", | ||
errors: [{ | ||
message: "Unexpected global stop() call.", | ||
type: "CallExpression" | ||
}] | ||
}, | ||
{ | ||
code: "start();", | ||
errors: [{ | ||
message: "Unexpected global start() call.", | ||
type: "CallExpression" | ||
}] | ||
} | ||
] | ||
}); |