Skip to content

Commit 396eef6

Browse files
committed
Fix: support rule tester
1 parent c09858d commit 396eef6

File tree

23 files changed

+105
-2181
lines changed

23 files changed

+105
-2181
lines changed

src/script/scope-analyzer.ts

+8-2
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ function isUnique(reference: eslintScope.Reference, index: number, references: e
2222
* @returns The transformed reference object.
2323
*/
2424
function transformReference(reference: eslintScope.Reference): Reference {
25-
return {
25+
const ret: Reference = {
2626
id: reference.identifier as ESLintIdentifier,
2727
mode: (
2828
reference.isReadOnly() ? "r" :
@@ -31,6 +31,9 @@ function transformReference(reference: eslintScope.Reference): Reference {
3131
),
3232
variable: null,
3333
}
34+
Object.defineProperty(ret, "variable", {enumerable: false})
35+
36+
return ret
3437
}
3538

3639
/**
@@ -39,11 +42,14 @@ function transformReference(reference: eslintScope.Reference): Reference {
3942
* @returns The transformed variable object.
4043
*/
4144
function transformVariable(variable: eslintScope.Variable): Variable {
42-
return {
45+
const ret: Variable = {
4346
id: variable.defs[0].name as ESLintIdentifier,
4447
kind: "v-for",
4548
references: [],
4649
}
50+
Object.defineProperty(ret, "references", {enumerable: false})
51+
52+
return ret
4753
}
4854

4955
/**

test/ast.js

-35
Original file line numberDiff line numberDiff line change
@@ -31,24 +31,6 @@ const PARSER_OPTIONS = {
3131
tokens: true,
3232
}
3333

34-
/**
35-
* Clone the given object as excluding the specific property.
36-
* @param {object} x The object to copy.
37-
* @param {string} exceptKey The key to except in the copy.
38-
* @returns {object} The cloned object.
39-
*/
40-
function cloneWithout(x, exceptKey) {
41-
const y = {}
42-
43-
for (const key of Object.keys(x)) {
44-
if (key !== exceptKey) {
45-
y[key] = x[key]
46-
}
47-
}
48-
49-
return y
50-
}
51-
5234
/**
5335
* Remove `parent` proeprties from the given AST.
5436
* @param {string} key The key.
@@ -67,23 +49,6 @@ function replacer(key, value) {
6749
column: e.column,
6850
}))
6951
}
70-
if (key === "variables" && Array.isArray(value)) {
71-
return value.map(v => {
72-
const cloned = Object.assign({}, v)
73-
cloned.references = cloned.references.map(r => cloneWithout(r, "variable"))
74-
return cloned
75-
})
76-
}
77-
if (key === "references" && Array.isArray(value)) {
78-
return value.map(r => {
79-
if (r.variable == null) {
80-
return r
81-
}
82-
const cloned = Object.assign({}, r)
83-
cloned.variable = cloneWithout(cloned.variable, "references")
84-
return cloned
85-
})
86-
}
8752
return value
8853
}
8954

test/fixtures/ast/directive-arguments/ast.json

+1-2
Original file line numberDiff line numberDiff line change
@@ -459,8 +459,7 @@
459459
],
460460
"name": "c"
461461
},
462-
"mode": "r",
463-
"variable": null
462+
"mode": "r"
464463
}
465464
]
466465
}

test/fixtures/ast/directive-modifiers/ast.json

+2-4
Original file line numberDiff line numberDiff line change
@@ -345,8 +345,7 @@
345345
],
346346
"name": "v"
347347
},
348-
"mode": "r",
349-
"variable": null
348+
"mode": "r"
350349
}
351350
]
352351
}
@@ -535,8 +534,7 @@
535534
],
536535
"name": "v"
537536
},
538-
"mode": "r",
539-
"variable": null
537+
"mode": "r"
540538
}
541539
]
542540
}

test/fixtures/ast/directives/ast.json

+3-6
Original file line numberDiff line numberDiff line change
@@ -459,8 +459,7 @@
459459
],
460460
"name": "b"
461461
},
462-
"mode": "r",
463-
"variable": null
462+
"mode": "r"
464463
}
465464
]
466465
}
@@ -643,8 +642,7 @@
643642
],
644643
"name": "b"
645644
},
646-
"mode": "r",
647-
"variable": null
645+
"mode": "r"
648646
}
649647
]
650648
}
@@ -827,8 +825,7 @@
827825
],
828826
"name": "b"
829827
},
830-
"mode": "r",
831-
"variable": null
828+
"mode": "r"
832829
}
833830
]
834831
}

test/fixtures/ast/expression-container-only/ast.json

+1-2
Original file line numberDiff line numberDiff line change
@@ -117,8 +117,7 @@
117117
],
118118
"name": "message"
119119
},
120-
"mode": "r",
121-
"variable": null
120+
"mode": "r"
122121
}
123122
]
124123
}

test/fixtures/ast/hole-in-array/ast.json

+3-6
Original file line numberDiff line numberDiff line change
@@ -332,8 +332,7 @@
332332
],
333333
"name": "list"
334334
},
335-
"mode": "r",
336-
"variable": null
335+
"mode": "r"
337336
}
338337
]
339338
}
@@ -380,8 +379,7 @@
380379
],
381380
"name": "a"
382381
},
383-
"kind": "v-for",
384-
"references": []
382+
"kind": "v-for"
385383
},
386384
{
387385
"id": {
@@ -404,8 +402,7 @@
404402
],
405403
"name": "b"
406404
},
407-
"kind": "v-for",
408-
"references": []
405+
"kind": "v-for"
409406
}
410407
]
411408
},

test/fixtures/ast/html-entities-surrogate-pair-and-expression/ast.json

+2-4
Original file line numberDiff line numberDiff line change
@@ -216,8 +216,7 @@
216216
],
217217
"name": "a"
218218
},
219-
"mode": "r",
220-
"variable": null
219+
"mode": "r"
221220
},
222221
{
223222
"id": {
@@ -240,8 +239,7 @@
240239
],
241240
"name": "b"
242241
},
243-
"mode": "r",
244-
"variable": null
242+
"mode": "r"
245243
}
246244
]
247245
},

test/fixtures/ast/html-entities-with-line-terminators/ast.json

+2-4
Original file line numberDiff line numberDiff line change
@@ -214,8 +214,7 @@
214214
],
215215
"name": "a"
216216
},
217-
"mode": "r",
218-
"variable": null
217+
"mode": "r"
219218
},
220219
{
221220
"id": {
@@ -238,8 +237,7 @@
238237
],
239238
"name": "b"
240239
},
241-
"mode": "r",
242-
"variable": null
240+
"mode": "r"
243241
}
244242
]
245243
}

test/fixtures/ast/html-entities/ast.json

+4-8
Original file line numberDiff line numberDiff line change
@@ -255,8 +255,7 @@
255255
],
256256
"name": "a"
257257
},
258-
"mode": "r",
259-
"variable": null
258+
"mode": "r"
260259
},
261260
{
262261
"id": {
@@ -279,8 +278,7 @@
279278
],
280279
"name": "b"
281280
},
282-
"mode": "r",
283-
"variable": null
281+
"mode": "r"
284282
}
285283
]
286284
}
@@ -386,8 +384,7 @@
386384
],
387385
"name": "a"
388386
},
389-
"mode": "r",
390-
"variable": null
387+
"mode": "r"
391388
},
392389
{
393390
"id": {
@@ -410,8 +407,7 @@
410407
],
411408
"name": "b"
412409
},
413-
"mode": "r",
414-
"variable": null
410+
"mode": "r"
415411
}
416412
]
417413
}

test/fixtures/ast/mustache/ast.json

+10-20
Original file line numberDiff line numberDiff line change
@@ -135,8 +135,7 @@
135135
],
136136
"name": "a"
137137
},
138-
"mode": "r",
139-
"variable": null
138+
"mode": "r"
140139
}
141140
]
142141
},
@@ -255,8 +254,7 @@
255254
],
256255
"name": "b"
257256
},
258-
"mode": "r",
259-
"variable": null
257+
"mode": "r"
260258
}
261259
]
262260
}
@@ -356,8 +354,7 @@
356354
],
357355
"name": "c"
358356
},
359-
"mode": "r",
360-
"variable": null
357+
"mode": "r"
361358
}
362359
]
363360
},
@@ -419,8 +416,7 @@
419416
],
420417
"name": "d"
421418
},
422-
"mode": "r",
423-
"variable": null
419+
"mode": "r"
424420
}
425421
]
426422
},
@@ -482,8 +478,7 @@
482478
],
483479
"name": "e"
484480
},
485-
"mode": "r",
486-
"variable": null
481+
"mode": "r"
487482
}
488483
]
489484
},
@@ -563,8 +558,7 @@
563558
],
564559
"name": "f"
565560
},
566-
"mode": "r",
567-
"variable": null
561+
"mode": "r"
568562
}
569563
]
570564
},
@@ -626,8 +620,7 @@
626620
],
627621
"name": "g"
628622
},
629-
"mode": "r",
630-
"variable": null
623+
"mode": "r"
631624
}
632625
]
633626
},
@@ -689,8 +682,7 @@
689682
],
690683
"name": "h"
691684
},
692-
"mode": "r",
693-
"variable": null
685+
"mode": "r"
694686
}
695687
]
696688
},
@@ -828,8 +820,7 @@
828820
],
829821
"name": "i"
830822
},
831-
"mode": "r",
832-
"variable": null
823+
"mode": "r"
833824
}
834825
]
835826
},
@@ -951,8 +942,7 @@
951942
],
952943
"name": "j"
953944
},
954-
"mode": "r",
955-
"variable": null
945+
"mode": "r"
956946
}
957947
]
958948
},

test/fixtures/ast/raw-names/ast.json

+1-2
Original file line numberDiff line numberDiff line change
@@ -257,8 +257,7 @@
257257
],
258258
"name": "def"
259259
},
260-
"mode": "r",
261-
"variable": null
260+
"mode": "r"
262261
}
263262
]
264263
}

0 commit comments

Comments
 (0)