Skip to content

Commit 1c5935b

Browse files
authored
feat!: change require-expect rule default option to never-except-zero (#375)
BREAKING CHANGE
1 parent 391647e commit 1c5935b

3 files changed

Lines changed: 13 additions & 13 deletions

File tree

docs/rules/require-expect.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ test. This rule checks for `expect` at linting time.
1515

1616
The "always" option requires that `expect` is called in each test.
1717

18-
The "except-simple" (**default**) option only requires an `expect` call when an assertion is
18+
The "except-simple" option only requires an `expect` call when an assertion is
1919
called inside of a block or when `assert` is passed to another function. The
2020
rationale here is that by wrapping `assert` statements in conditional blocks
2121
or callbacks, developers are at risk of creating tests that incorrectly pass
@@ -26,7 +26,7 @@ resilience in QUnit 2.0 for tracking asynchronous activity, projects may
2626
prefer to discourage use of redundant `assert.expect` calls in tests. This
2727
option codifies such convention.
2828

29-
The "never-except-zero" option disallows `except` calls, except when used to
29+
The "never-except-zero" option (**default**) disallows `except` calls, except when used to
3030
explicitly assert that a test performs no assertions, which would otherwise
3131
be considered an error.
3232

lib/rules/require-expect.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,6 @@ module.exports = {
214214
"except-simple": ExceptSimpleStrategy,
215215
"never": NeverStrategy,
216216
"never-except-zero": NeverExceptZeroStrategy
217-
}[context.options[0]] || ExceptSimpleStrategy;
217+
}[context.options[0]] || NeverExceptZeroStrategy;
218218
}
219219
};

tests/lib/rules/require-expect.js

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -52,27 +52,27 @@ ruleTester.run("require-expect", rule, {
5252
// default, calling expect is valid
5353
{
5454
code: "test('name', function(assert) { assert.expect(0) });",
55-
options: [] // Defaults to except-simple
55+
options: [] // Defaults to never-except-zero
5656
},
5757

5858
// default, using global expect
5959
{
6060
code: "test('name', function() { expect(0) });",
61-
options: [] // Defaults to except-simple
61+
options: [] // Defaults to never-except-zero
6262
},
6363

6464
// default, using global expect, TS
6565
{
6666
// TypeScript: test callback is adding a type to `this`
6767
code: "test('name', function(this: LocalTestContext) { expect(0) });",
68-
options: [], // Defaults to except-simple
68+
options: [], // Defaults to never-except-zero
6969
parser: require.resolve("@typescript-eslint/parser")
7070
},
7171

7272
// CallExpression without parent object throws no errors
7373
{
7474
code: "test('name', function(assert) { assert.expect(0); noParentObject() });",
75-
options: [] // Defaults to except-simple
75+
options: [] // Defaults to never-except-zero
7676
},
7777
{
7878
code: "test('name', function(assert) { assert.expect(0); noParentObject() });",
@@ -91,7 +91,7 @@ ruleTester.run("require-expect", rule, {
9191
},
9292
{
9393
code: "test('name', function(assert) { assert.ok(true) });",
94-
options: [] // Defaults to except-simple
94+
options: [] // Defaults to never-except-zero
9595
},
9696

9797
// global assertion at top of test context is ok
@@ -194,11 +194,6 @@ ruleTester.run("require-expect", rule, {
194194
options: ["except-simple"],
195195
errors: [exceptSimpleErrorMessage("assert.expect")]
196196
},
197-
{
198-
code: "test('name', function(assert) { while (false) { assert.ok(true) } });",
199-
options: [], // Defaults to except-simple
200-
errors: [exceptSimpleErrorMessage("assert.expect")]
201-
},
202197

203198
// global assertion in loop block
204199
{
@@ -410,6 +405,11 @@ ruleTester.run("require-expect", rule, {
410405
code: "test('name', function(assert) { assert.expect(1); assert.ok(true); });",
411406
options: ["never-except-zero"],
412407
errors: [neverErrorMessage("assert.expect")]
408+
},
409+
{
410+
code: "test('name', function(assert) { assert.expect(1); assert.ok(true); });",
411+
options: [], // defaults to never-except-zero
412+
errors: [neverErrorMessage("assert.expect")]
413413
}
414414
]
415415

0 commit comments

Comments
 (0)