Skip to content

vue/attribute-hyphenation autofix breaks the .sync modifier #2521

@kricsleo

Description

@kricsleo

Checklist

  • I have tried restarting my IDE and the issue persists.
  • I have read the FAQ and my problem is not listed.

Tell us about your environment

  • ESLint version: 9.8.0
  • eslint-plugin-vue version: 9.27.0
  • Vue version: 2.7.16
  • Node version: 20.10.0
  • Operating System: MacOS 14.5 (23F79)

Please show your full configuration:

I'am using antfu's @antfu/eslint-config

** Remember I've set the vue/v-on-event-hyphenation rule's config autofix tobe false.**

import eslint from '@antfu/eslint-config';

export default eslint({
  rules: {
    'vue/attribute-hyphenation': ['error', 'never'],
    'vue/v-on-event-hyphenation': ['error', 'never', {
      autofix: false
    }],
  },

  vue: {
    vueVersion: 2,
  },
});

What did you do?

Suppose this:

<Hi :my-name.sync="name" />

Then running eslint . --fix

After the autofix of vue/attribute-hyphenation, code becomes:

<Hi :myName.sync="name" />

This code should not be autofixed, because .sync means this is actually a shorthand of:

<Hi :my-name="name" @update:my-name="name = $event" />

When it's autofixed to the this code:

<Hi :myName.sync="name" />

It means:

<Hi :myName="name" @update:myName="name = $event" />

And this autofixed code would break, because the event name should be update:my-name, instead of update:myName.

Might be solution

fix: (fixer) => {
if (text.includes('_')) {
return null
}
if (/^[A-Z]/.test(name)) {
return null
}
return fixer.replaceText(

Maybe we can add another .sync check here(willing to contribute a PR for this), for example:

fix: (fixer) => {
  if (text.includes('_')) {
    return null
  }

  if (/^[A-Z]/.test(name)) {
    return null
  }

+ if(text.endsWith('.sync')) {
+   return null
+ }

  return fixer.replaceText(
    node.key,
    text.replace(name, caseConverter(name))
  )
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      pFad - Phonifier reborn

      Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

      Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


      Alternative Proxies:

      Alternative Proxy

      pFad Proxy

      pFad v3 Proxy

      pFad v4 Proxy