Skip to content

Commit bd1fcb5

Browse files
authored
Fix false positives due to conflicts with other rules in vue/no-unused-properties rule (#1790)
1 parent d6f0337 commit bd1fcb5

File tree

2 files changed

+45
-3
lines changed

2 files changed

+45
-3
lines changed

lib/rules/no-unused-properties.js

+4-2
Original file line numberDiff line numberDiff line change
@@ -586,8 +586,7 @@ module.exports = {
586586
}
587587
}),
588588
{
589-
/** @param {Program} node */
590-
'Program:exit'(node) {
589+
Program() {
591590
const styleVars = getStyleVariablesContext(context)
592591
if (styleVars) {
593592
templatePropertiesContainer.propertyReferences.push(
@@ -596,6 +595,9 @@ module.exports = {
596595
)
597596
)
598597
}
598+
},
599+
/** @param {Program} node */
600+
'Program:exit'(node) {
599601
if (!node.templateBody) {
600602
reportUnusedProperties()
601603
}

tests/lib/rules/no-unused-properties.js

+41-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44
*/
55
'use strict'
66

7-
const RuleTester = require('eslint').RuleTester
7+
const { RuleTester, Linter } = require('eslint')
8+
const assert = require('assert')
89
const rule = require('../../../lib/rules/no-unused-properties')
910

1011
const tester = new RuleTester({
@@ -2805,3 +2806,42 @@ tester.run('no-unused-properties', rule, {
28052806
}
28062807
]
28072808
})
2809+
2810+
// https://github.com/vuejs/eslint-plugin-vue/issues/1789
2811+
describe('`vue/no-unused-properties` and `vue/no-unused-components` should not conflict.', () => {
2812+
const linter = new Linter()
2813+
linter.defineParser('vue-eslint-parser', require('vue-eslint-parser'))
2814+
linter.defineRule(
2815+
'vue/no-unused-components',
2816+
require('../../../lib/rules/no-unused-components')
2817+
)
2818+
linter.defineRule('vue/no-unused-properties', rule)
2819+
2820+
const config = {
2821+
parser: 'vue-eslint-parser',
2822+
parserOptions: {
2823+
ecmaVersion: 2020,
2824+
sourceType: 'module'
2825+
},
2826+
rules: {
2827+
'vue/no-unused-components': 'error',
2828+
'vue/no-unused-properties': 'error'
2829+
}
2830+
}
2831+
2832+
it('should not be a false positive when using CSS v-bind().', () => {
2833+
const code = `
2834+
<template></template>
2835+
<script>
2836+
export default {
2837+
props: ['a']
2838+
};
2839+
</script>
2840+
<style>
2841+
a {
2842+
color: v-bind(a);
2843+
}
2844+
</style>`
2845+
assert.deepStrictEqual(linter.verify(code, config, 'test.vue'), [])
2846+
})
2847+
})

0 commit comments

Comments
 (0)