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

Fix false positives due to conflicts with other rules in vue/no-unused-properties rule #1790

Merged
merged 1 commit into from Feb 4, 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
6 changes: 4 additions & 2 deletions lib/rules/no-unused-properties.js
Expand Up @@ -586,8 +586,7 @@ module.exports = {
}
}),
{
/** @param {Program} node */
'Program:exit'(node) {
Program() {
const styleVars = getStyleVariablesContext(context)
if (styleVars) {
templatePropertiesContainer.propertyReferences.push(
Expand All @@ -596,6 +595,9 @@ module.exports = {
)
)
}
},
/** @param {Program} node */
'Program:exit'(node) {
if (!node.templateBody) {
reportUnusedProperties()
}
Expand Down
42 changes: 41 additions & 1 deletion tests/lib/rules/no-unused-properties.js
Expand Up @@ -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({
Expand Down Expand Up @@ -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 = `
<template></template>
<script>
export default {
props: ['a']
};
</script>
<style>
a {
color: v-bind(a);
}
</style>`
assert.deepStrictEqual(linter.verify(code, config, 'test.vue'), [])
})
})