eslint-plugin-vue icon indicating copy to clipboard operation
eslint-plugin-vue copied to clipboard

Extend no-duplicate-attributes with new option allowedDOMProps

Open mrzdevcore opened this issue 3 years ago • 3 comments

What rule do you want to change? no-duplicate-attributes

Does this change cause the rule to produce more or fewer warnings?

How will the change be implemented? (New option, new default behavior, etc.)? New option: allowedDOMProps

Please provide some example code that this change will affect:

{
  "vue/no-duplicate-attributes": ["error", {
    "allowCoexistClass": true,
    "allowCoexistStyle": true,
    "allowedDOMProps": ["name"]
  }]
}
 <MyComponent :name="'test'" :name.prop="def" />

What does the rule currently do for this code? nothing

What will the rule do after it's changed?

  • allowedDOMProps (Array<string>) ... Enables [v-bind:attribute-name.prop] directive to coexist with [v-bind:attribute-name] or [attribute-name] attribute. Default is []

Additional context

Pull request

mrzdevcore avatar Jun 29 '22 15:06 mrzdevcore

Thank you for posting issue.

I think we need to set allowedDOMProps for each component. This is because when a property is specified without .prop, it depends on each component whether or not it is applied directly to the DOM.

I think it makes sense to make the option an object so that you can specify a component name or pattern for the key, or use an array of objects with the component name or pattern and property name. What do you think?

ota-meshi avatar Jul 01 '22 05:07 ota-meshi

Hello @ota-meshi

I think it's a good idea. I will do it like that then.

{
  "vue/no-duplicate-attributes": ["error", {
    "allowCoexistClass": true,
    "allowCoexistStyle": true,
    "allowedDOMProps": [
         {
             "name": "<components-pattern>",
             "props": ["id", "name"]
         }
     ]
  }]
}

Is that ok for you ? @ota-meshi

mrzdevcore avatar Jul 04 '22 09:07 mrzdevcore

It sounds almost good!

I don't think <> is necessary.

{
  "vue/no-duplicate-attributes": ["error", {
    "allowCoexistClass": true,
    "allowCoexistStyle": true,
    "allowedDOMProps": [
         {
             "name": "components-pattern",
             "props": ["id", "name"]
         }
     ]
  }]
}

I think you can use toRegExp to use the pattern in the component name when implementing.

https://github.com/vuejs/eslint-plugin-vue/blob/71622f29e6f826c04e6dba7083ed65670e2edbf3/lib/utils/regexp.js#L27

ota-meshi avatar Jul 04 '22 09:07 ota-meshi