Skip to content

Commit aa96591

Browse files
committed
Remove unnecessary type narrowing
1 parent 4161d14 commit aa96591

File tree

3 files changed

+7
-23
lines changed

3 files changed

+7
-23
lines changed

lib/rules/button-has-type.js

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -136,9 +136,6 @@ module.exports = {
136136
checkValue(node, propValue);
137137
},
138138
CallExpression(node) {
139-
if (node.type !== 'CallExpression') {
140-
return;
141-
}
142139
if (!isCreateElement(node, context) || node.arguments.length < 1) {
143140
return;
144141
}

lib/rules/no-deprecated.js

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,7 @@ module.exports = {
236236

237237
VariableDeclarator(node) {
238238
const reactModuleName = getReactModuleName(node);
239+
const objectPatternNodeId = node.id.type === 'ObjectPattern' ? node.id : undefined;
239240
const isRequire = node.init.type === 'CallExpression'
240241
&& node.init.callee && node.init.callee.type === 'Identifier'
241242
&& node.init.callee.name === 'require';
@@ -244,18 +245,15 @@ module.exports = {
244245
&& node.init.arguments.length
245246
&& node.init.arguments[0].type === 'Literal'
246247
&& typeof MODULES[node.init.arguments[0].value] !== 'undefined';
247-
const isDestructuring = node.id && node.id.type === 'ObjectPattern';
248248

249249
if (
250-
!(isDestructuring && reactModuleName)
251-
&& !(isDestructuring && isRequire && isReactRequire)
250+
!(objectPatternNodeId && reactModuleName)
251+
&& !(objectPatternNodeId && isRequire && isReactRequire)
252252
) {
253253
return;
254254
}
255-
if (node.id.type !== 'ObjectPattern') {
256-
return;
257-
}
258-
node.id.properties.filter((p) => p.type !== 'RestElement' && p.key).forEach((property) => {
255+
256+
objectPatternNodeId.properties.forEach((property) => {
259257
if (property.type !== 'Property' || property.key.type !== 'Identifier') {
260258
return;
261259
}

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

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -105,10 +105,6 @@ module.exports = {
105105
},
106106

107107
CallExpression(node) {
108-
if (node.callee.type !== 'MemberExpression' && node.callee.type !== 'Identifier') {
109-
return;
110-
}
111-
112108
if (!isCreateElement(node, context)) {
113109
return;
114110
}
@@ -120,11 +116,7 @@ module.exports = {
120116
return;
121117
}
122118

123-
if (args[0].type !== 'Literal') {
124-
return;
125-
}
126-
127-
const elementName = args[0].value;
119+
const elementName = args[0].type === 'Literal' ? args[0].value : undefined;
128120

129121
if (!isVoidDOMElement(elementName)) {
130122
// e.g. React.createElement('div');
@@ -149,10 +141,7 @@ module.exports = {
149141
const props = args[1].properties;
150142

151143
const hasChildrenPropOrDanger = props.some((prop) => {
152-
if (prop.type !== 'Property') {
153-
return false;
154-
}
155-
if (!prop.key || prop.key.type !== 'Identifier') {
144+
if (prop.type !== 'Property' || prop.key.type !== 'Identifier') {
156145
return false;
157146
}
158147

0 commit comments

Comments
 (0)