Skip to content

Commit

Permalink
Make an exception for some SVG attributes in vue/attribute-hyphenation (
Browse files Browse the repository at this point in the history
#1484)

* Closes issue #1483

* linting

Co-authored-by: Raphaël Gaudy <rga@systerel.fr>
  • Loading branch information
rgaudy and Raphaël Gaudy committed May 29, 2021
1 parent 793112d commit 3da8d31
Show file tree
Hide file tree
Showing 3 changed files with 146 additions and 4 deletions.
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"
]

0 comments on commit 3da8d31

Please sign in to comment.