Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: support script setup and css var inj for vue 2.7 #1917

Merged
merged 1 commit into from Jul 6, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 3 additions & 2 deletions docs/rules/no-unsupported-features.md
Expand Up @@ -36,11 +36,12 @@ The `"ignores"` option accepts an array of the following strings.
- Vue.js 3.1.0+
- `"is-attribute-with-vue-prefix"` ... [`is` attribute with `vue:` prefix](https://v3.vuejs.org/api/special-attributes.html#is)
- Vue.js 3.0.0+
- `"style-css-vars-injection"` ... [SFC CSS variable injection][Vue RFCs - 0043-sfc-style-variables]
- `"script-setup"` ... [`<script setup>`][Vue RFCs - 0040-script-setup]
- `"v-model-argument"` ... [argument on `v-model`][Vue RFCs - 0005-replace-v-bind-sync-with-v-model-argument]
- `"v-model-custom-modifiers"` ... [custom modifiers on `v-model`][Vue RFCs - 0011-v-model-api-change]
- `"v-is"` ... [v-is](https://v3.vuejs.org/api/directives.html#v-is) directive.
- Vue.js 2.7.0+
- `"style-css-vars-injection"` ... [SFC CSS variable injection][Vue RFCs - 0043-sfc-style-variables]
- `"script-setup"` ... [`<script setup>`][Vue RFCs - 0040-script-setup]
- Vue.js 2.6.0+
- `"dynamic-directive-arguments"` ... [dynamic directive arguments](https://v3.vuejs.org/guide/template-syntax.html#dynamic-arguments).
- `"v-slot"` ... [v-slot](https://v3.vuejs.org/api/directives.html#v-slot) directive.
Expand Down
14 changes: 8 additions & 6 deletions lib/rules/no-unsupported-features.js
Expand Up @@ -20,12 +20,13 @@ const FEATURES = {
// Vue.js 2.6.0+
'dynamic-directive-arguments': require('./syntaxes/dynamic-directive-arguments'),
'v-slot': require('./syntaxes/v-slot'),
// Vue.js 2.7.0+
'script-setup': require('./syntaxes/script-setup'),
'style-css-vars-injection': require('./syntaxes/style-css-vars-injection'),
// Vue.js 3.0.0+
'v-model-argument': require('./syntaxes/v-model-argument'),
'v-model-custom-modifiers': require('./syntaxes/v-model-custom-modifiers'),
'v-is': require('./syntaxes/v-is'),
'script-setup': require('./syntaxes/script-setup'),
'style-css-vars-injection': require('./syntaxes/style-css-vars-injection'),
// Vue.js 3.1.0+
'is-attribute-with-vue-prefix': require('./syntaxes/is-attribute-with-vue-prefix'),
// Vue.js 3.2.0+
Expand Down Expand Up @@ -95,16 +96,17 @@ module.exports = {
forbiddenDynamicDirectiveArguments:
'Dynamic arguments are not supported until Vue.js "2.6.0".',
forbiddenVSlot: '`v-slot` are not supported until Vue.js "2.6.0".',
// Vue.js 2.7.0+
forbiddenScriptSetup:
'`<script setup>` is not supported until Vue.js "2.7.0".',
forbiddenStyleCssVarsInjection:
'SFC CSS variable injection is not supported until Vue.js ">=3.0.3 || >=2.7.0 <3.0.0".',
// Vue.js 3.0.0+
forbiddenVModelArgument:
'Argument on `v-model` is not supported until Vue.js "3.0.0".',
forbiddenVModelCustomModifiers:
'Custom modifiers on `v-model` are not supported until Vue.js "3.0.0".',
forbiddenVIs: '`v-is` are not supported until Vue.js "3.0.0".',
forbiddenScriptSetup:
'`<script setup>` are not supported until Vue.js "3.0.0".',
forbiddenStyleCssVarsInjection:
'SFC CSS variable injection is not supported until Vue.js "3.0.3".',
// Vue.js 3.1.0+
forbiddenIsAttributeWithVuePrefix:
'`is="vue:"` are not supported until Vue.js "3.1.0".',
Expand Down
2 changes: 1 addition & 1 deletion lib/rules/syntaxes/script-setup.js
Expand Up @@ -7,7 +7,7 @@
const utils = require('../../utils')

module.exports = {
supported: '>=3.0.0',
supported: '>=2.7.0',
/** @param {RuleContext} context @returns {TemplateListener} */
createScriptVisitor(context) {
const scriptSetup = utils.getScriptSetupElement(context)
Expand Down
2 changes: 1 addition & 1 deletion lib/rules/syntaxes/style-css-vars-injection.js
Expand Up @@ -7,7 +7,7 @@
const { getStyleVariablesContext } = require('../../utils/style-variables')

module.exports = {
supported: '>=3.0.3',
supported: '>=3.0.3 || >=2.7.0 <3.0.0',
/** @param {RuleContext} context @returns {TemplateListener} */
createScriptVisitor(context) {
const styleVars = getStyleVariablesContext(context)
Expand Down
8 changes: 7 additions & 1 deletion tests/lib/rules/no-unsupported-features/script-setup.js
Expand Up @@ -24,6 +24,12 @@ tester.run('no-unsupported-features/script-setup', rule, {
</script>`,
options: buildOptions()
},
{
code: `
<script setup>
</script>`,
options: buildOptions({ version: '^2.7.0' })
},
{
code: `
<script>
Expand All @@ -39,7 +45,7 @@ tester.run('no-unsupported-features/script-setup', rule, {
options: buildOptions({ version: '^2.6.0' }),
errors: [
{
message: '`<script setup>` are not supported until Vue.js "3.0.0".',
message: '`<script setup>` is not supported until Vue.js "2.7.0".',
line: 2
}
]
Expand Down
Expand Up @@ -54,6 +54,35 @@ tester.run('no-unsupported-features/style-css-vars-injection', rule, {
<div class="text">hello</div>
</template>

<script>
export default {
data() {
return {
color: 'red',
font: {
size: '2em',
},
}
},
}
</script>

<style>
.text {
color: v-bind(color);

/* expressions (wrap in quotes) */
font-size: v-bind('font.size');
}
</style>`,
options: buildOptions({ version: '^2.7.0' })
},
{
code: `
<template>
<div class="text">hello</div>
</template>

<script>
</script>

Expand Down Expand Up @@ -98,15 +127,15 @@ tester.run('no-unsupported-features/style-css-vars-injection', rule, {
errors: [
{
message:
'SFC CSS variable injection is not supported until Vue.js "3.0.3".',
'SFC CSS variable injection is not supported until Vue.js ">=3.0.3 || >=2.7.0 <3.0.0".',
line: 21,
column: 18,
endLine: 21,
endColumn: 31
},
{
message:
'SFC CSS variable injection is not supported until Vue.js "3.0.3".',
'SFC CSS variable injection is not supported until Vue.js ">=3.0.3 || >=2.7.0 <3.0.0".',
line: 24,
column: 22,
endLine: 24,
Expand Down