Skip to content

Commit fd3cebb

Browse files
dawidvdhljharb
authored andcommitted
[Fix] no-unknown-property: allowTransparency does not exist in React >= v16.1
1 parent 0f8d790 commit fd3cebb

File tree

2 files changed

+16
-6
lines changed

2 files changed

+16
-6
lines changed

lib/rules/no-unknown-property.js

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
'use strict';
77

88
const docsUrl = require('../util/docsUrl');
9+
const versionUtil = require('../util/version');
910

1011
// ------------------------------------------------------------------------------
1112
// Constants
@@ -117,7 +118,7 @@ const SVGDOM_ATTRIBUTE_NAMES = {
117118

118119
const DOM_PROPERTY_NAMES = [
119120
// Standard
120-
'acceptCharset', 'accessKey', 'allowFullScreen', 'allowTransparency', 'autoComplete', 'autoFocus', 'autoPlay',
121+
'acceptCharset', 'accessKey', 'allowFullScreen', 'autoComplete', 'autoFocus', 'autoPlay',
121122
'cellPadding', 'cellSpacing', 'classID', 'className', 'colSpan', 'contentEditable', 'contextMenu',
122123
'dateTime', 'encType', 'formAction', 'formEncType', 'formMethod', 'formNoValidate', 'formTarget',
123124
'frameBorder', 'hrefLang', 'htmlFor', 'httpEquiv', 'inputMode', 'keyParams', 'keyType', 'marginHeight', 'marginWidth',
@@ -133,6 +134,13 @@ const DOM_PROPERTY_NAMES = [
133134
'autoSave',
134135
'itemProp', 'itemScope', 'itemType', 'itemRef', 'itemID'
135136
];
137+
function getDOMPropertyNames(context) {
138+
// this was removed in React v16.1+, see https://github.com/facebook/react/pull/10823
139+
if (!versionUtil.testReactVersion(context, '16.1.0')) {
140+
return ['allowTransparency'].concat(DOM_PROPERTY_NAMES);
141+
}
142+
return DOM_PROPERTY_NAMES;
143+
}
136144

137145
// ------------------------------------------------------------------------------
138146
// Helpers
@@ -185,21 +193,23 @@ function tagNameHasDot(node) {
185193
/**
186194
* Get the standard name of the attribute.
187195
* @param {String} name - Name of the attribute.
196+
* @param {String} context - eslint context
188197
* @returns {String} The standard name of the attribute.
189198
*/
190-
function getStandardName(name) {
199+
function getStandardName(name, context) {
191200
if (DOM_ATTRIBUTE_NAMES[name]) {
192201
return DOM_ATTRIBUTE_NAMES[name];
193202
}
194203
if (SVGDOM_ATTRIBUTE_NAMES[name]) {
195204
return SVGDOM_ATTRIBUTE_NAMES[name];
196205
}
197206
let i = -1;
198-
const found = DOM_PROPERTY_NAMES.some((element, index) => {
207+
const names = getDOMPropertyNames(context);
208+
const found = names.some((element, index) => {
199209
i = index;
200210
return element.toLowerCase() === name;
201211
});
202-
return found ? DOM_PROPERTY_NAMES[i] : null;
212+
return found ? names[i] : null;
203213
}
204214

205215
// ------------------------------------------------------------------------------
@@ -262,7 +272,7 @@ module.exports = {
262272
});
263273
}
264274

265-
const standardName = getStandardName(name);
275+
const standardName = getStandardName(name, context);
266276
if (!isTagName(node) || !standardName) {
267277
return;
268278
}

lib/util/version.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ function detectReactVersion() {
3535
function getReactVersionFromContext(context) {
3636
let confVer = '999.999.999';
3737
// .eslintrc shared settings (http://eslint.org/docs/user-guide/configuring#adding-shared-settings)
38-
if (context.settings.react && context.settings.react.version) {
38+
if (context.settings && context.settings.react && context.settings.react.version) {
3939
let settingsVersion = context.settings.react.version;
4040
if (settingsVersion === 'detect') {
4141
settingsVersion = detectReactVersion();

0 commit comments

Comments
 (0)