WARNING: THIS SITE IS A MIRROR OF GITHUB.COM / IT CANNOT LOGIN OR REGISTER ACCOUNTS / THE CONTENTS ARE PROVIDED AS-IS / THIS SITE ASSUMES NO RESPONSIBILITY FOR ANY DISPLAYED CONTENT OR LINKS / IF YOU FOUND SOMETHING MAY NOT GOOD FOR EVERYONE, CONTACT ADMIN AT ilovescratch@foxmail.com
Skip to content

Commit 93e2771

Browse files
committed
chore: cleanup and update tests
1 parent f46ad20 commit 93e2771

File tree

2 files changed

+60
-41
lines changed

2 files changed

+60
-41
lines changed

lib/rules/no-undef-directives.js

Lines changed: 12 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -36,24 +36,12 @@ function getRegisteredDirectives(componentObject) {
3636
}
3737

3838
return directivesNode.value.properties
39-
.filter(
40-
/**
41-
* @param {Property | SpreadElement} node
42-
* @returns {node is Property}
43-
*/
44-
(node) => node.type === 'Property'
45-
)
39+
.filter((node) => node.type === 'Property')
4640
.map((node) => {
4741
const name = utils.getStaticPropertyName(node)
4842
return name ? { node, name } : null
4943
})
50-
.filter(
51-
/**
52-
* @param {{node: Property, name: string} | null} res
53-
* @returns {res is {node: Property, name: string}}
54-
*/
55-
(res) => res !== null
56-
)
44+
.filter((res) => !!res)
5745
}
5846

5947
class DefinedInSetupDirectives {
@@ -80,10 +68,7 @@ class DefinedInSetupDirectives {
8068
isDefinedDirective(rawName) {
8169
const camelName = camelize(rawName)
8270
const variableName = `v${casing.capitalize(camelName)}`
83-
if (this.names.has(variableName)) {
84-
return true
85-
}
86-
return false
71+
return this.names.has(variableName)
8772
}
8873
}
8974

@@ -222,13 +207,11 @@ module.exports = {
222207
})
223208

224209
verifyName = (rawName, reportNode) => {
225-
if (!isVerifyTargetDirective(rawName)) {
226-
return
227-
}
228-
if (definedInSetupDirectives.isDefinedDirective(rawName)) {
229-
return
230-
}
231-
if (definedInOptionDirectives.isDefinedDirective(rawName)) {
210+
if (
211+
!isVerifyTargetDirective(rawName) ||
212+
definedInSetupDirectives.isDefinedDirective(rawName) ||
213+
definedInOptionDirectives.isDefinedDirective(rawName)
214+
) {
232215
return
233216
}
234217

@@ -251,10 +234,10 @@ module.exports = {
251234
})
252235

253236
verifyName = (rawName, reportNode) => {
254-
if (!isVerifyTargetDirective(rawName)) {
255-
return
256-
}
257-
if (definedInOptionDirectives.isDefinedDirective(rawName)) {
237+
if (
238+
!isVerifyTargetDirective(rawName) ||
239+
definedInOptionDirectives.isDefinedDirective(rawName)
240+
) {
258241
return
259242
}
260243

tests/lib/rules/no-undef-directives.js

Lines changed: 48 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,10 @@ tester.run('no-undef-directives', rule, {
241241
errors: [
242242
{
243243
message: "The 'v-focus' directive has been used, but not defined.",
244-
line: 3
244+
line: 3,
245+
column: 14,
246+
endLine: 3,
247+
endColumn: 21
245248
}
246249
]
247250
},
@@ -258,7 +261,10 @@ tester.run('no-undef-directives', rule, {
258261
errors: [
259262
{
260263
message: "The 'v-focus' directive has been used, but not defined.",
261-
line: 6
264+
line: 6,
265+
column: 14,
266+
endLine: 6,
267+
endColumn: 21
262268
}
263269
]
264270
},
@@ -275,7 +281,10 @@ tester.run('no-undef-directives', rule, {
275281
errors: [
276282
{
277283
message: "The 'v-foo' directive has been used, but not defined.",
278-
line: 6
284+
line: 6,
285+
column: 14,
286+
endLine: 6,
287+
endColumn: 19
279288
}
280289
]
281290
},
@@ -292,7 +301,10 @@ tester.run('no-undef-directives', rule, {
292301
errors: [
293302
{
294303
message: "The 'v-focus' directive has been used, but not defined.",
295-
line: 6
304+
line: 6,
305+
column: 14,
306+
endLine: 6,
307+
endColumn: 21
296308
}
297309
]
298310
},
@@ -310,7 +322,10 @@ tester.run('no-undef-directives', rule, {
310322
{
311323
message:
312324
"The 'v-clickoutside' directive has been used, but not defined.",
313-
line: 6
325+
line: 6,
326+
column: 14,
327+
endLine: 6,
328+
endColumn: 28
314329
}
315330
]
316331
},
@@ -328,7 +343,10 @@ tester.run('no-undef-directives', rule, {
328343
{
329344
message:
330345
"The 'v-click-outside' directive has been used, but not defined.",
331-
line: 6
346+
line: 6,
347+
column: 14,
348+
endLine: 6,
349+
endColumn: 29
332350
}
333351
]
334352
},
@@ -342,7 +360,10 @@ tester.run('no-undef-directives', rule, {
342360
errors: [
343361
{
344362
message: "The 'v-foo' directive has been used, but not defined.",
345-
line: 3
363+
line: 3,
364+
column: 14,
365+
endLine: 3,
366+
endColumn: 25
346367
}
347368
]
348369
},
@@ -356,7 +377,10 @@ tester.run('no-undef-directives', rule, {
356377
errors: [
357378
{
358379
message: "The 'v-foo' directive has been used, but not defined.",
359-
line: 3
380+
line: 3,
381+
column: 14,
382+
endLine: 3,
383+
endColumn: 23
360384
}
361385
]
362386
},
@@ -370,7 +394,10 @@ tester.run('no-undef-directives', rule, {
370394
errors: [
371395
{
372396
message: "The 'v-foo' directive has been used, but not defined.",
373-
line: 3
397+
line: 3,
398+
column: 14,
399+
endLine: 3,
400+
endColumn: 27
374401
}
375402
]
376403
},
@@ -391,7 +418,10 @@ tester.run('no-undef-directives', rule, {
391418
errors: [
392419
{
393420
message: "The 'v-Focus' directive has been used, but not defined.",
394-
line: 10
421+
line: 10,
422+
column: 14,
423+
endLine: 10,
424+
endColumn: 21
395425
}
396426
]
397427
},
@@ -412,7 +442,10 @@ tester.run('no-undef-directives', rule, {
412442
errors: [
413443
{
414444
message: "The 'v-foo-bar' directive has been used, but not defined.",
415-
line: 10
445+
line: 10,
446+
column: 14,
447+
endLine: 10,
448+
endColumn: 23
416449
}
417450
]
418451
},
@@ -427,7 +460,10 @@ tester.run('no-undef-directives', rule, {
427460
errors: [
428461
{
429462
message: "The 'v-foo-bar' directive has been used, but not defined.",
430-
line: 3
463+
line: 3,
464+
column: 14,
465+
endLine: 3,
466+
endColumn: 23
431467
}
432468
]
433469
}

0 commit comments

Comments
 (0)