Skip to content

Commit 1710e44

Browse files
committed
fix: do not fix when there are parent conflicts
1 parent 30418af commit 1710e44

File tree

3 files changed

+111
-8
lines changed

3 files changed

+111
-8
lines changed

Diff for: packages/eslint-plugin-svelte/src/rules/derived-has-same-inputs-outputs.ts

+17-8
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,25 @@ function findVariableForName(
1515
let hasConflict = false;
1616
let variable: Variable | null = null;
1717

18-
for (const v of scope.variables) {
19-
if (hasConflict && variable) {
20-
break;
21-
}
22-
if (v.name === expectedName) {
18+
for (const ref of scope.references) {
19+
if (ref.identifier.name === expectedName) {
2320
hasConflict = true;
24-
continue;
21+
break;
2522
}
26-
if (v.name === name) {
27-
variable = v;
23+
}
24+
25+
if (!hasConflict) {
26+
for (const v of scope.variables) {
27+
if (hasConflict && variable) {
28+
break;
29+
}
30+
if (v.name === expectedName) {
31+
hasConflict = true;
32+
continue;
33+
}
34+
if (v.name === name) {
35+
variable = v;
36+
}
2837
}
2938
}
3039

Diff for: packages/eslint-plugin-svelte/tests/fixtures/rules/derived-has-same-inputs-outputs/invalid/test01-errors.yaml

+88
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,12 @@
6666
const $a = 303;
6767
$a;
6868
});
69+
somethingWithACallback(() => {
70+
const $a = 303;
71+
derived(a, (b) => {
72+
$a;
73+
});
74+
});
6975
- message: The argument name should be '$c'.
7076
line: 6
7177
column: 13
@@ -134,6 +140,12 @@
134140
const $a = 303;
135141
$a;
136142
});
143+
somethingWithACallback(() => {
144+
const $a = 303;
145+
derived(a, (b) => {
146+
$a;
147+
});
148+
});
137149
- message: The argument name should be '$e'.
138150
line: 9
139151
column: 19
@@ -202,6 +214,12 @@
202214
const $a = 303;
203215
$a;
204216
});
217+
somethingWithACallback(() => {
218+
const $a = 303;
219+
derived(a, (b) => {
220+
$a;
221+
});
222+
});
205223
- message: The argument name should be '$f'.
206224
line: 9
207225
column: 22
@@ -270,6 +288,12 @@
270288
const $a = 303;
271289
$a;
272290
});
291+
somethingWithACallback(() => {
292+
const $a = 303;
293+
derived(a, (b) => {
294+
$a;
295+
});
296+
});
273297
- message: The argument name should be '$i'.
274298
line: 12
275299
column: 19
@@ -338,6 +362,12 @@
338362
const $a = 303;
339363
$a;
340364
});
365+
somethingWithACallback(() => {
366+
const $a = 303;
367+
derived(a, (b) => {
368+
$a;
369+
});
370+
});
341371
- message: The argument name should be '$j'.
342372
line: 12
343373
column: 22
@@ -406,6 +436,12 @@
406436
const $a = 303;
407437
$a;
408438
});
439+
somethingWithACallback(() => {
440+
const $a = 303;
441+
derived(a, (b) => {
442+
$a;
443+
});
444+
});
409445
- message: The argument name should be '$l'.
410446
line: 15
411447
column: 26
@@ -474,6 +510,12 @@
474510
const $a = 303;
475511
$a;
476512
});
513+
somethingWithACallback(() => {
514+
const $a = 303;
515+
derived(a, (b) => {
516+
$a;
517+
});
518+
});
477519
- message: The argument name should be '$o'.
478520
line: 18
479521
column: 22
@@ -542,6 +584,12 @@
542584
const $a = 303;
543585
$a;
544586
});
587+
somethingWithACallback(() => {
588+
const $a = 303;
589+
derived(a, (b) => {
590+
$a;
591+
});
592+
});
545593
- message: The argument name should be '$a'.
546594
line: 21
547595
column: 13
@@ -610,6 +658,12 @@
610658
const $a = 303;
611659
$a;
612660
});
661+
somethingWithACallback(() => {
662+
const $a = 303;
663+
derived(a, (b) => {
664+
$a;
665+
});
666+
});
613667
- message: The argument name should be '$a'.
614668
line: 28
615669
column: 13
@@ -678,6 +732,12 @@
678732
const $a = 303;
679733
$a;
680734
});
735+
somethingWithACallback(() => {
736+
const $a = 303;
737+
derived(a, (b) => {
738+
$a;
739+
});
740+
});
681741
- message: The argument name should be '$e'.
682742
line: 37
683743
column: 19
@@ -746,6 +806,12 @@
746806
const $a = 303;
747807
$a;
748808
});
809+
somethingWithACallback(() => {
810+
const $a = 303;
811+
derived(a, (b) => {
812+
$a;
813+
});
814+
});
749815
- message: The argument name should be '$f'.
750816
line: 37
751817
column: 22
@@ -814,6 +880,12 @@
814880
const $a = 303;
815881
$a;
816882
});
883+
somethingWithACallback(() => {
884+
const $a = 303;
885+
derived(a, (b) => {
886+
$a;
887+
});
888+
});
817889
- message: The argument name should be '$e'.
818890
line: 46
819891
column: 19
@@ -882,6 +954,12 @@
882954
const $a = 303;
883955
$a;
884956
});
957+
somethingWithACallback(() => {
958+
const $a = 303;
959+
derived(a, (b) => {
960+
$a;
961+
});
962+
});
885963
- message: The argument name should be '$f'.
886964
line: 46
887965
column: 22
@@ -950,7 +1028,17 @@
9501028
const $a = 303;
9511029
$a;
9521030
});
1031+
somethingWithACallback(() => {
1032+
const $a = 303;
1033+
derived(a, (b) => {
1034+
$a;
1035+
});
1036+
});
9531037
- message: The argument name should be '$a'.
9541038
line: 57
9551039
column: 13
9561040
suggestions: null
1041+
- message: The argument name should be '$a'.
1042+
line: 64
1043+
column: 14
1044+
suggestions: null

Diff for: packages/eslint-plugin-svelte/tests/fixtures/rules/derived-has-same-inputs-outputs/invalid/test01-input.js

+6
Original file line numberDiff line numberDiff line change
@@ -59,3 +59,9 @@ derived(a, (b) => {
5959
const $a = 303;
6060
$a;
6161
});
62+
somethingWithACallback(() => {
63+
const $a = 303;
64+
derived(a, (b) => {
65+
$a;
66+
});
67+
});

0 commit comments

Comments
 (0)