-
-
Notifications
You must be signed in to change notification settings - Fork 669
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
Add rule attribute-hyphenation
.
#95
Add rule attribute-hyphenation
.
#95
Conversation
html-attributes-casing
.html-attributes-casing
.
Based on #92 (comment) we are missing some cases |
c248c96
to
a4be85d
Compare
html-attributes-casing
.html-attributes-casing
.
@michalsnik rule is done |
6178486
to
24305db
Compare
24305db
to
50dce57
Compare
docs/rules/html-attributes-casing.md
Outdated
@@ -0,0 +1,35 @@ | |||
# Define a style for the attributes casing in templates. (html-attributes-casing) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for the contributing! I'm sorry for the delay.
I'm not sure whether this rule makes sense. Below is the result of my investigation.
- In all known HTML/SVG/MathML elements, all of
attrname
,attrName
andAttrName
are the same attribute butattr-name
is another. - In custom components,
- about defined properties,
- for example
attr-name
property, people can chooseattrName
orattr-name
butattrname
andAttrName
do not work. - for example
attrName
property, people can chooseattrName
orattr-name
butattrname
andAttrName
do not work. - for example
AttrName
property, people can chooseAttrName
orattr-name
butattrname
andattrName
do not work.
- for example
- about undefined properties, the same behaivor to known HTML/SVG/MathML elements.
- about defined properties,
So I think the options camelCase
and PascalCase
are not useful because it might be uncontrollable due to the definition of libraries. So maybe.... What do you think below?
- Change rule name to
attribute-hyphenation
- Options are:
"always"
(default) or"never"
."always"
... Use hyphenated name. (It errors on upper case letters.)"never"
... Don't use hyphenated name. (It errors on hyphens exceptdata-
andaria-
.)
(I think this rule don't need html-
prefix because this rule can work on AST. I think that rules which use details of tokens should have html-
prefix.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like it:
- change name of rule to attribute-hyphenation
- apply rule only on components
isCustomComponent
- change options to
always
(default) ornever
- add
aria-
to exceptions
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mysticatea there is bug: vuejs/vue-eslint-parser#12 with parsing argument
for VDirectiveKey
lib/rules/html-attributes-casing.js
Outdated
// ---------------------------------------------------------------------- | ||
|
||
utils.registerTemplateBodyVisitor(context, { | ||
'VStartTag' (obj) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that you can use VAttribute
handler to avoid extra looping.
lib/rules/html-attributes-casing.js
Outdated
|
||
utils.registerTemplateBodyVisitor(context, { | ||
'VStartTag' (obj) { | ||
if (!utils.isSvgElementName(obj.id.name) && !utils.isMathMLElementName(obj.id.name)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This rule should check only custom components.
lib/utils/mathml-elements.json
Outdated
@@ -0,0 +1,206 @@ | |||
[ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can use node.namespace
to check SVG/MathML now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
docs/rules/attribute-hyphenation.md
Outdated
|
||
## :wrench: Options | ||
|
||
Default casing is set to `allways` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
always
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@afontcu fixed
docs/rules/attribute-hyphenation.md
Outdated
```html | ||
<template> | ||
<foo my-prop="prop"> | ||
<a onClick="retrun false"></a> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
return (same below 😇 )
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@afontcu fixed
54cd80e
to
8d8e3d7
Compare
html-attributes-casing
.attribute-hyphenation
.
790099f
to
a6342f4
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, thank you!
* master: Add rule `vue/require-valid-default-prop`. (vuejs#119) 3.10.0 Update readme to 3.10.0 Chore: remove package-lock.json (vuejs#128) Fix: parserService must exist always (fixes vuejs#125) (vuejs#127) Add rule `require-render-return`. (vuejs#114) 3.9.0 Update package-lock Update: options for `no-duplicate-attributes` (fixes vuejs#112)(vuejs#113) New: add rule `attribute-hyphenation`. (fixes vuejs#92)(vuejs#95) Add namespace check of svg & mathML instead of tag names (vuejs#120)⚠️ Add support for deprecated state in update-rules⚠️ (vuejs#121) Add rules: `no-dupe-keys` and `no-reserved-keys`. (vuejs#88) Chore: Improve tests for name-property-casing & improve documentation (vuejs#115) New: add `require-prop-types` rule (fixes vuejs#19)(vuejs#85) Update: upgrade vue-eslint-parser (fixes vuejs#36, fixes vuejs#56, fixes vuejs#96) (vuejs#116)
This PR implements rules proposed in #92
TODO:
data-
attributearia-
attributenode.namespace
to determine if node is Svg & MathML instead of checking node namesThis PR contains changes proposed in #120 and should be merged after it.