eslint-plugin-julia 0.0.0-stage → 0.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +159 -0
- package/LICENSE +21 -0
- package/README.md +213 -2
- package/data/base-core-exports.json +5 -0
- package/data/public-only.json +35 -0
- package/data/stdlib-exports.json +180 -0
- package/package.json +76 -4
- package/src/index.js +226 -0
- package/src/language.js +46 -0
- package/src/macro-signatures.js +277 -0
- package/src/module-resolution.js +1187 -0
- package/src/orphans.js +631 -0
- package/src/parser/flags.js +25 -0
- package/src/parser/green-tree.js +41 -0
- package/src/parser/positions.js +29 -0
- package/src/parser/syntax-tree.js +91 -0
- package/src/parser/wasm-host.js +92 -0
- package/src/resolver/index.js +232 -0
- package/src/resolver/pkg-child.mjs +165 -0
- package/src/resolver/toml.js +63 -0
- package/src/resolver/warm.mjs +26 -0
- package/src/rules/common.js +52 -0
- package/src/rules/correctness-common.js +90 -0
- package/src/rules/growth-common.js +93 -0
- package/src/rules/idiom-common.js +116 -0
- package/src/rules/no-collapsible-if.js +38 -0
- package/src/rules/no-collect-before-range-iteration.js +24 -0
- package/src/rules/no-compare-negative-zero.js +50 -0
- package/src/rules/no-concat-growth-in-loop.js +18 -0
- package/src/rules/no-cond-assign.js +126 -0
- package/src/rules/no-const-reassign.js +61 -0
- package/src/rules/no-constant-condition.js +59 -0
- package/src/rules/no-debugger.js +96 -0
- package/src/rules/no-discarded-copy-result.js +50 -0
- package/src/rules/no-dupe-args.js +25 -0
- package/src/rules/no-dupe-elseif.js +57 -0
- package/src/rules/no-duplicate-dict-keys.js +95 -0
- package/src/rules/no-duplicate-keyword-arguments.js +40 -0
- package/src/rules/no-duplicate-logical-operands.js +85 -0
- package/src/rules/no-duplicate-method-signatures.js +90 -0
- package/src/rules/no-duplicate-struct-fields.js +38 -0
- package/src/rules/no-empty-block.js +49 -0
- package/src/rules/no-empty-catch.js +32 -0
- package/src/rules/no-empty-literal-range.js +26 -0
- package/src/rules/no-env-mutation.js +62 -0
- package/src/rules/no-eval-local-symbol.js +85 -0
- package/src/rules/no-fill-with-mutable.js +43 -0
- package/src/rules/no-full-slice-in-consumer.js +41 -0
- package/src/rules/no-identical-branches.js +44 -0
- package/src/rules/no-import-assign.js +64 -0
- package/src/rules/no-impossible-length-comparison.js +49 -0
- package/src/rules/no-invalid-foreign-call-signature.js +58 -0
- package/src/rules/no-isdefined-local-call.js +23 -0
- package/src/rules/no-loss-of-float-integer-precision.js +41 -0
- package/src/rules/no-nothing-return-conversion.js +127 -0
- package/src/rules/no-obvious-type-piracy.js +112 -0
- package/src/rules/no-orphan-file.js +39 -0
- package/src/rules/no-overwritten-literal-index.js +80 -0
- package/src/rules/no-reassigned-capture.js +107 -0
- package/src/rules/no-redundant-type-assertion.js +36 -0
- package/src/rules/no-redundant-union-members.js +42 -0
- package/src/rules/no-restricted-calls.js +74 -0
- package/src/rules/no-restricted-imports.js +105 -0
- package/src/rules/no-restricted-macros.js +61 -0
- package/src/rules/no-self-assign.js +65 -0
- package/src/rules/no-self-identity-comparison.js +37 -0
- package/src/rules/no-shadowed-loop-var.js +83 -0
- package/src/rules/no-show-macro.js +90 -0
- package/src/rules/no-single-iteration-loop.js +50 -0
- package/src/rules/no-string-growth-in-loop.js +18 -0
- package/src/rules/no-throw-literal.js +33 -0
- package/src/rules/no-unbound-type-parameters.js +91 -0
- package/src/rules/no-undef.js +284 -0
- package/src/rules/no-undefined-exports.js +60 -0
- package/src/rules/no-uninitialized-ref-read.js +38 -0
- package/src/rules/no-unreachable.js +82 -0
- package/src/rules/no-unsafe-finally.js +35 -0
- package/src/rules/no-unsafe-negation.js +77 -0
- package/src/rules/no-unused-expressions.js +137 -0
- package/src/rules/no-unused-type-parameters.js +55 -0
- package/src/rules/no-unused-vars.js +123 -0
- package/src/rules/no-use-before-define.js +139 -0
- package/src/rules/no-useless-assignment.js +75 -0
- package/src/rules/no-useless-catch.js +28 -0
- package/src/rules/parse-errors.js +19 -0
- package/src/rules/performance-common.js +119 -0
- package/src/rules/prefer-any.js +75 -0
- package/src/rules/prefer-const-global.js +103 -0
- package/src/rules/prefer-count-over-findall-length.js +46 -0
- package/src/rules/prefer-eachindex.js +120 -0
- package/src/rules/prefer-extreme-over-sort.js +73 -0
- package/src/rules/prefer-generator-sum.js +34 -0
- package/src/rules/prefer-identity-nothing.js +43 -0
- package/src/rules/prefer-in.js +67 -0
- package/src/rules/prefer-isa.js +70 -0
- package/src/rules/prefer-isempty.js +57 -0
- package/src/rules/prefer-ismissing.js +42 -0
- package/src/rules/prefer-parenthesized-interpolation.js +160 -0
- package/src/rules/prefer-size-dimension.js +19 -0
- package/src/rules/prefer-sized-push-buffer.js +81 -0
- package/src/rules/prefer-typed-empty-array.js +90 -0
- package/src/rules/require-typed-global.js +60 -0
- package/src/rules/restricted-common.js +211 -0
- package/src/rules/semantic-common.js +105 -0
- package/src/rules/use-isnan.js +28 -0
- package/src/scope.js +1338 -0
- package/src/source-code.js +100 -0
- package/types/ast.d.ts +49 -0
- package/types/index.d.ts +65 -0
- package/types/scope.d.ts +71 -0
- package/wasm/LICENSES/Julia.md +26 -0
- package/wasm/LICENSES/JuliaSyntax-MIT.md +46 -0
- package/wasm/LICENSES/WasmCodegen-MIT.txt +21 -0
- package/wasm/manifest.json +44 -0
- package/wasm/parser.wasm +0 -0
|
@@ -0,0 +1,211 @@
|
|
|
1
|
+
// Shared written-invocation matching. No macro expansion or value-alias inference.
|
|
2
|
+
import { readFileSync } from 'node:fs';
|
|
3
|
+
import { identifierName } from '../scope.js';
|
|
4
|
+
import { isInfixCall, isQuoted } from '../parser/flags.js';
|
|
5
|
+
import { strip, text } from './idiom-common.js';
|
|
6
|
+
export { strip, text };
|
|
7
|
+
const inventory = JSON.parse(
|
|
8
|
+
readFileSync(new URL('../../data/base-core-exports.json', import.meta.url)),
|
|
9
|
+
);
|
|
10
|
+
const core = new Set([...inventory.Core, 'ccall']);
|
|
11
|
+
const base = new Set([...inventory.Base, 'include', 'eval']);
|
|
12
|
+
const builtin = (name) =>
|
|
13
|
+
core.has(name) ? `Core.${name}` : base.has(name) ? `Base.${name}` : null;
|
|
14
|
+
|
|
15
|
+
export function glob(pattern, value) {
|
|
16
|
+
const escaped = [...pattern]
|
|
17
|
+
.map((c) =>
|
|
18
|
+
c === '*' ? '[^.]*' : c === '?' ? '[^.]' : c.replace(/[\\^$.*+?()[\]{}|]/gu, '\\$&'),
|
|
19
|
+
)
|
|
20
|
+
.join('');
|
|
21
|
+
return new RegExp(`^${escaped}$`, 'u').test(value);
|
|
22
|
+
}
|
|
23
|
+
export function canonical(path) {
|
|
24
|
+
if (path === 'Threads' || path.startsWith('Threads.')) path = `Base.${path}`;
|
|
25
|
+
// Base reexports Core bindings; both spellings identify the Core binding.
|
|
26
|
+
if (/^Base\.[^.]+$/u.test(path) && core.has(path.slice(5))) return `Core.${path.slice(5)}`;
|
|
27
|
+
return path;
|
|
28
|
+
}
|
|
29
|
+
function headName(node) {
|
|
30
|
+
node = strip(node);
|
|
31
|
+
if (['curly', 'TOMBSTONE'].includes(node?.kind)) return headName(node.children[0]);
|
|
32
|
+
// Property syntax can quote an operator, e.g. Base.:+.
|
|
33
|
+
if (node?.kind === 'quote' && node.children.length === 1) return identifierName(node.children[0]);
|
|
34
|
+
return identifierName(node);
|
|
35
|
+
}
|
|
36
|
+
export function writtenName(node) {
|
|
37
|
+
node = strip(node);
|
|
38
|
+
if (['curly', 'TOMBSTONE'].includes(node?.kind)) return writtenName(node.children[0]);
|
|
39
|
+
if (node?.kind === '.' && node.children.length === 2) {
|
|
40
|
+
const left = writtenName(node.children[0]),
|
|
41
|
+
right = headName(node.children[1]);
|
|
42
|
+
return left && right ? `${left}.${right}` : null;
|
|
43
|
+
}
|
|
44
|
+
return headName(node);
|
|
45
|
+
}
|
|
46
|
+
export function invocation(node) {
|
|
47
|
+
const i = isInfixCall(node) ? 1 : 0;
|
|
48
|
+
return { head: node.children[i], args: node.children.filter((_, j) => i !== j) };
|
|
49
|
+
}
|
|
50
|
+
export function visible(node, source, includeMacroPayloads = false) {
|
|
51
|
+
return (
|
|
52
|
+
!isQuoted(node, source) &&
|
|
53
|
+
(includeMacroPayloads || !source.getAncestors(node).some((n) => n.kind === 'macrocall'))
|
|
54
|
+
);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
// Explicit imports establish provenance even when a package is unavailable. Wildcard
|
|
58
|
+
// imports need an export fact. Known modules supply a small documented fallback for
|
|
59
|
+
// debugger macros; arbitrary unknown wildcard imports never establish an origin.
|
|
60
|
+
export function originResolver(m, knownModules = {}) {
|
|
61
|
+
const modelsFor = (scope) => m.moduleResolution?.scopes.get(scope?.module) ?? [];
|
|
62
|
+
function importedPath(d) {
|
|
63
|
+
const original = d.imported.split(/\s+as\s+/u)[0].replace(/\s/gu, '');
|
|
64
|
+
return canonical(d.named ? `${d.moduleName}.${original}` : d.moduleName);
|
|
65
|
+
}
|
|
66
|
+
function fromModels(name, scope) {
|
|
67
|
+
const origins = new Set();
|
|
68
|
+
for (const model of modelsFor(scope))
|
|
69
|
+
for (const imp of model.imports) {
|
|
70
|
+
const declarations = m.imports.filter(
|
|
71
|
+
(d) => d.scope === scope.module && !d.named && d.moduleName === imp.path,
|
|
72
|
+
);
|
|
73
|
+
if (
|
|
74
|
+
imp.wildcard &&
|
|
75
|
+
declarations.length &&
|
|
76
|
+
declarations.every((d) => d.importKind === 'import')
|
|
77
|
+
)
|
|
78
|
+
continue;
|
|
79
|
+
if (
|
|
80
|
+
imp.wildcard &&
|
|
81
|
+
(imp.resolvedExports?.has(name) ||
|
|
82
|
+
(Object.hasOwn(knownModules, imp.path) && knownModules[imp.path].includes(name)))
|
|
83
|
+
)
|
|
84
|
+
origins.add(canonical(`${imp.path}.${name}`));
|
|
85
|
+
else if (!imp.wildcard)
|
|
86
|
+
for (let i = 0; i < imp.names.length; i++)
|
|
87
|
+
if (imp.names[i] === name) origins.add(canonical(`${imp.path}.${imp.sourceNames[i]}`));
|
|
88
|
+
}
|
|
89
|
+
return origins.size === 1 ? [...origins][0] : null;
|
|
90
|
+
}
|
|
91
|
+
function bindingOrigin(binding, name, scope) {
|
|
92
|
+
if (!binding) return fromModels(name, scope);
|
|
93
|
+
if (binding.kind === 'builtin') {
|
|
94
|
+
// An unavailable wildcard package may export a competing name.
|
|
95
|
+
if (scope?.module.bareUsing.some((p) => !['Base', 'Core'].includes(p))) return null;
|
|
96
|
+
return builtin(name);
|
|
97
|
+
}
|
|
98
|
+
if (
|
|
99
|
+
binding.kind !== 'import' ||
|
|
100
|
+
binding.writes.length ||
|
|
101
|
+
binding.definitions.some((d) => d.kind !== 'import')
|
|
102
|
+
)
|
|
103
|
+
return null;
|
|
104
|
+
const origins = new Set(
|
|
105
|
+
binding.definitions.filter((d) => d.kind === 'import').map(importedPath),
|
|
106
|
+
);
|
|
107
|
+
return origins.size === 1 ? [...origins][0] : origins.size ? null : fromModels(name, scope);
|
|
108
|
+
}
|
|
109
|
+
return (head, node) => {
|
|
110
|
+
const spelling = writtenName(head);
|
|
111
|
+
if (!spelling) return null;
|
|
112
|
+
const scope = m.scopeFor(node) ?? m.globalScope;
|
|
113
|
+
if (!spelling.includes('.')) {
|
|
114
|
+
let bare = strip(head);
|
|
115
|
+
while (['curly', 'TOMBSTONE'].includes(bare?.kind)) bare = strip(bare.children[0]);
|
|
116
|
+
return bindingOrigin(m.resolve(bare) ?? m.lookup(spelling, scope), spelling, scope);
|
|
117
|
+
}
|
|
118
|
+
const [root, ...parts] = spelling.split('.');
|
|
119
|
+
const b = m.lookup(root, scope);
|
|
120
|
+
let namespace;
|
|
121
|
+
if (b?.kind === 'builtin') {
|
|
122
|
+
if (['Base', 'Core', 'Threads'].includes(root)) namespace = canonical(root);
|
|
123
|
+
} else {
|
|
124
|
+
const candidate = bindingOrigin(b, root, scope);
|
|
125
|
+
const knownNamespace = [
|
|
126
|
+
'Base',
|
|
127
|
+
'Core',
|
|
128
|
+
'Base.Threads',
|
|
129
|
+
...Object.keys(knownModules),
|
|
130
|
+
].includes(candidate);
|
|
131
|
+
// A named import can be a function or an object, not a module. Only
|
|
132
|
+
// recognized namespaces and explicit module imports establish a receiver.
|
|
133
|
+
if (knownNamespace || b?.definitions.some((d) => d.kind === 'import' && !d.named))
|
|
134
|
+
namespace = candidate;
|
|
135
|
+
}
|
|
136
|
+
// Qualified debugger names are accepted without loading those packages. A
|
|
137
|
+
// written local definition of that root still takes precedence.
|
|
138
|
+
if (!b && Object.hasOwn(knownModules, root)) namespace = root;
|
|
139
|
+
return namespace ? canonical(`${namespace}.${parts.join('.')}`) : null;
|
|
140
|
+
};
|
|
141
|
+
}
|
|
142
|
+
export function matches(entry, spelling, origin) {
|
|
143
|
+
const resolved = (entry.binding ?? 'resolved') === 'resolved';
|
|
144
|
+
const value = resolved ? origin : spelling;
|
|
145
|
+
if (!value) return false;
|
|
146
|
+
let wanted = entry.name ?? entry.pattern;
|
|
147
|
+
if (resolved)
|
|
148
|
+
wanted = wanted.includes('.')
|
|
149
|
+
? canonical(wanted)
|
|
150
|
+
: entry.name
|
|
151
|
+
? (builtin(wanted) ?? wanted)
|
|
152
|
+
: wanted;
|
|
153
|
+
const candidate = wanted.includes('.') ? value : value.split('.').at(-1);
|
|
154
|
+
return entry.name ? candidate === wanted : glob(wanted, candidate);
|
|
155
|
+
}
|
|
156
|
+
export function withinFunction(node, patterns, m) {
|
|
157
|
+
return (
|
|
158
|
+
patterns?.length &&
|
|
159
|
+
m.functions.some((fn) => {
|
|
160
|
+
if (
|
|
161
|
+
!['function', 'macro'].includes(fn.node.kind) ||
|
|
162
|
+
!fn.call ||
|
|
163
|
+
fn.node === node ||
|
|
164
|
+
node.range[0] < fn.node.range[0] ||
|
|
165
|
+
node.range[1] > fn.node.range[1]
|
|
166
|
+
)
|
|
167
|
+
return false;
|
|
168
|
+
const name = writtenName(invocation(fn.call).head)?.split('.').at(-1);
|
|
169
|
+
return name && patterns.some((p) => glob(p, name));
|
|
170
|
+
})
|
|
171
|
+
);
|
|
172
|
+
}
|
|
173
|
+
export function constInitializer(node, source) {
|
|
174
|
+
for (let child = node, p = source.getParent(child); p; child = p, p = source.getParent(p)) {
|
|
175
|
+
if (['function', 'macro', '->', 'do'].includes(p.kind)) return false;
|
|
176
|
+
if (p.kind === '=' && p.children[1] === child && source.getParent(p)?.kind === 'const')
|
|
177
|
+
return true;
|
|
178
|
+
}
|
|
179
|
+
return false;
|
|
180
|
+
}
|
|
181
|
+
const nonempty = { type: 'string', minLength: 1 };
|
|
182
|
+
export const matchProperties = {
|
|
183
|
+
name: nonempty,
|
|
184
|
+
pattern: nonempty,
|
|
185
|
+
binding: { enum: ['resolved', 'spelling'] },
|
|
186
|
+
message: nonempty,
|
|
187
|
+
};
|
|
188
|
+
export const matchChoice = [
|
|
189
|
+
{ required: ['name'], not: { required: ['pattern'] } },
|
|
190
|
+
{ required: ['pattern'], not: { required: ['name'] } },
|
|
191
|
+
];
|
|
192
|
+
export function optionsSchema(properties) {
|
|
193
|
+
return [
|
|
194
|
+
{
|
|
195
|
+
type: 'object',
|
|
196
|
+
additionalProperties: false,
|
|
197
|
+
properties: {
|
|
198
|
+
entries: {
|
|
199
|
+
type: 'array',
|
|
200
|
+
items: {
|
|
201
|
+
type: 'object',
|
|
202
|
+
additionalProperties: false,
|
|
203
|
+
properties: { ...matchProperties, ...properties },
|
|
204
|
+
oneOf: matchChoice,
|
|
205
|
+
},
|
|
206
|
+
},
|
|
207
|
+
includeMacroPayloads: { type: 'boolean' },
|
|
208
|
+
},
|
|
209
|
+
},
|
|
210
|
+
];
|
|
211
|
+
}
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import { defineRule } from './common.js';
|
|
2
|
+
import { getScopeManager } from '../scope.js';
|
|
3
|
+
export * from './idiom-common.js';
|
|
4
|
+
|
|
5
|
+
// Pass the physical filename through so include/package shadowing is respected.
|
|
6
|
+
export function check(description, create, { properties = {}, fixable, suggestions = false } = {}) {
|
|
7
|
+
return defineRule({
|
|
8
|
+
meta: {
|
|
9
|
+
type: 'problem',
|
|
10
|
+
docs: { description },
|
|
11
|
+
schema: [{ type: 'object', properties, additionalProperties: false }],
|
|
12
|
+
...(fixable && { fixable }),
|
|
13
|
+
...(suggestions && { hasSuggestions: true }),
|
|
14
|
+
messages: { diagnostic: '{{message}}', replace: '{{message}}' },
|
|
15
|
+
},
|
|
16
|
+
create(context) {
|
|
17
|
+
return create(
|
|
18
|
+
context,
|
|
19
|
+
getScopeManager(context.sourceCode, context),
|
|
20
|
+
context.sourceCode,
|
|
21
|
+
context.options[0] ?? {},
|
|
22
|
+
);
|
|
23
|
+
},
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
// Deliberately small catalogue: membership proves a named builtin type, not
|
|
28
|
+
// arbitrary type-valued exports or equivalence between aliases such as Int/Int64.
|
|
29
|
+
export const builtinTypes = new Set([
|
|
30
|
+
'Any',
|
|
31
|
+
'Union',
|
|
32
|
+
'UnionAll',
|
|
33
|
+
'DataType',
|
|
34
|
+
'Type',
|
|
35
|
+
'Nothing',
|
|
36
|
+
'Missing',
|
|
37
|
+
'Bool',
|
|
38
|
+
'Char',
|
|
39
|
+
'Symbol',
|
|
40
|
+
'String',
|
|
41
|
+
'AbstractString',
|
|
42
|
+
'Number',
|
|
43
|
+
'Real',
|
|
44
|
+
'Integer',
|
|
45
|
+
'Signed',
|
|
46
|
+
'Unsigned',
|
|
47
|
+
'AbstractFloat',
|
|
48
|
+
'Float16',
|
|
49
|
+
'Float32',
|
|
50
|
+
'Float64',
|
|
51
|
+
'Int',
|
|
52
|
+
'Int8',
|
|
53
|
+
'Int16',
|
|
54
|
+
'Int32',
|
|
55
|
+
'Int64',
|
|
56
|
+
'Int128',
|
|
57
|
+
'UInt',
|
|
58
|
+
'UInt8',
|
|
59
|
+
'UInt16',
|
|
60
|
+
'UInt32',
|
|
61
|
+
'UInt64',
|
|
62
|
+
'UInt128',
|
|
63
|
+
'BigInt',
|
|
64
|
+
'BigFloat',
|
|
65
|
+
'Function',
|
|
66
|
+
'IO',
|
|
67
|
+
'Tuple',
|
|
68
|
+
'NamedTuple',
|
|
69
|
+
'AbstractArray',
|
|
70
|
+
'Array',
|
|
71
|
+
'Vector',
|
|
72
|
+
'Matrix',
|
|
73
|
+
'AbstractVector',
|
|
74
|
+
'AbstractMatrix',
|
|
75
|
+
'Dict',
|
|
76
|
+
'Set',
|
|
77
|
+
'Pair',
|
|
78
|
+
'Exception',
|
|
79
|
+
'Module',
|
|
80
|
+
'Task',
|
|
81
|
+
]);
|
|
82
|
+
export function stableType(node, m) {
|
|
83
|
+
while (node?.kind === 'parens' && node.children.length === 1) node = node.children[0];
|
|
84
|
+
for (const name of builtinTypes) if (m.isUnshadowedBuiltin(node, name)) return `builtin:${name}`;
|
|
85
|
+
const b = m.resolve(node);
|
|
86
|
+
return b?.kind === 'type-parameter' && !b.writes.length ? b : null;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
// A different function frame can observe writes between the two reads. Opaque
|
|
90
|
+
// macro payloads may introduce tasks/captures that syntax cannot reconstruct.
|
|
91
|
+
export function hasCaptureOrOpaqueUse(binding, source) {
|
|
92
|
+
const frame = (scope) => {
|
|
93
|
+
for (let s = scope; s; s = s.parent) if (['function', 'module'].includes(s.kind)) return s;
|
|
94
|
+
};
|
|
95
|
+
const owner = frame(binding.scope);
|
|
96
|
+
return [...binding.references, ...binding.definitions].some(
|
|
97
|
+
(r) =>
|
|
98
|
+
r.opaque ||
|
|
99
|
+
frame(r.scope) !== owner ||
|
|
100
|
+
(() => {
|
|
101
|
+
for (let p = r.node; p; p = source.getParent(p)) if (p.kind === 'macrocall') return true;
|
|
102
|
+
return false;
|
|
103
|
+
})(),
|
|
104
|
+
);
|
|
105
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { rule, ordinary, binary, strip, text, suggest, baseAvailable } from './idiom-common.js';
|
|
2
|
+
export default rule(
|
|
3
|
+
'Suggest isnan for comparisons with known NaN constants.',
|
|
4
|
+
{
|
|
5
|
+
identity: { type: 'boolean' },
|
|
6
|
+
},
|
|
7
|
+
(context, m, source, options) => ({
|
|
8
|
+
call(node) {
|
|
9
|
+
const parts = binary(node);
|
|
10
|
+
if (!parts || !ordinary(node, source)) return;
|
|
11
|
+
if (!m.isUnshadowedBuiltin(parts[1], parts[1].value)) return;
|
|
12
|
+
const [a, op, b] = parts;
|
|
13
|
+
if (!['==', '!=', ...(options.identity === false ? [] : ['===', '!=='])].includes(op.value))
|
|
14
|
+
return;
|
|
15
|
+
const nan = (n) =>
|
|
16
|
+
['NaN', 'NaN16', 'NaN32'].some((name) => m.isUnshadowedBuiltin(strip(n), name));
|
|
17
|
+
const operand = nan(a) ? b : nan(b) ? a : null;
|
|
18
|
+
if (!operand) return;
|
|
19
|
+
const replacement = `${['!=', '!=='].includes(op.value) ? '!' : ''}Base.isnan(${text(source, operand)})`;
|
|
20
|
+
suggest(
|
|
21
|
+
context,
|
|
22
|
+
node,
|
|
23
|
+
'Use isnan to test for NaN; equality and identity have different NaN semantics.',
|
|
24
|
+
baseAvailable(m, node) ? replacement : null,
|
|
25
|
+
);
|
|
26
|
+
},
|
|
27
|
+
}),
|
|
28
|
+
);
|