Skip to content

Commit 36d6089

Browse files
committed
Use the pragma setting instead of React
1 parent 341bb4f commit 36d6089

File tree

2 files changed

+19
-19
lines changed

2 files changed

+19
-19
lines changed

lib/rules/void-dom-elements-no-children.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ module.exports = {
9999
return;
100100
}
101101

102-
if (!utils.isReactCreateElement(node)) {
102+
if (!utils.isPragmaCreateElement(node)) {
103103
return;
104104
}
105105

lib/util/Components.js

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -255,33 +255,33 @@ function componentRule(rule, context) {
255255
},
256256

257257
/**
258-
* Check if variable is destructured from React import
258+
* Check if variable is destructured from pragma import
259259
*
260260
* @param {variable} String The variable name to check
261-
* @returns {Boolean} True if createElement is destructured from React
261+
* @returns {Boolean} True if createElement is destructured from the pragma
262262
*/
263-
isDestructuredFromReactImport: function(variable) {
263+
isDestructuredFromPragmaImport: function(variable) {
264264
const variables = variableUtil.variablesInScope(context);
265265
const variableInScope = variableUtil.getVariable(variables, variable);
266266
if (variableInScope) {
267267
const map = variableInScope.scope.set;
268-
return map.has('React');
268+
return map.has(pragma);
269269
}
270270
return false;
271271
},
272272

273273
/**
274-
* Checks to see if node is called within React.createElement
274+
* Checks to see if node is called within createElement from pragma
275275
*
276276
* @param {ASTNode} node The AST node being checked.
277-
* @returns {Boolean} True if React.createElement called
277+
* @returns {Boolean} True if createElement called from pragma
278278
*/
279-
isReactCreateElement: function(node) {
280-
const calledOnReact = (
279+
isPragmaCreateElement: function(node) {
280+
const calledOnPragma = (
281281
node &&
282282
node.callee &&
283283
node.callee.object &&
284-
node.callee.object.name === 'React' &&
284+
node.callee.object.name === pragma &&
285285
node.callee.property &&
286286
node.callee.property.name === 'createElement'
287287
);
@@ -292,10 +292,10 @@ function componentRule(rule, context) {
292292
node.callee.name === 'createElement'
293293
);
294294

295-
if (this.isDestructuredFromReactImport('createElement')) {
296-
return calledDirectly || calledOnReact;
295+
if (this.isDestructuredFromPragmaImport('createElement')) {
296+
return calledDirectly || calledOnPragma;
297297
}
298-
return calledOnReact;
298+
return calledOnPragma;
299299
},
300300

301301
getReturnPropertyAndNode(ASTnode) {
@@ -357,12 +357,12 @@ function componentRule(rule, context) {
357357
node[property] &&
358358
jsxUtil.isJSX(node[property])
359359
;
360-
const returnsReactCreateElement = this.isReactCreateElement(node[property]);
360+
const returnsPragmaCreateElement = this.isPragmaCreateElement(node[property]);
361361

362362
return Boolean(
363363
returnsConditionalJSX ||
364364
returnsJSX ||
365-
returnsReactCreateElement
365+
returnsPragmaCreateElement
366366
);
367367
},
368368

@@ -395,16 +395,16 @@ function componentRule(rule, context) {
395395
return utils.isReturningJSX(ASTNode, strict) || utils.isReturningNull(ASTNode);
396396
},
397397

398-
isReactComponentWrapper(node) {
398+
isPragmaComponentWrapper(node) {
399399
if (node.type !== 'CallExpression') {
400400
return false;
401401
}
402402
const propertyNames = ['forwardRef', 'memo'];
403403
const calleeObject = node.callee.object;
404404
if (calleeObject) {
405-
return arrayIncludes(propertyNames, node.callee.property.name) && node.callee.object.name === 'React';
405+
return arrayIncludes(propertyNames, node.callee.property.name) && node.callee.object.name === pragma;
406406
}
407-
return arrayIncludes(propertyNames, node.callee.name) && this.isDestructuredFromReactImport(node.callee.name);
407+
return arrayIncludes(propertyNames, node.callee.name) && this.isDestructuredFromPragmaImport(node.callee.name);
408408
},
409409

410410
/**
@@ -476,7 +476,7 @@ function componentRule(rule, context) {
476476
const enclosingScopeParent = enclosingScope && enclosingScope.block.parent;
477477
const isClass = enclosingScope && astUtil.isClass(enclosingScope.block);
478478
const isMethod = enclosingScopeParent && enclosingScopeParent.type === 'MethodDefinition'; // Classes methods
479-
const isArgument = node.parent && node.parent.type === 'CallExpression' && !this.isReactComponentWrapper(node.parent); // Arguments (callback, etc.)
479+
const isArgument = node.parent && node.parent.type === 'CallExpression' && !this.isPragmaComponentWrapper(node.parent); // Arguments (callback, etc.)
480480
// Attribute Expressions inside JSX Elements (<button onClick={() => props.handleClick()}></button>)
481481
const isJSXExpressionContainer = node.parent && node.parent.type === 'JSXExpressionContainer';
482482
// Stop moving up if we reach a class or an argument (like a callback)

0 commit comments

Comments
 (0)