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

prevent-abbreviations: Skip fix for variables used in Vue template #2012

Merged
merged 1 commit into from
Dec 12, 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
7 changes: 6 additions & 1 deletion rules/prevent-abbreviations.js
Expand Up @@ -448,7 +448,12 @@ const create = context => {
node: definition.name,
};

if (variableReplacements.total === 1 && shouldFix(variable) && variableReplacements.samples[0]) {
if (
variableReplacements.total === 1
&& shouldFix(variable)
&& variableReplacements.samples[0]
&& !variable.references.some(reference => reference.vueUsedInTemplate)
) {
const [replacement] = variableReplacements.samples;

for (const scope of scopes) {
Expand Down
31 changes: 31 additions & 0 deletions test/prevent-abbreviations.mjs
Expand Up @@ -2002,5 +2002,36 @@ test({
],
},
],
});

test.vue({
valid: [],
invalid: [
{
code: outdent`
<template>
<button @click="goToPrev"/>
</template>
<script setup>
const goToPrev = () => {}
</script>
`,
errors: 1,
},
{
code: outdent`
<template><button/></template>
<script setup>
const goToPrev = () => {}
</script>
`,
output: outdent`
<template><button/></template>
<script setup>
const goToPrevious = () => {}
</script>
`,
errors: 1,
},
],
});