Skip to content

Commit 3da8d31

Browse files
rgaudyRaphaël Gaudy
and
Raphaël Gaudy
authored
Make an exception for some SVG attributes in vue/attribute-hyphenation (#1484)
* Closes issue #1483 * linting Co-authored-by: Raphaël Gaudy <[email protected]>
1 parent 793112d commit 3da8d31

File tree

3 files changed

+146
-4
lines changed

3 files changed

+146
-4
lines changed

docs/rules/attribute-hyphenation.md

+4-3
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,11 @@ This rule enforces using hyphenated attribute names on custom components in Vue
4040
}
4141
```
4242

43-
Default casing is set to `always` with `['data-', 'aria-', 'slot-scope']` set to be ignored
43+
Default casing is set to `always`. By default the following attributes are ignored: `data-`, `aria-`, `slot-scope`,
44+
and all the [SVG attributes](https://developer.mozilla.org/en-US/docs/Web/SVG/Attribute) with either an upper case letter or an hyphen.
4445

4546
- `"always"` (default) ... Use hyphenated name.
46-
- `"never"` ... Don't use hyphenated name except `data-`, `aria-` and `slot-scope`.
47+
- `"never"` ... Don't use hyphenated name except the ones that are ignored.
4748
- `"ignore"` ... Array of ignored names
4849

4950
### `"always"`
@@ -66,7 +67,7 @@ It errors on upper case letters.
6667

6768
### `"never"`
6869

69-
It errors on hyphens except `data-`, `aria-` and `slot-scope`.
70+
It errors on hyphens except on the attributes in the ignored attributes list.
7071

7172
<eslint-code-block fix :rules="{'vue/attribute-hyphenation': ['error', 'never']}">
7273

lib/rules/attribute-hyphenation.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
const utils = require('../utils')
88
const casing = require('../utils/casing')
9+
const svgAttributes = require('../utils/svg-attributes-weird-case.json')
910

1011
// ------------------------------------------------------------------------------
1112
// Rule Definition
@@ -51,7 +52,9 @@ module.exports = {
5152
const option = context.options[0]
5253
const optionsPayload = context.options[1]
5354
const useHyphenated = option !== 'never'
54-
let ignoredAttributes = ['data-', 'aria-', 'slot-scope']
55+
let ignoredAttributes = ['data-', 'aria-', 'slot-scope'].concat(
56+
svgAttributes
57+
)
5558

5659
if (optionsPayload && optionsPayload.ignore) {
5760
ignoredAttributes = ignoredAttributes.concat(optionsPayload.ignore)
+138
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,138 @@
1+
[
2+
"accent-height",
3+
"alignment-baseline",
4+
"arabic-form",
5+
"attributeName",
6+
"attributeType",
7+
"baseFrequency",
8+
"baseline-shift",
9+
"baseProfile",
10+
"calcMode",
11+
"cap-height",
12+
"clipPathUnits",
13+
"clip-path",
14+
"clip-rule",
15+
"color-interpolation",
16+
"color-interpolation-filters",
17+
"color-profile",
18+
"color-rendering",
19+
"contentScriptType",
20+
"contentStyleType",
21+
"diffuseConstant",
22+
"dominant-baseline",
23+
"edgeMode",
24+
"enable-background",
25+
"externalResourcesRequired",
26+
"fill-opacity",
27+
"fill-rule",
28+
"filterRes",
29+
"filterUnits",
30+
"flood-color",
31+
"flood-opacity",
32+
"font-family",
33+
"font-size",
34+
"font-size-adjust",
35+
"font-stretch",
36+
"font-style",
37+
"font-variant",
38+
"font-weight",
39+
"glyph-name",
40+
"glyph-orientation-horizontal",
41+
"glyph-orientation-vertical",
42+
"glyphRef",
43+
"gradientTransform",
44+
"gradientUnits",
45+
"horiz-adv-x",
46+
"horiz-origin-x",
47+
"image-rendering",
48+
"kernelMatrix",
49+
"kernelUnitLength",
50+
"keyPoints",
51+
"keySplines",
52+
"keyTimes",
53+
"lengthAdjust",
54+
"letter-spacing",
55+
"lighting-color",
56+
"limitingConeAngle",
57+
"marker-end",
58+
"marker-mid",
59+
"marker-start",
60+
"markerHeight",
61+
"markerUnits",
62+
"markerWidth",
63+
"maskContentUnits",
64+
"maskUnits",
65+
"numOctaves",
66+
"overline-position",
67+
"overline-thickness",
68+
"panose-1",
69+
"paint-order",
70+
"pathLength",
71+
"patternContentUnits",
72+
"patternTransform",
73+
"patternUnits",
74+
"pointer-events",
75+
"pointsAtX",
76+
"pointsAtY",
77+
"pointsAtZ",
78+
"preserveAlpha",
79+
"preserveAspectRatio",
80+
"primitiveUnits",
81+
"referrerPolicy",
82+
"refX",
83+
"refY",
84+
"rendering-intent",
85+
"repeatCount",
86+
"repeatDur",
87+
"requiredExtensions",
88+
"requiredFeatures",
89+
"shape-rendering",
90+
"specularConstant",
91+
"specularExponent",
92+
"spreadMethod",
93+
"startOffset",
94+
"stdDeviation",
95+
"stitchTiles",
96+
"stop-color",
97+
"stop-opacity",
98+
"strikethrough-position",
99+
"strikethrough-thickness",
100+
"stroke-dasharray",
101+
"stroke-dashoffset",
102+
"stroke-linecap",
103+
"stroke-linejoin",
104+
"stroke-miterlimit",
105+
"stroke-opacity",
106+
"stroke-width",
107+
"surfaceScale",
108+
"systemLanguage",
109+
"tableValues",
110+
"targetX",
111+
"targetY",
112+
"text-anchor",
113+
"text-decoration",
114+
"text-rendering",
115+
"textLength",
116+
"transform-origin",
117+
"underline-position",
118+
"underline-thickness",
119+
"unicode-bidi",
120+
"unicode-range",
121+
"units-per-em",
122+
"v-alphabetic",
123+
"v-hanging",
124+
"v-ideographic",
125+
"v-mathematical",
126+
"vector-effect",
127+
"vert-adv-y",
128+
"vert-origin-x",
129+
"vert-origin-y",
130+
"viewBox",
131+
"viewTarget",
132+
"word-spacing",
133+
"writing-mode",
134+
"x-height",
135+
"xChannelSelector",
136+
"yChannelSelector",
137+
"zoomAndPan"
138+
]

0 commit comments

Comments
 (0)