Skip to content

Commit

Permalink
New: no-qunit-push rule (refs #20)
Browse files Browse the repository at this point in the history
  • Loading branch information
platinumazure committed May 14, 2016
1 parent 3cf4483 commit 8200f99
Show file tree
Hide file tree
Showing 5 changed files with 117 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Expand Up @@ -27,6 +27,7 @@ Below is the list of rules available in this plugin.
* [no-negated-ok](./docs/rules/no-negated-ok.md)
* [no-ok-equality](./docs/rules/no-ok-equality.md)
* [no-only](./docs/rules/no-only.md)
* [no-qunit-push](./docs/rules/no-qunit-push.md)
* [no-reassign-log-callbacks](./docs/rules/no-reassign-log-callbacks.md)
* [no-reset](./docs/rules/no-reset.md)
* [no-setup-teardown](./docs/rules/no-setup-teardown.md)
Expand Down
39 changes: 39 additions & 0 deletions docs/rules/no-qunit-push.md
@@ -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/)
2 changes: 2 additions & 0 deletions index.js
Expand Up @@ -18,6 +18,7 @@ module.exports = {
"no-negated-ok": require("./lib/rules/no-negated-ok"),
"no-ok-equality": require("./lib/rules/no-ok-equality"),
"no-only": require("./lib/rules/no-only"),
"no-qunit-push": require("./lib/rules/no-qunit-push"),
"no-reassign-log-callbacks": require("./lib/rules/no-reassign-log-callbacks"),
"no-reset": require("./lib/rules/no-reset"),
"no-setup-teardown": require("./lib/rules/no-setup-teardown"),
Expand All @@ -41,6 +42,7 @@ module.exports = {
"no-negated-ok": 0,
"no-ok-equality": 1,
"no-only": 1,
"no-qunit-push": 0,
"no-reassign-log-callbacks": 0,
"no-reset": 0,
"no-setup-teardown": 0,
Expand Down
41 changes: 41 additions & 0 deletions lib/rules/no-qunit-push.js
@@ -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 = [];
34 changes: 34 additions & 0 deletions tests/lib/rules/no-qunit-push.js
@@ -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"
}]
}
]
});

0 comments on commit 8200f99

Please sign in to comment.