Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Breaking: Enable checkBooleanAssertions in no-negated-ok and no-ok-equality by default #193

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/rules/no-negated-ok.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ QUnit.test('test', function (assert) {

This rule takes an optional object containing:

* `checkBooleanAssertions` (boolean, default: false): Whether the rule should check the [true](https://api.qunitjs.com/assert/true/) and [false](https://api.qunitjs.com/assert/false/) boolean assertions
* `checkBooleanAssertions` (boolean, default: true): Whether the rule should check the [true](https://api.qunitjs.com/assert/true/) and [false](https://api.qunitjs.com/assert/false/) boolean assertions
* `fixToNotOk` (boolean, default: true): Whether the rule should autofix `assert.ok(!foo)` to `assert.notOk(foo)` ([notOk](https://api.qunitjs.com/assert/notOk/) was added in QUnit 1.18)

## When Not to Use It
Expand Down
2 changes: 1 addition & 1 deletion docs/rules/no-ok-equality.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ QUnit.test("Name", function (assert) { assert.ok(x instanceof Number); });
This rule takes an optional object containing:

* `allowGlobals` (boolean, default: true): Whether the rule should check global assertions
* `checkBooleanAssertions` (boolean, default: false): Whether the rule should check the [true](https://api.qunitjs.com/assert/true/) and [false](https://api.qunitjs.com/assert/false/) boolean assertions
* `checkBooleanAssertions` (boolean, default: true): Whether the rule should check the [true](https://api.qunitjs.com/assert/true/) and [false](https://api.qunitjs.com/assert/false/) boolean assertions

## When Not to Use It

Expand Down
4 changes: 2 additions & 2 deletions lib/rules/no-negated-ok.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ module.exports = {
properties: {
checkBooleanAssertions: {
type: "boolean",
default: false
default: true
},
fixToNotOk: {
type: "boolean",
Expand All @@ -49,7 +49,7 @@ module.exports = {
},

create: function (context) {
const checkBooleanAssertions = context.options[0] && context.options[0].checkBooleanAssertions;
const checkBooleanAssertions = !context.options[0] || context.options[0].checkBooleanAssertions;
const fixToNotOk = !context.options[0] || context.options[0].fixToNotOk;

const POSITIVE_ASSERTIONS = checkBooleanAssertions ? ["ok", "true"] : ["ok"];
Expand Down
2 changes: 1 addition & 1 deletion lib/rules/no-ok-equality.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ module.exports = {
const asyncStateStack = [],
DEFAULT_OPTIONS = {
allowGlobal: true,
checkBooleanAssertions: false
checkBooleanAssertions: true
},
options = context.options[0] || DEFAULT_OPTIONS,
sourceCode = context.getSourceCode();
Expand Down
16 changes: 10 additions & 6 deletions tests/lib/rules/no-negated-ok.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,12 +111,6 @@ ruleTester.run("no-negated-ok", rule, {
options: [{ checkBooleanAssertions: true }]
},

// Boolean assertions, negation, checkBooleanAssertions = false (implicitly)
wrap("assert.true(!foo)"),
wrap("assert.true(!foo, 'message')"),
wrap("assert.false(!foo)"),
wrap("assert.false(!foo, 'message')"),

// Boolean assertions, negation, checkBooleanAssertions = false (explicitly)
{
code: wrap("assert.true(!foo)"),
Expand Down Expand Up @@ -237,6 +231,11 @@ ruleTester.run("no-negated-ok", rule, {
},

// true
{
code: wrap("assert.true(!foo)"),
output: wrap("assert.false(foo)"),
errors: [createError("assert.true")]
},
{
code: wrap("assert.true(!foo)"),
output: wrap("assert.false(foo)"),
Expand All @@ -245,6 +244,11 @@ ruleTester.run("no-negated-ok", rule, {
},

// false
{
code: wrap("assert.false(!foo)"),
output: wrap("assert.true(foo)"),
errors: [createError("assert.false")]
},
{
code: wrap("assert.false(!foo)"),
output: wrap("assert.true(foo)"),
Expand Down
20 changes: 16 additions & 4 deletions tests/lib/rules/no-ok-equality.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,10 +99,6 @@ ruleTester.run("no-ok-equality", rule, {
options: [{ checkBooleanAssertions: true }]
},

// Boolean assertions with equality checks (checkBooleanAssertions = false, implicitly)
"test('Name', function (assert) { assert.true(x === 1); });",
"test('Name', function (assert) { assert.false(x === 1); });",

// Boolean assertions with equality checks (checkBooleanAssertions = false, explicitly)
{
code: "test('Name', function (assert) { assert.true(x === 1); });",
Expand Down Expand Up @@ -244,6 +240,22 @@ ruleTester.run("no-ok-equality", rule, {
]
},

// Boolean assertions with equality checks (checkBooleanAssertions = true, implicitly)
{
code: "test('Name', function (assert) { assert.true(x === 1); });",
output: "test('Name', function (assert) { assert.strictEqual(x, 1); });",
errors: [
createError("assert.true", "assert.strictEqual", "x", "1")
]
},
{
code: "test('Name', function (assert) { assert.false(x === 1); });",
output: "test('Name', function (assert) { assert.notStrictEqual(x, 1); });",
errors: [
createError("assert.false", "assert.notStrictEqual", "x", "1")
]
},

// Boolean assertions with equality checks (checkBooleanAssertions = true, explicitly)
{
// true
Expand Down