main
Last change
on this file since d565449 was d565449, checked in by stefan toskovski <stefantoska84@…>, 4 weeks ago |
Update repo after prototype presentation
|
-
Property mode
set to
100644
|
File size:
1.2 KB
|
Line | |
---|
1 | /**
|
---|
2 | * @fileoverview Rule to flag comparisons to null without a type-checking
|
---|
3 | * operator.
|
---|
4 | * @author Ian Christian Myers
|
---|
5 | */
|
---|
6 |
|
---|
7 | "use strict";
|
---|
8 |
|
---|
9 | //------------------------------------------------------------------------------
|
---|
10 | // Rule Definition
|
---|
11 | //------------------------------------------------------------------------------
|
---|
12 |
|
---|
13 | /** @type {import('../shared/types').Rule} */
|
---|
14 | module.exports = {
|
---|
15 | meta: {
|
---|
16 | type: "suggestion",
|
---|
17 |
|
---|
18 | docs: {
|
---|
19 | description: "Disallow `null` comparisons without type-checking operators",
|
---|
20 | recommended: false,
|
---|
21 | url: "https://eslint.org/docs/latest/rules/no-eq-null"
|
---|
22 | },
|
---|
23 |
|
---|
24 | schema: [],
|
---|
25 |
|
---|
26 | messages: {
|
---|
27 | unexpected: "Use '===' to compare with null."
|
---|
28 | }
|
---|
29 | },
|
---|
30 |
|
---|
31 | create(context) {
|
---|
32 |
|
---|
33 | return {
|
---|
34 |
|
---|
35 | BinaryExpression(node) {
|
---|
36 | const badOperator = node.operator === "==" || node.operator === "!=";
|
---|
37 |
|
---|
38 | if (node.right.type === "Literal" && node.right.raw === "null" && badOperator ||
|
---|
39 | node.left.type === "Literal" && node.left.raw === "null" && badOperator) {
|
---|
40 | context.report({ node, messageId: "unexpected" });
|
---|
41 | }
|
---|
42 | }
|
---|
43 | };
|
---|
44 |
|
---|
45 | }
|
---|
46 | };
|
---|
Note:
See
TracBrowser
for help on using the repository browser.