Skip to content

Commit d2dd7f0

Browse files
sjarvaljharb
authored andcommitted
[Refactor] no-unknown-property: update DOM properties to include also one word properties
Also regroup the properties to global, element specific and React or Safari/Apple specific
1 parent 84a9771 commit d2dd7f0

File tree

2 files changed

+40
-14
lines changed

2 files changed

+40
-14
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ This change log adheres to standards from [Keep a CHANGELOG](https://keepachange
1313
### Changed
1414
* [Docs] [`jsx-sort-props`]: replace ref string with ref variable ([#3375][] @Luccasoli)
1515
* [Refactor] [`no-unknown-property`]: improve jsdoc; extract logic to separate functions ([#3377][] @sjarva)
16+
* [Refactor] [`no-unknown-property`]: update DOM properties to include also one word properties ([#3377][] @sjarva)
1617

1718
[#3377]: https://github.com/jsx-eslint/eslint-plugin-react/pull/3377
1819
[#3376]: https://github.com/jsx-eslint/eslint-plugin-react/issues/3376

lib/rules/no-unknown-property.js

Lines changed: 39 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -116,23 +116,47 @@ const SVGDOM_ATTRIBUTE_NAMES = {
116116
'xml:space': 'xmlSpace',
117117
};
118118

119-
const DOM_PROPERTY_NAMES = [
120-
// Standard
121-
'acceptCharset', 'accessKey', 'allowFullScreen', 'autoComplete', 'autoFocus', 'autoPlay',
122-
'cellPadding', 'cellSpacing', 'classID', 'className', 'colSpan', 'contentEditable', 'contextMenu',
123-
'dateTime', 'encType', 'formAction', 'formEncType', 'formMethod', 'formNoValidate', 'formTarget',
124-
'frameBorder', 'hrefLang', 'htmlFor', 'httpEquiv', 'inputMode', 'keyParams', 'keyType', 'marginHeight', 'marginWidth',
119+
const DOM_PROPERTY_NAMES_ONE_WORD = [
120+
// Global attributes - can be used on any HTML/DOM element
121+
// See https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes
122+
'dir', 'draggable', 'hidden', 'id', 'lang', 'nonce', 'part', 'slot', 'style', 'title', 'translate',
123+
// Element specific attributes
124+
// See https://developer.mozilla.org/en-US/docs/Web/HTML/Attributes (includes global attributes too)
125+
// To be considered if these should be added also to ATTRIBUTE_TAGS_MAP
126+
'accept', 'action', 'allow', 'alt', 'async', 'buffered', 'capture', 'challenge', 'cite', 'code', 'cols',
127+
'content', 'coords', 'csp', 'data', 'decoding', 'default', 'defer', 'disabled', 'form',
128+
'headers', 'height', 'high', 'href', 'icon', 'importance', 'integrity', 'kind', 'label',
129+
'language', 'loading', 'list', 'loop', 'low', 'max', 'media', 'method', 'min', 'multiple', 'muted',
130+
'name', 'open', 'optimum', 'pattern', 'ping', 'placeholder', 'poster', 'preload', 'profile',
131+
'rel', 'required', 'reversed', 'role', 'rows', 'sandbox', 'scope', 'selected', 'shape', 'size', 'sizes',
132+
'span', 'src', 'start', 'step', 'target', 'type', 'value', 'width', 'wrap',
133+
// React specific attributes
134+
'ref',
135+
];
136+
137+
const DOM_PROPERTY_NAMES_TWO_WORDS = [
138+
// Global attributes - can be used on any HTML/DOM element
139+
// See https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes
140+
'accessKey', 'autoCapitalize', 'autoFocus', 'contentEditable', 'enterKeyHint', 'exportParts',
141+
'inputMode', 'itemID', 'itemRef', 'itemProp', 'itemScope', 'itemType', 'spellCheck', 'tabIndex',
142+
// Element specific attributes
143+
// See https://developer.mozilla.org/en-US/docs/Web/HTML/Attributes (includes global attributes too)
144+
// To be considered if these should be added also to ATTRIBUTE_TAGS_MAP
145+
'acceptCharset', 'allowFullScreen', 'autoComplete', 'autoPlay', 'cellPadding', 'cellSpacing', 'classID', 'codeBase',
146+
'colSpan', 'contextMenu', 'dateTime', 'encType', 'formAction', 'formEncType', 'formMethod', 'formNoValidate', 'formTarget',
147+
'frameBorder', 'hrefLang', 'httpEquiv', 'isMap', 'keyParams', 'keyType', 'marginHeight', 'marginWidth',
125148
'maxLength', 'mediaGroup', 'minLength', 'noValidate', 'onAnimationEnd', 'onAnimationIteration', 'onAnimationStart',
126149
'onBlur', 'onChange', 'onClick', 'onContextMenu', 'onCopy', 'onCompositionEnd', 'onCompositionStart',
127150
'onCompositionUpdate', 'onCut', 'onDoubleClick', 'onDrag', 'onDragEnd', 'onDragEnter', 'onDragExit', 'onDragLeave',
128151
'onError', 'onFocus', 'onInput', 'onKeyDown', 'onKeyPress', 'onKeyUp', 'onLoad', 'onWheel', 'onDragOver',
129152
'onDragStart', 'onDrop', 'onMouseDown', 'onMouseEnter', 'onMouseLeave', 'onMouseMove', 'onMouseOut', 'onMouseOver',
130-
'onMouseUp', 'onPaste', 'onScroll', 'onSelect', 'onSubmit', 'onTransitionEnd', 'radioGroup', 'readOnly', 'rowSpan',
131-
'spellCheck', 'srcDoc', 'srcLang', 'srcSet', 'tabIndex', 'useMap',
132-
// Non standard
133-
'autoCapitalize', 'autoCorrect',
134-
'autoSave',
135-
'itemProp', 'itemScope', 'itemType', 'itemRef', 'itemID',
153+
'onMouseUp', 'onPaste', 'onScroll', 'onSelect', 'onSubmit', 'onTransitionEnd', 'radioGroup', 'readOnly', 'referrerPolicy',
154+
'rowSpan', 'srcDoc', 'srcLang', 'srcSet', 'useMap',
155+
// Safari/Apple specific, no listing available
156+
'autoCorrect', // https://stackoverflow.com/questions/47985384/html-autocorrect-for-text-input-is-not-working
157+
'autoSave', // https://stackoverflow.com/questions/25456396/what-is-autosave-attribute-supposed-to-do-how-do-i-use-it
158+
// React specific attributes https://reactjs.org/docs/dom-elements.html#differences-in-attributes
159+
'className', 'dangerouslySetInnerHTML', 'defaultValue', 'htmlFor', 'onChange', 'suppressContentEditableWarning', 'suppressHydrationWarning',
136160
];
137161

138162
const DOM_PROPERTIES_IGNORE_CASE = ['charset'];
@@ -155,11 +179,12 @@ const ARIA_PROPERTIES = [
155179
];
156180

157181
function getDOMPropertyNames(context) {
182+
const ALL_DOM_PROPERTY_NAMES = DOM_PROPERTY_NAMES_TWO_WORDS.concat(DOM_PROPERTY_NAMES_ONE_WORD);
158183
// this was removed in React v16.1+, see https://github.com/facebook/react/pull/10823
159184
if (!testReactVersion(context, '>= 16.1.0')) {
160-
return ['allowTransparency'].concat(DOM_PROPERTY_NAMES);
185+
return ['allowTransparency'].concat(ALL_DOM_PROPERTY_NAMES);
161186
}
162-
return DOM_PROPERTY_NAMES;
187+
return ALL_DOM_PROPERTY_NAMES;
163188
}
164189

165190
// ------------------------------------------------------------------------------

0 commit comments

Comments
 (0)