Skip to content

Commit 725d4c7

Browse files
committed
Move isCreateContext to seperate file
1 parent 6373941 commit 725d4c7

File tree

2 files changed

+54
-52
lines changed

2 files changed

+54
-52
lines changed

lib/rules/display-name.js

Lines changed: 1 addition & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
const values = require('object.values');
99

1010
const Components = require('../util/Components');
11+
const isCreateContext = require('../util/isCreateContext');
1112
const astUtil = require('../util/ast');
1213
const componentUtil = require('../util/componentUtil');
1314
const docsUrl = require('../util/docsUrl');
@@ -77,58 +78,6 @@ module.exports = {
7778
return node.type === 'CallExpression' && argumentIsCallExpression && utils.isPragmaComponentWrapper(node);
7879
}
7980

80-
/**
81-
* Checks if the node is a React.createContext call
82-
* @param {ASTNode} node - The AST node being checked.
83-
* @returns {Boolean} - True if node is a React.createContext call, false if not.
84-
*/
85-
function isCreateContext(node) {
86-
if (
87-
node.init
88-
&& node.init.type === 'CallExpression'
89-
&& node.init.callee
90-
&& node.init.callee.name === 'createContext'
91-
) {
92-
return true;
93-
}
94-
95-
if (
96-
node.init
97-
&& node.init.callee
98-
&& node.init.callee.type === 'MemberExpression'
99-
&& node.init.callee.property
100-
&& node.init.callee.property.name === 'createContext'
101-
) {
102-
return true;
103-
}
104-
105-
if (
106-
node.expression
107-
&& node.expression.type === 'AssignmentExpression'
108-
&& node.expression.operator === '='
109-
&& node.expression.right.type === 'CallExpression'
110-
&& node.expression.right.callee
111-
&& node.expression.right.callee.name === 'createContext'
112-
) {
113-
return true;
114-
}
115-
116-
if (
117-
node.expression
118-
&& node.expression.type === 'AssignmentExpression'
119-
&& node.expression.operator === '='
120-
&& node.expression.right.type === 'CallExpression'
121-
&& node.expression.right.callee
122-
&& node.expression.right.callee.type === 'MemberExpression'
123-
&& node.expression.right.callee.property
124-
&& node.expression.right.callee.property.name === 'createContext'
125-
) {
126-
return true;
127-
}
128-
129-
return false;
130-
}
131-
13281
/**
13382
* Reports missing display name for a given component
13483
* @param {Object} component The component to process

lib/util/isCreateContext.js

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
'use strict';
2+
3+
/**
4+
* Checks if the node is a React.createContext call
5+
* @param {ASTNode} node - The AST node being checked.
6+
* @returns {Boolean} - True if node is a React.createContext call, false if not.
7+
*/
8+
module.exports = function isCreateContext(node) {
9+
if (
10+
node.init
11+
&& node.init.type === 'CallExpression'
12+
&& node.init.callee
13+
&& node.init.callee.name === 'createContext'
14+
) {
15+
return true;
16+
}
17+
18+
if (
19+
node.init
20+
&& node.init.callee
21+
&& node.init.callee.type === 'MemberExpression'
22+
&& node.init.callee.property
23+
&& node.init.callee.property.name === 'createContext'
24+
) {
25+
return true;
26+
}
27+
28+
if (
29+
node.expression
30+
&& node.expression.type === 'AssignmentExpression'
31+
&& node.expression.operator === '='
32+
&& node.expression.right.type === 'CallExpression'
33+
&& node.expression.right.callee
34+
&& node.expression.right.callee.name === 'createContext'
35+
) {
36+
return true;
37+
}
38+
39+
if (
40+
node.expression
41+
&& node.expression.type === 'AssignmentExpression'
42+
&& node.expression.operator === '='
43+
&& node.expression.right.type === 'CallExpression'
44+
&& node.expression.right.callee
45+
&& node.expression.right.callee.type === 'MemberExpression'
46+
&& node.expression.right.callee.property
47+
&& node.expression.right.callee.property.name === 'createContext'
48+
) {
49+
return true;
50+
}
51+
52+
return false;
53+
};

0 commit comments

Comments
 (0)