6
6
7
7
const RuleTester = require ( 'eslint' ) . RuleTester
8
8
const rule = require ( '../../../lib/rules/no-undef-components' )
9
+ const semver = require ( 'semver' )
9
10
10
11
const tester = new RuleTester ( {
11
12
parser : require . resolve ( 'vue-eslint-parser' ) ,
@@ -598,6 +599,26 @@ tester.run('no-undef-components', rule, {
598
599
<script setup>
599
600
import TheModal from 'foo'
600
601
</script>`
602
+ } ,
603
+ {
604
+ filename : 'test.vue' ,
605
+ code : `
606
+ <script setup lang="ts">
607
+ import Foo from './Foo.vue'
608
+ import {HelloWorld1} from './components/HelloWorld'
609
+ </script>
610
+
611
+ <template>
612
+ <Foo />
613
+ <HelloWorld1 />
614
+ </template>
615
+ ` ,
616
+ parserOptions : {
617
+ ecmaVersion : 6 ,
618
+ sourceType : 'module' ,
619
+ parser : require . resolve ( '@typescript-eslint/parser' )
620
+ } ,
621
+ parser : require . resolve ( 'vue-eslint-parser' )
601
622
}
602
623
] ,
603
624
invalid : [
@@ -661,9 +682,14 @@ tester.run('no-undef-components', rule, {
661
682
}
662
683
]
663
684
} ,
664
- {
665
- filename : 'test.vue' ,
666
- code : `
685
+ ...( semver . gte (
686
+ require ( '@typescript-eslint/parser/package.json' ) . version ,
687
+ '5.0.0'
688
+ )
689
+ ? [
690
+ {
691
+ filename : 'test.vue' ,
692
+ code : `
667
693
<script setup lang="ts">
668
694
import type Foo from './Foo.vue'
669
695
import type {HelloWorld1} from './components/HelloWorld'
@@ -681,6 +707,58 @@ tester.run('no-undef-components', rule, {
681
707
<HelloWorld4 />
682
708
<HelloWorld5 />
683
709
</template>
710
+ ` ,
711
+ parserOptions : {
712
+ ecmaVersion : 6 ,
713
+ sourceType : 'module' ,
714
+ parser : require . resolve ( '@typescript-eslint/parser' )
715
+ } ,
716
+ parser : require . resolve ( 'vue-eslint-parser' ) ,
717
+ errors : [
718
+ {
719
+ message :
720
+ "The '<Foo>' component has been used, but 'Foo' only refers to a type." ,
721
+ line : 12
722
+ } ,
723
+ {
724
+ message :
725
+ "The '<HelloWorld1>' component has been used, but 'HelloWorld1' only refers to a type." ,
726
+ line : 13
727
+ } ,
728
+ {
729
+ message :
730
+ "The '<HelloWorld2>' component has been used, but 'HelloWorld2' only refers to a type." ,
731
+ line : 14
732
+ } ,
733
+ {
734
+ message :
735
+ "The '<HelloWorld3>' component has been used, but 'HelloWorld3' only refers to a type." ,
736
+ line : 15
737
+ } ,
738
+ {
739
+ message :
740
+ "The '<HelloWorld4>' component has been used, but 'HelloWorld4' only refers to a type." ,
741
+ line : 16
742
+ } ,
743
+ {
744
+ message :
745
+ "The '<HelloWorld5>' component has been used, but 'HelloWorld5' only refers to a type." ,
746
+ line : 17
747
+ }
748
+ ]
749
+ }
750
+ ]
751
+ : [ ] ) ,
752
+ {
753
+ filename : 'test.vue' ,
754
+ code : `
755
+ <script setup lang="ts">
756
+ type Foo = {}
757
+ </script>
758
+
759
+ <template>
760
+ <Foo />
761
+ </template>
684
762
` ,
685
763
parserOptions : {
686
764
ecmaVersion : 6 ,
@@ -692,32 +770,7 @@ tester.run('no-undef-components', rule, {
692
770
{
693
771
message :
694
772
"The '<Foo>' component has been used, but 'Foo' only refers to a type." ,
695
- line : 12
696
- } ,
697
- {
698
- message :
699
- "The '<HelloWorld1>' component has been used, but 'HelloWorld1' only refers to a type." ,
700
- line : 13
701
- } ,
702
- {
703
- message :
704
- "The '<HelloWorld2>' component has been used, but 'HelloWorld2' only refers to a type." ,
705
- line : 14
706
- } ,
707
- {
708
- message :
709
- "The '<HelloWorld3>' component has been used, but 'HelloWorld3' only refers to a type." ,
710
- line : 15
711
- } ,
712
- {
713
- message :
714
- "The '<HelloWorld4>' component has been used, but 'HelloWorld4' only refers to a type." ,
715
- line : 16
716
- } ,
717
- {
718
- message :
719
- "The '<HelloWorld5>' component has been used, but 'HelloWorld5' only refers to a type." ,
720
- line : 17
773
+ line : 7
721
774
}
722
775
]
723
776
} ,
0 commit comments