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

Make an exception for some SVG attributes in vue/attribute-hyphenation #1484

Merged
merged 2 commits into from May 29, 2021
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: 4 additions & 3 deletions docs/rules/attribute-hyphenation.md
Expand Up @@ -40,10 +40,11 @@ This rule enforces using hyphenated attribute names on custom components in Vue
}
```

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

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

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

### `"never"`

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

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

Expand Down
5 changes: 4 additions & 1 deletion lib/rules/attribute-hyphenation.js
Expand Up @@ -6,6 +6,7 @@

const utils = require('../utils')
const casing = require('../utils/casing')
const svgAttributes = require('../utils/svg-attributes-weird-case.json')

// ------------------------------------------------------------------------------
// Rule Definition
Expand Down Expand Up @@ -51,7 +52,9 @@ module.exports = {
const option = context.options[0]
const optionsPayload = context.options[1]
const useHyphenated = option !== 'never'
let ignoredAttributes = ['data-', 'aria-', 'slot-scope']
let ignoredAttributes = ['data-', 'aria-', 'slot-scope'].concat(
svgAttributes
)

if (optionsPayload && optionsPayload.ignore) {
ignoredAttributes = ignoredAttributes.concat(optionsPayload.ignore)
Expand Down
138 changes: 138 additions & 0 deletions lib/utils/svg-attributes-weird-case.json
@@ -0,0 +1,138 @@
[
"accent-height",
"alignment-baseline",
"arabic-form",
"attributeName",
"attributeType",
"baseFrequency",
"baseline-shift",
"baseProfile",
"calcMode",
"cap-height",
"clipPathUnits",
"clip-path",
"clip-rule",
"color-interpolation",
"color-interpolation-filters",
"color-profile",
"color-rendering",
"contentScriptType",
"contentStyleType",
"diffuseConstant",
"dominant-baseline",
"edgeMode",
"enable-background",
"externalResourcesRequired",
"fill-opacity",
"fill-rule",
"filterRes",
"filterUnits",
"flood-color",
"flood-opacity",
"font-family",
"font-size",
"font-size-adjust",
"font-stretch",
"font-style",
"font-variant",
"font-weight",
"glyph-name",
"glyph-orientation-horizontal",
"glyph-orientation-vertical",
"glyphRef",
"gradientTransform",
"gradientUnits",
"horiz-adv-x",
"horiz-origin-x",
"image-rendering",
"kernelMatrix",
"kernelUnitLength",
"keyPoints",
"keySplines",
"keyTimes",
"lengthAdjust",
"letter-spacing",
"lighting-color",
"limitingConeAngle",
"marker-end",
"marker-mid",
"marker-start",
"markerHeight",
"markerUnits",
"markerWidth",
"maskContentUnits",
"maskUnits",
"numOctaves",
"overline-position",
"overline-thickness",
"panose-1",
"paint-order",
"pathLength",
"patternContentUnits",
"patternTransform",
"patternUnits",
"pointer-events",
"pointsAtX",
"pointsAtY",
"pointsAtZ",
"preserveAlpha",
"preserveAspectRatio",
"primitiveUnits",
"referrerPolicy",
"refX",
"refY",
"rendering-intent",
"repeatCount",
"repeatDur",
"requiredExtensions",
"requiredFeatures",
"shape-rendering",
"specularConstant",
"specularExponent",
"spreadMethod",
"startOffset",
"stdDeviation",
"stitchTiles",
"stop-color",
"stop-opacity",
"strikethrough-position",
"strikethrough-thickness",
"stroke-dasharray",
"stroke-dashoffset",
"stroke-linecap",
"stroke-linejoin",
"stroke-miterlimit",
"stroke-opacity",
"stroke-width",
"surfaceScale",
"systemLanguage",
"tableValues",
"targetX",
"targetY",
"text-anchor",
"text-decoration",
"text-rendering",
"textLength",
"transform-origin",
"underline-position",
"underline-thickness",
"unicode-bidi",
"unicode-range",
"units-per-em",
"v-alphabetic",
"v-hanging",
"v-ideographic",
"v-mathematical",
"vector-effect",
"vert-adv-y",
"vert-origin-x",
"vert-origin-y",
"viewBox",
"viewTarget",
"word-spacing",
"writing-mode",
"x-height",
"xChannelSelector",
"yChannelSelector",
"zoomAndPan"
]