From bd1fcb5533946a98bda6cbbbde66817ce1a6f74c Mon Sep 17 00:00:00 2001 From: Yosuke Ota Date: Fri, 4 Feb 2022 19:13:18 +0900 Subject: [PATCH] Fix false positives due to conflicts with other rules in `vue/no-unused-properties` rule (#1790) --- lib/rules/no-unused-properties.js | 6 ++-- tests/lib/rules/no-unused-properties.js | 42 ++++++++++++++++++++++++- 2 files changed, 45 insertions(+), 3 deletions(-) diff --git a/lib/rules/no-unused-properties.js b/lib/rules/no-unused-properties.js index 74762e446..1414df359 100644 --- a/lib/rules/no-unused-properties.js +++ b/lib/rules/no-unused-properties.js @@ -586,8 +586,7 @@ module.exports = { } }), { - /** @param {Program} node */ - 'Program:exit'(node) { + Program() { const styleVars = getStyleVariablesContext(context) if (styleVars) { templatePropertiesContainer.propertyReferences.push( @@ -596,6 +595,9 @@ module.exports = { ) ) } + }, + /** @param {Program} node */ + 'Program:exit'(node) { if (!node.templateBody) { reportUnusedProperties() } diff --git a/tests/lib/rules/no-unused-properties.js b/tests/lib/rules/no-unused-properties.js index 0023443cb..a75d83e72 100644 --- a/tests/lib/rules/no-unused-properties.js +++ b/tests/lib/rules/no-unused-properties.js @@ -4,7 +4,8 @@ */ 'use strict' -const RuleTester = require('eslint').RuleTester +const { RuleTester, Linter } = require('eslint') +const assert = require('assert') const rule = require('../../../lib/rules/no-unused-properties') const tester = new RuleTester({ @@ -2805,3 +2806,42 @@ tester.run('no-unused-properties', rule, { } ] }) + +// https://github.com/vuejs/eslint-plugin-vue/issues/1789 +describe('`vue/no-unused-properties` and `vue/no-unused-components` should not conflict.', () => { + const linter = new Linter() + linter.defineParser('vue-eslint-parser', require('vue-eslint-parser')) + linter.defineRule( + 'vue/no-unused-components', + require('../../../lib/rules/no-unused-components') + ) + linter.defineRule('vue/no-unused-properties', rule) + + const config = { + parser: 'vue-eslint-parser', + parserOptions: { + ecmaVersion: 2020, + sourceType: 'module' + }, + rules: { + 'vue/no-unused-components': 'error', + 'vue/no-unused-properties': 'error' + } + } + + it('should not be a false positive when using CSS v-bind().', () => { + const code = ` + + + ` + assert.deepStrictEqual(linter.verify(code, config, 'test.vue'), []) + }) +})