File tree 6 files changed +177
-2
lines changed
tests/lib/rules/no-unsupported-features
6 files changed +177
-2
lines changed Original file line number Diff line number Diff line change @@ -29,6 +29,9 @@ This rule reports unsupported Vue.js syntax on the specified version.
29
29
- ` version ` ... The ` version ` option accepts [ the valid version range of ` node-semver ` ] ( https://github.com/npm/node-semver#range-grammar ) . Set the version of Vue.js you are using. This option is required.
30
30
- ` ignores ` ... You can use this ` ignores ` option to ignore the given features.
31
31
The ` "ignores" ` option accepts an array of the following strings.
32
+ - Vue.js 3.3.0+
33
+ - ` "define-slots" ` ... ` defineSlots() ` macro.
34
+ - ` "define-options" ` ... ` defineOptions() ` macro.
32
35
- Vue.js 3.2.0+
33
36
- ` "v-memo" ` ... [ v-memo] ( https://vuejs.org/api/built-in-directives.html#v-memo ) directive.
34
37
- ` "v-bind-prop-modifier-shorthand" ` ... ` v-bind ` with ` .prop ` modifier shorthand.
@@ -100,6 +103,8 @@ The `"ignores"` option accepts an array of the following strings.
100
103
101
104
## :books : Further Reading
102
105
106
+ - [ API - defineOptions()] ( https://vuejs.org/api/sfc-script-setup.html#defineoptions )
107
+ - [ API - defineSlots()] ( https://vuejs.org/api/sfc-script-setup.html#defineslots )
103
108
- [ API - v-memo] ( https://vuejs.org/api/built-in-directives.html#v-memo )
104
109
- [ API - v-is] ( https://v3.vuejs.org/api/directives.html#v-is )
105
110
- [ API - v-is (Old)] ( https://github.com/vuejs/docs-next/blob/008613756c3d781128d96b64a2d27f7598f8f548/src/api/directives.md#v-is )
Original file line number Diff line number Diff line change @@ -32,7 +32,10 @@ const FEATURES = {
32
32
// Vue.js 3.2.0+
33
33
'v-memo' : require ( './syntaxes/v-memo' ) ,
34
34
'v-bind-prop-modifier-shorthand' : require ( './syntaxes/v-bind-prop-modifier-shorthand' ) ,
35
- 'v-bind-attr-modifier' : require ( './syntaxes/v-bind-attr-modifier' )
35
+ 'v-bind-attr-modifier' : require ( './syntaxes/v-bind-attr-modifier' ) ,
36
+ // Vue.js 3.3.0+
37
+ 'define-options' : require ( './syntaxes/define-options' ) ,
38
+ 'define-slots' : require ( './syntaxes/define-slots' )
36
39
}
37
40
38
41
const SYNTAX_NAMES = /** @type {(keyof FEATURES)[] } */ ( Object . keys ( FEATURES ) )
@@ -115,7 +118,12 @@ module.exports = {
115
118
forbiddenVBindPropModifierShorthand :
116
119
'`.prop` shorthand are not supported until Vue.js "3.2.0".' ,
117
120
forbiddenVBindAttrModifier :
118
- '`.attr` modifiers on `v-bind` are not supported until Vue.js "3.2.0".'
121
+ '`.attr` modifiers on `v-bind` are not supported until Vue.js "3.2.0".' ,
122
+ // Vue.js 3.3.0+
123
+ forbiddenDefineOptions :
124
+ '`defineOptions()` macros are not supported until Vue.js "3.3.0".' ,
125
+ forbiddenDefineSlots :
126
+ '`defineSlots()` macros are not supported until Vue.js "3.3.0".'
119
127
}
120
128
} ,
121
129
/** @param {RuleContext } context */
Original file line number Diff line number Diff line change
1
+ /**
2
+ * @author Yosuke Ota
3
+ * See LICENSE file in root directory for full license.
4
+ */
5
+ 'use strict'
6
+
7
+ const utils = require ( '../../utils/index' )
8
+
9
+ module . exports = {
10
+ supported : '>=3.3.0' ,
11
+ /** @param {RuleContext } context @returns {RuleListener } */
12
+ createScriptVisitor ( context ) {
13
+ return utils . defineScriptSetupVisitor ( context , {
14
+ onDefineOptionsEnter ( node ) {
15
+ context . report ( {
16
+ node,
17
+ messageId : 'forbiddenDefineOptions'
18
+ } )
19
+ }
20
+ } )
21
+ }
22
+ }
Original file line number Diff line number Diff line change
1
+ /**
2
+ * @author Yosuke Ota
3
+ * See LICENSE file in root directory for full license.
4
+ */
5
+ 'use strict'
6
+
7
+ const utils = require ( '../../utils/index' )
8
+
9
+ module . exports = {
10
+ supported : '>=3.3.0' ,
11
+ /** @param {RuleContext } context @returns {RuleListener } */
12
+ createScriptVisitor ( context ) {
13
+ return utils . defineScriptSetupVisitor ( context , {
14
+ onDefineSlotsEnter ( node ) {
15
+ context . report ( {
16
+ node,
17
+ messageId : 'forbiddenDefineSlots'
18
+ } )
19
+ }
20
+ } )
21
+ }
22
+ }
Original file line number Diff line number Diff line change
1
+ /**
2
+ * @author Yosuke Ota
3
+ * See LICENSE file in root directory for full license.
4
+ */
5
+ 'use strict'
6
+
7
+ const RuleTester = require ( 'eslint' ) . RuleTester
8
+ const rule = require ( '../../../../lib/rules/no-unsupported-features' )
9
+ const utils = require ( './utils' )
10
+
11
+ const buildOptions = utils . optionsBuilder ( 'define-options' , '^3.2.0' )
12
+ const tester = new RuleTester ( {
13
+ parser : require . resolve ( 'vue-eslint-parser' ) ,
14
+ parserOptions : {
15
+ ecmaVersion : 2019
16
+ }
17
+ } )
18
+
19
+ tester . run ( 'no-unsupported-features/define-options' , rule , {
20
+ valid : [
21
+ {
22
+ code : `
23
+ <script setup>
24
+ defineOptions({})
25
+ </script>` ,
26
+ options : buildOptions ( { version : '^3.3.0' } )
27
+ } ,
28
+ {
29
+ code : `
30
+ <script setup>
31
+ defineProps({})
32
+ </script>` ,
33
+ options : buildOptions ( )
34
+ } ,
35
+ {
36
+ code : `
37
+ <script setup>
38
+ defineOptions({})
39
+ </script>` ,
40
+ options : buildOptions ( { version : '^3.0.0' , ignores : [ 'define-options' ] } )
41
+ }
42
+ ] ,
43
+ invalid : [
44
+ {
45
+ code : `
46
+ <script setup>
47
+ defineOptions({})
48
+ </script>` ,
49
+ options : buildOptions ( ) ,
50
+ errors : [
51
+ {
52
+ message :
53
+ '`defineOptions()` macros are not supported until Vue.js "3.3.0".' ,
54
+ line : 3
55
+ }
56
+ ]
57
+ }
58
+ ]
59
+ } )
Original file line number Diff line number Diff line change
1
+ /**
2
+ * @author Yosuke Ota
3
+ * See LICENSE file in root directory for full license.
4
+ */
5
+ 'use strict'
6
+
7
+ const RuleTester = require ( 'eslint' ) . RuleTester
8
+ const rule = require ( '../../../../lib/rules/no-unsupported-features' )
9
+ const utils = require ( './utils' )
10
+
11
+ const buildOptions = utils . optionsBuilder ( 'define-slots' , '^3.2.0' )
12
+ const tester = new RuleTester ( {
13
+ parser : require . resolve ( 'vue-eslint-parser' ) ,
14
+ parserOptions : {
15
+ ecmaVersion : 2019
16
+ }
17
+ } )
18
+
19
+ tester . run ( 'no-unsupported-features/define-slots' , rule , {
20
+ valid : [
21
+ {
22
+ code : `
23
+ <script setup>
24
+ const slots = defineSlots()
25
+ </script>` ,
26
+ options : buildOptions ( { version : '^3.3.0' } )
27
+ } ,
28
+ {
29
+ code : `
30
+ <script setup>
31
+ defineProps({})
32
+ </script>` ,
33
+ options : buildOptions ( )
34
+ } ,
35
+ {
36
+ code : `
37
+ <script setup>
38
+ const slots = defineSlots()
39
+ </script>` ,
40
+ options : buildOptions ( { version : '^3.0.0' , ignores : [ 'define-slots' ] } )
41
+ }
42
+ ] ,
43
+ invalid : [
44
+ {
45
+ code : `
46
+ <script setup>
47
+ const slots = defineSlots()
48
+ </script>` ,
49
+ options : buildOptions ( ) ,
50
+ errors : [
51
+ {
52
+ message :
53
+ '`defineSlots()` macros are not supported until Vue.js "3.3.0".' ,
54
+ line : 3
55
+ }
56
+ ]
57
+ }
58
+ ]
59
+ } )
You can’t perform that action at this time.
0 commit comments