-
-
Notifications
You must be signed in to change notification settings - Fork 334
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(lint): type-safe equality operator when comparing literals
For comparing (non empty) strings, we can use === reliably (instead of ==).
- Loading branch information
Showing
40 changed files
with
484 additions
and
414 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
const eslint = require('eslint'); | ||
const ruleComposer = require('eslint-rule-composer'); | ||
|
||
const rule = new eslint.Linter().getRules().get('eqeqeq'); | ||
|
||
module.exports = ruleComposer.filterReports( | ||
rule, | ||
(problem) => { | ||
if (problem.node.type === 'BinaryExpression' | ||
&& (problem.node.operator === '==' || problem.node.operator === '!=') | ||
&& problem.node.right.type === 'Literal' | ||
) { | ||
return problem; | ||
} | ||
|
||
return false; | ||
} | ||
); |
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
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
Oops, something went wrong.