Skip to content

Commit 4a4260c

Browse files
authored
Fix false positives for store in no-redeclare (#23)
1 parent ca70b5a commit 4a4260c

File tree

8 files changed

+1997
-26
lines changed

8 files changed

+1997
-26
lines changed

explorer/src/components/ScopeExplorer.vue

Lines changed: 21 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -247,40 +247,40 @@ function processScope(options, ctx, scope) {
247247
ctx.appendIndent().appendText("{\n").indent()
248248
ctx.appendIndent().appendText(`"type": "${scope.type}",\n`)
249249
ctx.appendIndent().appendText(`"variables": [\n`).indent()
250-
for (const variable of scope.variables) {
250+
scope.variables.forEach((variable, index) => {
251251
processVariable(options, ctx, variable)
252-
if (scope.variables[scope.variables.length - 1] !== variable) {
252+
if (scope.variables.length - 1 !== index) {
253253
ctx.appendText(",")
254254
}
255255
ctx.appendText("\n")
256-
}
256+
})
257257
ctx.outdent().appendIndent().appendText(`],\n`)
258258
ctx.appendIndent().appendText(`"references": [\n`).indent()
259-
for (const reference of scope.references) {
259+
scope.references.forEach((reference, index) => {
260260
processReference(options, ctx, reference)
261-
if (scope.references[scope.references.length - 1] !== reference) {
261+
if (scope.references.length - 1 !== index) {
262262
ctx.appendText(",")
263263
}
264264
ctx.appendText("\n")
265-
}
265+
})
266266
ctx.outdent().appendIndent().appendText(`],\n`)
267267
ctx.appendIndent().appendText(`"childScopes": [\n`).indent()
268-
for (const childScope of scope.childScopes) {
268+
scope.childScopes.forEach((childScope, index) => {
269269
processScope(options, ctx, childScope)
270-
if (scope.childScopes[scope.childScopes.length - 1] !== childScope) {
270+
if (scope.childScopes.length - 1 !== index) {
271271
ctx.appendText(",")
272272
}
273273
ctx.appendText("\n")
274-
}
274+
})
275275
ctx.outdent().appendIndent().appendText(`],\n`)
276276
ctx.appendIndent().appendText(`"through": [\n`).indent()
277-
for (const through of scope.through) {
277+
scope.through.forEach((through, index) => {
278278
processReference(options, ctx, through)
279-
if (scope.through[scope.through.length - 1] !== through) {
279+
if (scope.through.length - 1 !== index) {
280280
ctx.appendText(",")
281281
}
282282
ctx.appendText("\n")
283-
}
283+
})
284284
ctx.outdent().appendIndent().appendText(`]\n`)
285285
ctx.outdent().appendIndent().appendText("}")
286286
}
@@ -294,35 +294,33 @@ function processVariable(options, ctx, variable) {
294294
ctx.appendIndent().appendText("{\n").indent()
295295
ctx.appendIndent().appendText(`"name": "${variable.name}",\n`)
296296
ctx.appendIndent().appendText(`"identifiers": [\n`).indent()
297-
for (const identifier of variable.identifiers) {
297+
variable.identifiers.forEach((identifier, index) => {
298298
ctx.appendIndent()
299299
processJsonValue(options, ctx, identifier)
300-
if (
301-
variable.identifiers[variable.identifiers.length - 1] !== identifier
302-
) {
300+
if (variable.identifiers.length - 1 !== index) {
303301
ctx.appendText(",")
304302
}
305303
ctx.appendText("\n")
306-
}
304+
})
307305
ctx.outdent().appendIndent().appendText(`],\n`)
308306
ctx.appendIndent().appendText(`"defs": [\n`).indent()
309-
for (const def of variable.defs) {
307+
variable.defs.forEach((def, index) => {
310308
ctx.appendIndent()
311309
processJsonValue(options, ctx, def)
312-
if (variable.defs[variable.defs.length - 1] !== def) {
310+
if (variable.defs.length - 1 !== index) {
313311
ctx.appendText(",")
314312
}
315313
ctx.appendText("\n")
316-
}
314+
})
317315
ctx.outdent().appendIndent().appendText(`],\n`)
318316
ctx.appendIndent().appendText(`"references": [\n`).indent()
319-
for (const reference of variable.references) {
317+
variable.references.forEach((reference, index) => {
320318
processReference(options, ctx, reference)
321-
if (variable.references[variable.references.length - 1] !== reference) {
319+
if (variable.references.length - 1 !== index) {
322320
ctx.appendText(",")
323321
}
324322
ctx.appendText("\n")
325-
}
323+
})
326324
ctx.outdent().appendIndent().appendText(`]\n`)
327325
ctx.outdent().appendIndent().appendText("}")
328326
}

src/parser/analyze-scope.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -203,9 +203,6 @@ function removeReferenceFromThrough(reference: Reference, baseScope: Scope) {
203203
if (!variable.references.includes(ref)) {
204204
variable.references.push(ref)
205205
}
206-
if (!variable.identifiers.includes(ref.identifier)) {
207-
variable.identifiers.push(ref.identifier)
208-
}
209206
return false
210207
}
211208
return true
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<script>
2+
import { imported, createStore } from './store.js';
3+
const writeOnly = createStore();
4+
$writeOnly = 99;
5+
const readOnly = createStore();
6+
$readOnly;
7+
$imported = 'some value';
8+
</script>
9+
<div on:click={() => $imported = 'clicked' }/>
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
[
2+
{
3+
"ruleId": "no-unused-expressions",
4+
"code": "$readOnly;",
5+
"line": 6,
6+
"column": 2
7+
}
8+
]
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
[
2+
{
3+
"ruleId": "no-unused-vars",
4+
"code": "writeOnly",
5+
"line": 3,
6+
"column": 8
7+
}
8+
]

0 commit comments

Comments
 (0)