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
1 parent
bc8f463
commit d624a5f
Showing
5 changed files
with
123 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,37 @@ | ||
# Forbids use of QUnit.reset (no-reset) | ||
|
||
Early versions of QUnit exposed the `QUnit.reset()` function, which allowed | ||
consumers to invoke the internal QUnit fixture reset logic. This has been | ||
discouraged for a long time since QUnit now automatically invokes this method | ||
between tests. In QUnit 2.0, the function will be removed from the public API. | ||
Tests that rely on this functionality will need to be split into multiple tests. | ||
|
||
This rule will detect and report calls to `QUnit.reset()`. | ||
|
||
## Rule Details | ||
|
||
The following patterns are considered warnings: | ||
|
||
```js | ||
|
||
QUnit.reset(); | ||
|
||
``` | ||
|
||
The following patterns are not warnings: | ||
|
||
```js | ||
|
||
QUnit.reset; // Only attempting to invoke the function is reported | ||
|
||
``` | ||
|
||
## When Not To Use It | ||
|
||
This rule can be disabled if there are tests that rely on this functionality and | ||
there are no plans to migrate to QUnit 2.0. For the other 99.9% of use cases, | ||
use of this rule is *highly* recommended. | ||
|
||
## Further Reading | ||
|
||
* [QUnit Upgrade Guide: Stop using `QUnit.reset`](http://qunitjs.com/upgrade-guide-2.x/#stop-using-qunit-reset-split-one-test-into-multiple-tests) |
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,42 @@ | ||
/** | ||
* @fileoverview Forbids use of QUnit.reset. | ||
* @author Kevin Partington | ||
* @copyright 2016 Kevin Partington. All rights reserved. | ||
* See LICENSE file in root directory for full license. | ||
*/ | ||
"use strict"; | ||
|
||
//------------------------------------------------------------------------------ | ||
// Rule Definition | ||
//------------------------------------------------------------------------------ | ||
|
||
module.exports = function (context) { | ||
var MESSAGE = "Do not use QUnit.reset()."; | ||
|
||
function isQUnitReset(calleeNode) { | ||
return calleeNode.type === "MemberExpression" && | ||
calleeNode.object && | ||
calleeNode.object.type === "Identifier" && | ||
calleeNode.object.name === "QUnit" && | ||
calleeNode.property && | ||
calleeNode.property.type === "Identifier" && | ||
calleeNode.property.name === "reset"; | ||
} | ||
|
||
//-------------------------------------------------------------------------- | ||
// Public | ||
//-------------------------------------------------------------------------- | ||
|
||
return { | ||
"CallExpression": function (node) { | ||
if (isQUnitReset(node.callee)) { | ||
context.report({ | ||
node: node, | ||
message: MESSAGE | ||
}); | ||
} | ||
} | ||
}; | ||
}; | ||
|
||
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,41 @@ | ||
/** | ||
* @fileoverview Forbids use of QUnit.reset. | ||
* @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-reset"), | ||
RuleTester = require("eslint").RuleTester; | ||
|
||
|
||
//------------------------------------------------------------------------------ | ||
// Tests | ||
//------------------------------------------------------------------------------ | ||
|
||
var ruleTester = new RuleTester(); | ||
ruleTester.run("no-reset", rule, { | ||
|
||
valid: [ | ||
// Only invocations are reported | ||
"QUnit.reset", | ||
|
||
// Only QUnit.reset() is reported | ||
"QUnit.init()" | ||
], | ||
|
||
invalid: [ | ||
{ | ||
code: "QUnit.reset();", | ||
errors: [{ | ||
message: "Do not use QUnit.reset().", | ||
type: "CallExpression" | ||
}] | ||
} | ||
] | ||
}); |