Skip to content

Commit d47de39

Browse files
authored
Update vue/no-unsupported-features rule to support <script setup> (#1554)
1 parent 6fdb024 commit d47de39

File tree

4 files changed

+83
-0
lines changed

4 files changed

+83
-0
lines changed

Diff for: docs/rules/no-unsupported-features.md

+3
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ The `"ignores"` option accepts an array of the following strings.
3232
- Vue.js 3.1.0+
3333
- `"is-attribute-with-vue-prefix"` ... [`is` attribute with `vue:` prefix](https://v3.vuejs.org/api/special-attributes.html#is)
3434
- Vue.js 3.0.0+
35+
- `"script-setup"` ... [`<script setup>`][Vue RFCs - 0040-script-setup]
3536
- `"v-model-argument"` ... [argument on `v-model`][Vue RFCs - 0005-replace-v-bind-sync-with-v-model-argument]
3637
- `"v-model-custom-modifiers"` ... [custom modifiers on `v-model`][Vue RFCs - 0011-v-model-api-change]
3738
- `"v-is"` ... [v-is](https://v3.vuejs.org/api/directives.html#v-is) directive.
@@ -105,13 +106,15 @@ The `"ignores"` option accepts an array of the following strings.
105106
- [Vue RFCs - 0003-dynamic-directive-arguments]
106107
- [Vue RFCs - 0005-replace-v-bind-sync-with-v-model-argument]
107108
- [Vue RFCs - 0011-v-model-api-change]
109+
- [Vue RFCs - 0040-script-setup]
108110
- [Vue RFCs - v-bind .prop shorthand proposal]
109111

110112
[Vue RFCs - 0001-new-slot-syntax]: https://github.com/vuejs/rfcs/blob/master/active-rfcs/0001-new-slot-syntax.md
111113
[Vue RFCs - 0002-slot-syntax-shorthand]: https://github.com/vuejs/rfcs/blob/master/active-rfcs/0002-slot-syntax-shorthand.md
112114
[Vue RFCs - 0003-dynamic-directive-arguments]: https://github.com/vuejs/rfcs/blob/master/active-rfcs/0003-dynamic-directive-arguments.md
113115
[Vue RFCs - 0005-replace-v-bind-sync-with-v-model-argument]: https://github.com/vuejs/rfcs/blob/master/active-rfcs/0005-replace-v-bind-sync-with-v-model-argument.md
114116
[Vue RFCs - 0011-v-model-api-change]: https://github.com/vuejs/rfcs/blob/master/active-rfcs/0011-v-model-api-change.md
117+
[Vue RFCs - 0040-script-setup]: https://github.com/vuejs/rfcs/blob/master/active-rfcs/0040-script-setup.md
115118

116119
[Vue RFCs - v-bind .prop shorthand proposal]: https://github.com/vuejs/rfcs/pull/18
117120

Diff for: lib/rules/no-unsupported-features.js

+4
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ const FEATURES = {
2626
'v-model-argument': require('./syntaxes/v-model-argument'),
2727
'v-model-custom-modifiers': require('./syntaxes/v-model-custom-modifiers'),
2828
'v-is': require('./syntaxes/v-is'),
29+
'script-setup': require('./syntaxes/script-setup'),
2930
// Vue.js 3.1.0+
3031
'is-attribute-with-vue-prefix': require('./syntaxes/is-attribute-with-vue-prefix')
3132
}
@@ -100,6 +101,9 @@ module.exports = {
100101
forbiddenVModelCustomModifiers:
101102
'Custom modifiers on `v-model` are not supported until Vue.js "3.0.0".',
102103
forbiddenVIs: '`v-is` are not supported until Vue.js "3.0.0".',
104+
forbiddenScriptSetup:
105+
'`<script setup>` are not supported until Vue.js "3.0.0".',
106+
// Vue.js 3.1.0+
103107
forbiddenIsAttributeWithVuePrefix:
104108
'`is="vue:"` are not supported until Vue.js "3.1.0".'
105109
}

Diff for: lib/rules/syntaxes/script-setup.js

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
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')
8+
9+
module.exports = {
10+
supported: '>=3.0.0',
11+
/** @param {RuleContext} context @returns {TemplateListener} */
12+
createScriptVisitor(context) {
13+
const scriptSetup = utils.getScriptSetupElement(context)
14+
if (!scriptSetup) {
15+
return {}
16+
}
17+
const reportNode =
18+
utils.getAttribute(scriptSetup, 'setup') || scriptSetup.startTag
19+
return {
20+
Program() {
21+
context.report({
22+
node: reportNode,
23+
messageId: 'forbiddenScriptSetup'
24+
})
25+
}
26+
}
27+
}
28+
}
+48
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
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('script-setup', '^3.0.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/script-setup', rule, {
20+
valid: [
21+
{
22+
code: `
23+
<script setup>
24+
</script>`,
25+
options: buildOptions()
26+
},
27+
{
28+
code: `
29+
<script>
30+
</script>`,
31+
options: buildOptions({ version: '^2.6.0' })
32+
}
33+
],
34+
invalid: [
35+
{
36+
code: `
37+
<script setup>
38+
</script>`,
39+
options: buildOptions({ version: '^2.6.0' }),
40+
errors: [
41+
{
42+
message: '`<script setup>` are not supported until Vue.js "3.0.0".',
43+
line: 2
44+
}
45+
]
46+
}
47+
]
48+
})

0 commit comments

Comments
 (0)