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
3cf4483
commit 8200f99
Showing
5 changed files
with
117 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,39 @@ | ||
# Forbid the use of QUnit.push (no-qunit-push) | ||
|
||
When writing custom assertions, the proper way to log an assertion result | ||
used to be calling `QUnit.push()` with the assertion result data. However, in | ||
order to allow for better control of test context, `QUnit.push` has been | ||
deprecated (to be removed in 2.0) and the correct way to log the assertion | ||
result is to call `this.pushResult()` from within the assertion function. | ||
|
||
## Rule Details | ||
|
||
The following patterns are considered warnings: | ||
|
||
```js | ||
|
||
QUnit.push(result, actual, expected, message); | ||
|
||
``` | ||
|
||
The following patterns are not warnings: | ||
|
||
```js | ||
|
||
this.pushResult({ | ||
result: result, | ||
actual: actual, | ||
expected: expected, | ||
message: message | ||
}); | ||
|
||
``` | ||
|
||
## When Not To Use It | ||
|
||
This rule may be safely disabled if you are working in a legacy codebase that | ||
will not be migrated to QUnit 2.0. | ||
|
||
## Further Reading | ||
|
||
* [QUnit.push()](http://api.qunitjs.com/QUnit.push/) |
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,41 @@ | ||
/** | ||
* @fileoverview Forbid the use of QUnit.push. | ||
* @author Kevin Partington | ||
*/ | ||
"use strict"; | ||
|
||
//------------------------------------------------------------------------------ | ||
// Rule Definition | ||
//------------------------------------------------------------------------------ | ||
|
||
module.exports = function (context) { | ||
var MESSAGE = "Do not use QUnit.push()."; | ||
|
||
function isQUnitPush(calleeNode) { | ||
return calleeNode && | ||
calleeNode.type === "MemberExpression" && | ||
calleeNode.object && | ||
calleeNode.object.type === "Identifier" && | ||
calleeNode.object.name === "QUnit" && | ||
calleeNode.property && | ||
calleeNode.property.type === "Identifier" && | ||
calleeNode.property.name === "push"; | ||
} | ||
|
||
//-------------------------------------------------------------------------- | ||
// Public | ||
//-------------------------------------------------------------------------- | ||
|
||
return { | ||
"CallExpression": function (node) { | ||
if (isQUnitPush(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,34 @@ | ||
/** | ||
* @fileoverview Forbid the use of QUnit.push. | ||
* @author Kevin Partington | ||
*/ | ||
"use strict"; | ||
|
||
//------------------------------------------------------------------------------ | ||
// Requirements | ||
//------------------------------------------------------------------------------ | ||
|
||
var rule = require("../../../lib/rules/no-qunit-push"), | ||
RuleTester = require("eslint").RuleTester; | ||
|
||
|
||
//------------------------------------------------------------------------------ | ||
// Tests | ||
//------------------------------------------------------------------------------ | ||
|
||
var ruleTester = new RuleTester(); | ||
ruleTester.run("no-qunit-push", rule, { | ||
valid: [ | ||
"this.pushResult({ result: result, actual: actual, expected: expected, message: message });" | ||
], | ||
|
||
invalid: [ | ||
{ | ||
code: "QUnit.push(result, actual, expected, message);", | ||
errors: [{ | ||
message: "Do not use QUnit.push().", | ||
type: "CallExpression" | ||
}] | ||
} | ||
] | ||
}); |