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
Chore: avoid loose equality assertions #9415
Conversation
This updates the `no-restricted-syntax` configuration to disallow `assert.equal` and `assert.notEqual` in favor of `assert.strictEqual` and `assert.notStrictEqual`. It also fixes a few places where the tests were relying on a loose equality check (e.g. comparing a single-element array to a string).
LGTM |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Left a few comments/suggestions, nothing that should be considered a blocker. Thanks for doing this!
tests/lib/config.js
Outdated
assert.equal(actual.length, 1); | ||
assert.equal(actual, expected); | ||
assert.strictEqual(actual.length, 1); | ||
assert.deepEqual(actual, [expected]); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Given that there's a length assertion above this line, we could assert for strict equality as follows:
assert.strictEqual(actual[0], expected);
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually, it looks like assert.deepStrictEqual
is supported on all necessary Node versions, so maybe we should switch to using that as well.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd be in favor of that for sure. Maybe we could add assert.deepEqual
to no-restricted-properties as well?
tests/lib/ignored-paths.js
Outdated
@@ -127,14 +127,14 @@ describe("IgnoredPaths", () => { | |||
const ignorePatterns = getIgnorePatterns(ignoredPaths); | |||
|
|||
assert.isNotNull(ignoredPaths.baseDir); | |||
assert.equal(getIgnoreFiles(ignoredPaths), expectedIgnoreFile); | |||
assert.deepEqual(getIgnoreFiles(ignoredPaths), [expectedIgnoreFile]); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Similarly, by asserting on length here, we could also do a strict comparison of the first element.
tests/lib/options.js
Outdated
@@ -92,7 +92,7 @@ describe("options", () => { | |||
const currentOptions = options.parse("--rulesdir /morerules"); | |||
|
|||
assert.isArray(currentOptions.rulesdir); | |||
assert.equal(currentOptions.rulesdir, "/morerules"); | |||
assert.deepEqual(currentOptions.rulesdir, ["/morerules"]); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could achieve strict comparison by comparing length and first element.
tests/performance/jshint.js
Outdated
@@ -9596,10 +9596,10 @@ assert.ok = ok; | |||
|
|||
// 5. The equality assertion tests shallow, coercive equality with | |||
// ==. | |||
// assert.equal(actual, expected, message_opt); | |||
// assert.strictEqual(actual, expected, message_opt); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this be changed?
tests/performance/jshint.js
Outdated
|
||
assert.equal = function equal(actual, expected, message) { | ||
if (actual != expected) fail(actual, expected, message, '==', assert.equal); | ||
assert.strictEqual = function equal(actual, expected, message) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would it make more sense to reconfigure no-restricted-properties for this file to allow the local assert.equal? I'm assuming this is third party code, maybe I'm misunderstanding.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oops, this was an accidental change resulting from a global find/replace.
LGTM |
Thanks for contributing to ESLint! |
What is the purpose of this pull request? (put an "X" next to item)
[ ] Documentation update
[ ] Bug fix (template)
[ ] New rule (template)
[ ] Changes an existing rule (template)
[ ] Add autofixing to a rule
[ ] Add a CLI option
[ ] Add something to the core
[x] Other, please explain:
What changes did you make? (Give an overview)
This updates the
no-restricted-syntax
configuration to disallowassert.equal
andassert.notEqual
in favor ofassert.strictEqual
andassert.notStrictEqual
. It also fixes a few places where the tests were relying on a loose equality check (e.g. comparing a single-element array to a string).A few loose equality assertions in
RuleTester
were kept for backwards compatibility.Is there anything you'd like reviewers to focus on?
Nothing in particular