Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 628f409

Browse files
Fix false positives for namespace component in vue/script-setup-uses-vars rule (#1602)
1 parent 59db655 commit 628f409

File tree

3 files changed

+33
-5
lines changed

3 files changed

+33
-5
lines changed

‎lib/rules/script-setup-uses-vars.js‎

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -53,28 +53,32 @@ module.exports = {
5353
/**
5454
* `casing.camelCase()` converts the beginning to lowercase,
5555
* but does not convert the case of the beginning character when converting with Vue3.
56-
* @see https://github.com/vuejs/vue-next/blob/1ffd48a2f5fd3eead3ea29dae668b7ed1c6f6130/packages/shared/src/index.ts#L116
56+
* @see https://github.com/vuejs/vue-next/blob/2749c15170ad4913e6530a257db485d4e7ed2283/packages/shared/src/index.ts#L116
5757
* @param {string} str
5858
*/
5959
function camelize(str) {
6060
return str.replace(/-(\w)/g, (_, c) => (c ? c.toUpperCase() : ''))
6161
}
6262
/**
63-
* @see https://github.com/vuejs/vue-next/blob/1ffd48a2f5fd3eead3ea29dae668b7ed1c6f6130/packages/compiler-core/src/transforms/transformElement.ts#L321
63+
* @see https://github.com/vuejs/vue-next/blob/2749c15170ad4913e6530a257db485d4e7ed2283/packages/compiler-core/src/transforms/transformElement.ts#L333
6464
* @param {string} name
6565
*/
66-
function markElementVariableAsUsed(name) {
66+
function markSetupReferenceVariableAsUsed(name) {
6767
if (scriptVariableNames.has(name)) {
6868
context.markVariableAsUsed(name)
69+
return true
6970
}
7071
const camelName = camelize(name)
7172
if (scriptVariableNames.has(camelName)) {
7273
context.markVariableAsUsed(camelName)
74+
return true
7375
}
7476
const pascalName = casing.capitalize(camelName)
7577
if (scriptVariableNames.has(pascalName)) {
7678
context.markVariableAsUsed(pascalName)
79+
return true
7780
}
81+
return false
7882
}
7983

8084
return utils.defineTemplateBodyVisitor(
@@ -97,14 +101,21 @@ module.exports = {
97101
) {
98102
return
99103
}
100-
markElementVariableAsUsed(node.rawName)
104+
if (!markSetupReferenceVariableAsUsed(node.rawName)) {
105+
// Check namespace
106+
// https://github.com/vuejs/vue-next/blob/2749c15170ad4913e6530a257db485d4e7ed2283/packages/compiler-core/src/transforms/transformElement.ts#L304
107+
const dotIndex = node.rawName.indexOf('.')
108+
if (dotIndex > 0) {
109+
markSetupReferenceVariableAsUsed(node.rawName.slice(0, dotIndex))
110+
}
111+
}
101112
},
102113
/** @param {VDirective} node */
103114
'VAttribute[directive=true]'(node) {
104115
if (utils.isBuiltInDirectiveName(node.key.name.name)) {
105116
return
106117
}
107-
markElementVariableAsUsed(`v-${node.key.name.rawName}`)
118+
markSetupReferenceVariableAsUsed(`v-${node.key.name.rawName}`)
108119
},
109120
/** @param {VAttribute} node */
110121
'VAttribute[directive=false]'(node) {

‎lib/utils/index.js‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -704,6 +704,7 @@ module.exports = {
704704
name === 'pre' ||
705705
name === 'cloak' ||
706706
name === 'once' ||
707+
name === 'memo' ||
707708
name === 'is'
708709
)
709710
},

‎tests/lib/rules/script-setup-uses-vars.js‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,22 @@ describe('script-setup-uses-vars', () => {
198198
}
199199
</style>
200200
`
201+
},
202+
// ns
203+
{
204+
filename: 'test.vue',
205+
code: `
206+
<script setup>
207+
/* eslint script-setup-uses-vars: 1 */
208+
import * as Form from './form-components'
209+
</script>
210+
211+
<template>
212+
<Form.Input>
213+
<Form.Label>label</Form.Label>
214+
</Form.Input>
215+
</template>
216+
`
201217
}
202218
],
203219

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /