Skip to content

Commit 22cedd8

Browse files
Mayoljharb
Mayo
authored andcommitted
[Fix] no-unknown-property: add SVG and meta properties
Fixes #3380
1 parent 512909b commit 22cedd8

File tree

3 files changed

+56
-1
lines changed

3 files changed

+56
-1
lines changed

CHANGELOG.md

+5
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,11 @@ This change log adheres to standards from [Keep a CHANGELOG](https://keepachange
55

66
## Unreleased
77

8+
### Fixed
9+
* [`no-unknown-property`]: add SVG and meta properties ([#3381][] @AhmadMayo)
10+
11+
[#3381]: https://github.com/jsx-eslint/eslint-plugin-react/pull/3381
12+
813
## [7.31.2] - 2022.09.02
914

1015
### Fixed

lib/rules/no-unknown-property.js

+48-1
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@ const DOM_ATTRIBUTE_NAMES = {
2929
const ATTRIBUTE_TAGS_MAP = {
3030
// image is required for SVG support, all other tags are HTML.
3131
crossOrigin: ['script', 'img', 'video', 'audio', 'link', 'image'],
32+
fill: ['svg'],
33+
property: ['meta'],
34+
viewBox: ['svg'],
3235
};
3336

3437
const SVGDOM_ATTRIBUTE_NAMES = {
@@ -130,8 +133,22 @@ const DOM_PROPERTY_NAMES_ONE_WORD = [
130133
'name', 'open', 'optimum', 'pattern', 'ping', 'placeholder', 'poster', 'preload', 'profile',
131134
'rel', 'required', 'reversed', 'role', 'rows', 'sandbox', 'scope', 'selected', 'shape', 'size', 'sizes',
132135
'span', 'src', 'start', 'step', 'target', 'type', 'value', 'width', 'wrap',
136+
// SVG attributes
137+
// See https://developer.mozilla.org/en-US/docs/Web/SVG/Attribute
138+
'accumulate', 'additive', 'alphabetic', 'amplitude', 'ascent', 'azimuth', 'bbox', 'begin',
139+
'bias', 'by', 'clip', 'color', 'cursor', 'cx', 'cy', 'd', 'decelerate', 'descent', 'direction',
140+
'display', 'divisor', 'dur', 'dx', 'dy', 'elevation', 'end', 'exponent', 'fill', 'filter',
141+
'format', 'from', 'fr', 'fx', 'fy', 'g1', 'g2', 'hanging', 'height', 'hreflang', 'ideographic',
142+
'in', 'in2', 'intercept', 'k', 'k1', 'k2', 'k3', 'k4', 'kerning', 'local', 'mask', 'mode',
143+
'offset', 'opacity', 'operator', 'order', 'orient', 'orientation', 'origin', 'overflow', 'path',
144+
'ping', 'points', 'r', 'radius', 'rel', 'restart', 'result', 'rotate', 'rx', 'ry', 'scale',
145+
'seed', 'slope', 'spacing', 'speed', 'stemh', 'stemv', 'string', 'stroke', 'to', 'transform',
146+
'u1', 'u2', 'unicode', 'values', 'version', 'visibility', 'widths', 'x', 'x1', 'x2', 'xmlns',
147+
'y', 'y1', 'y2', 'z',
148+
// OpenGraph meta tag attributes
149+
'property',
133150
// React specific attributes
134-
'ref',
151+
'ref', 'key',
135152
];
136153

137154
const DOM_PROPERTY_NAMES_TWO_WORDS = [
@@ -152,6 +169,36 @@ const DOM_PROPERTY_NAMES_TWO_WORDS = [
152169
'onDragStart', 'onDrop', 'onMouseDown', 'onMouseEnter', 'onMouseLeave', 'onMouseMove', 'onMouseOut', 'onMouseOver',
153170
'onMouseUp', 'onPaste', 'onScroll', 'onSelect', 'onSubmit', 'onTransitionEnd', 'radioGroup', 'readOnly', 'referrerPolicy',
154171
'rowSpan', 'srcDoc', 'srcLang', 'srcSet', 'useMap',
172+
// SVG attributes
173+
// See https://developer.mozilla.org/en-US/docs/Web/SVG/Attribute
174+
'crossOrigin', 'accentHeight', 'alignmentBaseline', 'arabicForm', 'attributeName',
175+
'attributeType', 'baseFrequency', 'baselineShift', 'baseProfile', 'calcMode', 'capHeight',
176+
'clipPathUnits', 'clipPath', 'clipRule', 'colorInterpolation', 'colorInterpolationFilters',
177+
'colorProfile', 'colorRendering', 'contentScriptType', 'contentStyleType', 'diffuseConstant',
178+
'dominantBaseline', 'edgeMode', 'enableBackground', 'fillOpacity', 'fillRule', 'filterRes',
179+
'filterUnits', 'floodColor', 'floodOpacity', 'fontFamily', 'fontSize', 'fontSizeAdjust',
180+
'fontStretch', 'fontStyle', 'fontVariant', 'fontWeight', 'glyphName',
181+
'glyphOrientationHorizontal', 'glyphOrientationVertical', 'glyphRef', 'gradientTransform',
182+
'gradientUnits', 'horizAdvX', 'horizOriginX', 'imageRendering', 'kernelMatrix',
183+
'kernelUnitLength', 'keyPoints', 'keySplines', 'keyTimes', 'lengthAdjust', 'letterSpacing',
184+
'lightingColor', 'limitingConeAngle', 'markerEnd', 'markerMid', 'markerStart', 'markerHeight',
185+
'markerUnits', 'markerWidth', 'maskContentUnits', 'maskUnits', 'mathematical', 'numOctaves',
186+
'overlinePosition', 'overlineThickness', 'panose1', 'paintOrder', 'pathLength',
187+
'patternContentUnits', 'patternTransform', 'patternUnits', 'pointerEvents', 'pointsAtX',
188+
'pointsAtY', 'pointsAtZ', 'preserveAlpha', 'preserveAspectRatio', 'primitiveUnits',
189+
'referrerPolicy', 'refX', 'refY', 'rendering-intent', 'repeatCount', 'repeatDur',
190+
'requiredExtensions', 'requiredFeatures', 'shapeRendering', 'specularConstant',
191+
'specularExponent', 'spreadMethod', 'startOffset', 'stdDeviation', 'stitchTiles', 'stopColor',
192+
'stopOpacity', 'strikethroughPosition', 'strikethroughThickness', 'strokeDasharray',
193+
'strokeDashoffset', 'strokeLinecap', 'strokeLinejoin', 'strokeMiterlimit', 'strokeOpacity',
194+
'strokeWidth', 'surfaceScale', 'systemLanguage', 'tableValues', 'targetX', 'targetY',
195+
'textAnchor', 'textDecoration', 'textRendering', 'textLength', 'transformOrigin',
196+
'underlinePosition', 'underlineThickness', 'unicodeBidi', 'unicodeRange', 'unitsPerEm',
197+
'vAlphabetic', 'vHanging', 'vIdeographic', 'vMathematical', 'vectorEffect', 'vertAdvY',
198+
'vertOriginX', 'vertOriginY', 'viewBox', 'viewTarget', 'wordSpacing', 'writingMode', 'xHeight',
199+
'xChannelSelector', 'xlinkActuate', 'xlinkArcrole', 'xlinkHref', 'xlinkRole', 'xlinkShow',
200+
'xlinkTitle', 'xlinkType', 'xmlBase', 'xmlLang', 'xmlnsXlink', 'xmlSpace', 'yChannelSelector',
201+
'zoomAndPan',
155202
// Safari/Apple specific, no listing available
156203
'autoCorrect', // https://stackoverflow.com/questions/47985384/html-autocorrect-for-text-input-is-not-working
157204
'autoSave', // https://stackoverflow.com/questions/25456396/what-is-autosave-attribute-supposed-to-do-how-do-i-use-it

tests/lib/rules/no-unknown-property.js

+3
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,10 @@ ruleTester.run('no-unknown-property', rule, {
4848
{ code: '<img src="cat_keyboard.jpeg" alt="A cat sleeping on a keyboard" />' },
4949
{ code: '<input type="password" required />' },
5050
{ code: '<input ref={this.input} type="radio" />' },
51+
{ code: '<input key="bar" type="radio" />' },
5152
{ code: '<button disabled>You cannot click me</button>;' },
53+
{ code: '<svg key="lock" viewBox="box" fill={10} d="d" stroke={1} strokeWidth={2} strokeLinecap={3} strokeLinejoin={4} transform="something" clipRule="else" x1={5} x2="6" y1="7" y2="8"></svg>' },
54+
{ code: '<meta property="og:type" content="website" />' },
5255
// Case ignored attributes, for `charset` discussion see https://github.com/jsx-eslint/eslint-plugin-react/pull/1863
5356
{ code: '<meta charset="utf-8" />;' },
5457
{ code: '<meta charSet="utf-8" />;' },

0 commit comments

Comments
 (0)