Skip to content

Commit

Permalink
remove isCreateClass from components util
Browse files Browse the repository at this point in the history
  • Loading branch information
golopot committed Apr 19, 2022
1 parent e8ce9fe commit cbaf278
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 24 deletions.
3 changes: 1 addition & 2 deletions lib/rules/jsx-indent.js
Expand Up @@ -36,7 +36,6 @@ const astUtil = require('../util/ast');
const docsUrl = require('../util/docsUrl');
const reportC = require('../util/report');
const jsxUtil = require('../util/jsx');
const isCreateElement = require('../util/isCreateElement');

// ------------------------------------------------------------------------------
// Rule Definition
Expand Down Expand Up @@ -428,7 +427,7 @@ module.exports = {
}
if (
!fn
|| !jsxUtil.isReturningJSX((n) => isCreateElement(n, context), node, context, true)
|| !jsxUtil.isReturningJSX(node, context, true)
) {
return;
}
Expand Down
17 changes: 3 additions & 14 deletions lib/util/Components.js
Expand Up @@ -18,7 +18,6 @@ const jsxUtil = require('./jsx');
const usedPropTypesUtil = require('./usedPropTypes');
const defaultPropsUtil = require('./defaultProps');
const isFirstLetterCapitalized = require('./isFirstLetterCapitalized');
const isCreateElement = require('./isCreateElement');
const isDestructuredFromPragmaImport = require('./isDestructuredFromPragmaImport');

function getId(node) {
Expand Down Expand Up @@ -266,26 +265,16 @@ function componentRule(rule, context) {
return isDestructuredFromPragmaImport(variable, context);
},

/**
* Checks to see if node is called within createElement from pragma
*
* @param {ASTNode} node The AST node being checked.
* @returns {Boolean} True if createElement called from pragma
*/
isCreateElement(node) {
return isCreateElement(node, context);
},

isReturningJSX(ASTNode, strict) {
return jsxUtil.isReturningJSX(this.isCreateElement.bind(this), ASTNode, context, strict, true);
return jsxUtil.isReturningJSX(ASTNode, context, strict, true);
},

isReturningJSXOrNull(ASTNode, strict) {
return jsxUtil.isReturningJSX(this.isCreateElement.bind(this), ASTNode, context, strict);
return jsxUtil.isReturningJSX(ASTNode, context, strict);
},

isReturningOnlyNull(ASTNode) {
return jsxUtil.isReturningOnlyNull(this.isCreateElement.bind(this), ASTNode, context);
return jsxUtil.isReturningOnlyNull(ASTNode, context);
},

getPragmaComponentWrapper(node) {
Expand Down
11 changes: 4 additions & 7 deletions lib/util/jsx.js
Expand Up @@ -7,6 +7,7 @@
const elementType = require('jsx-ast-utils/elementType');

const astUtil = require('./ast');
const isCreateElement = require('./isCreateElement');
const variableUtil = require('./variable');

// See https://github.com/babel/babel/blob/ce420ba51c68591e057696ef43e028f41c6e04cd/packages/babel-types/src/validators/react/isCompatTag.js
Expand Down Expand Up @@ -85,15 +86,13 @@ function isWhiteSpaces(value) {
/**
* Check if the node is returning JSX or null
*
* @param {Function} isCreateElement Function to determine if a CallExpresion is
* a createElement one
* @param {ASTNode} ASTnode The AST node being checked
* @param {Context} context The context of `ASTNode`.
* @param {Boolean} [strict] If true, in a ternary condition the node must return JSX in both cases
* @param {Boolean} [ignoreNull] If true, null return values will be ignored
* @returns {Boolean} True if the node is returning JSX or null, false if not
*/
function isReturningJSX(isCreateElement, ASTnode, context, strict, ignoreNull) {
function isReturningJSX(ASTnode, context, strict, ignoreNull) {
const isJSXValue = (node) => {
if (!node) {
return false;
Expand All @@ -115,7 +114,7 @@ function isReturningJSX(isCreateElement, ASTnode, context, strict, ignoreNull) {
case 'JSXFragment':
return true;
case 'CallExpression':
return isCreateElement(node);
return isCreateElement(node, context);
case 'Literal':
if (!ignoreNull && node.value === null) {
return true;
Expand Down Expand Up @@ -144,13 +143,11 @@ function isReturningJSX(isCreateElement, ASTnode, context, strict, ignoreNull) {
/**
* Check if the node is returning only null values
*
* @param {Function} isCreateElement Function to determine if a CallExpresion is
* a createElement one
* @param {ASTNode} ASTnode The AST node being checked
* @param {Context} context The context of `ASTNode`.
* @returns {Boolean} True if the node is returning only null values
*/
function isReturningOnlyNull(isCreateElement, ASTnode, context) {
function isReturningOnlyNull(ASTnode, context) {
let found = false;
let foundSomethingElse = false;
astUtil.traverseReturns(ASTnode, context, (node) => {
Expand Down
2 changes: 1 addition & 1 deletion tests/util/jsx.js
Expand Up @@ -34,7 +34,7 @@ const mockContext = {
describe('jsxUtil', () => {
describe('isReturningJSX', () => {
const assertValid = (codeStr) => assert(
isReturningJSX(() => false, parseCode(codeStr), mockContext)
isReturningJSX(parseCode(codeStr), mockContext)
);

it('Works when returning JSX', () => {
Expand Down

0 comments on commit cbaf278

Please sign in to comment.