From 23be6e4ef09d0241648010604d6af6a821fe68cc Mon Sep 17 00:00:00 2001 From: Yosuke Ota Date: Sun, 18 Jul 2021 15:21:35 +0900 Subject: [PATCH] Update some rules to support style CSS vars injection (#1574) * Update `vue/no-unused-properties` and `vue/script-setup-uses-vars` rule to support style CSS vars * Add testcase * upgrade vue-eslint-parser * update test * Update no-unsupported-features --- docs/rules/no-unsupported-features.md | 3 + lib/rules/no-unsupported-features.js | 3 + lib/rules/no-unused-properties.js | 10 ++ lib/rules/script-setup-uses-vars.js | 12 +- .../syntaxes/style-css-vars-injection.js | 28 +++++ lib/utils/style-variables/index.js | 61 +++++++++ package.json | 2 +- tests/lib/rules/no-parsing-error.js | 26 ++++ .../style-css-vars-injection.js | 118 ++++++++++++++++++ tests/lib/rules/no-unused-properties.js | 32 +++++ tests/lib/rules/script-setup-uses-vars.js | 40 ++++++ 11 files changed, 333 insertions(+), 2 deletions(-) create mode 100644 lib/rules/syntaxes/style-css-vars-injection.js create mode 100644 lib/utils/style-variables/index.js create mode 100644 tests/lib/rules/no-unsupported-features/style-css-vars-injection.js diff --git a/docs/rules/no-unsupported-features.md b/docs/rules/no-unsupported-features.md index 48e222a99..858a8445d 100644 --- a/docs/rules/no-unsupported-features.md +++ b/docs/rules/no-unsupported-features.md @@ -32,6 +32,7 @@ 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"` ... [` + + `, + options: buildOptions() + }, + { + code: ` + + + + + `, + options: buildOptions({ version: '^2.6.0' }) + } + ], + invalid: [ + { + code: ` + + + + + `, + options: buildOptions({ version: '^3.0.0' }), + errors: [ + { + message: + 'SFC CSS variable injection is not supported until Vue.js "3.0.3".', + line: 21, + column: 18, + endLine: 21, + endColumn: 31 + }, + { + message: + 'SFC CSS variable injection is not supported until Vue.js "3.0.3".', + line: 24, + column: 22, + endLine: 24, + endColumn: 41 + } + ] + } + ] +}) diff --git a/tests/lib/rules/no-unused-properties.js b/tests/lib/rules/no-unused-properties.js index 4af8091af..164e562ab 100644 --- a/tests/lib/rules/no-unused-properties.js +++ b/tests/lib/rules/no-unused-properties.js @@ -1562,6 +1562,38 @@ tester.run('no-unused-properties', rule, { } `, options: allOptions + }, + + //style vars + { + filename: 'test.vue', + code: ` + + + + + + ` } ], diff --git a/tests/lib/rules/script-setup-uses-vars.js b/tests/lib/rules/script-setup-uses-vars.js index 5d3c80060..dd49cf6a2 100644 --- a/tests/lib/rules/script-setup-uses-vars.js +++ b/tests/lib/rules/script-setup-uses-vars.js @@ -179,6 +179,25 @@ describe('script-setup-uses-vars', () => {
` + }, + + //style vars + { + filename: 'test.vue', + code: ` + + + + ` } ], @@ -305,6 +324,27 @@ describe('script-setup-uses-vars', () => { line: 4 } ] + }, + + //style vars + { + filename: 'test.vue', + code: ` + + + + `, + errors: ["'color' is assigned a value but never used."] } ] })