Skip to content

Commit 6421386

Browse files
committed
[Refactor] use !! over Boolean()
1 parent a90aa6a commit 6421386

8 files changed

+20
-20
lines changed

lib/rules/no-direct-mutation-state.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ module.exports = {
4141
* @returns {Boolean} True if the component is valid, false if not.
4242
*/
4343
function isValid(component) {
44-
return Boolean(component && !component.mutateSetState);
44+
return !!component && !component.mutateSetState;
4545
}
4646

4747
/**

lib/rules/no-set-state.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ module.exports = {
4141
* @returns {Boolean} True if the component is valid, false if not.
4242
*/
4343
function isValid(component) {
44-
return Boolean(component && !component.useSetState);
44+
return !!component && !component.useSetState;
4545
}
4646

4747
/**

lib/rules/no-unused-prop-types.js

+1-4
Original file line numberDiff line numberDiff line change
@@ -77,10 +77,7 @@ module.exports = {
7777
* @returns {Boolean} True if the component must be validated, false if not.
7878
*/
7979
function mustBeValidated(component) {
80-
return Boolean(
81-
component
82-
&& !component.ignoreUnusedPropTypesValidation
83-
);
80+
return !!component && !component.ignoreUnusedPropTypesValidation;
8481
}
8582

8683
/**

lib/rules/require-optimization.js

+3-6
Original file line numberDiff line numberDiff line change
@@ -104,10 +104,7 @@ module.exports = {
104104
* @returns {Boolean} True if we are declaring a shouldComponentUpdate method, false if not.
105105
*/
106106
function isSCUDeclared(node) {
107-
return Boolean(
108-
node
109-
&& node.name === 'shouldComponentUpdate'
110-
);
107+
return !!node && node.name === 'shouldComponentUpdate';
111108
}
112109

113110
/**
@@ -126,8 +123,8 @@ module.exports = {
126123
}
127124
}
128125

129-
return Boolean(
130-
node
126+
return (
127+
!!node
131128
&& node.key.name === 'mixins'
132129
&& hasPR
133130
);

lib/rules/sort-prop-types.js

+5-2
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,11 @@ function isRequiredProp(node) {
4848
}
4949

5050
function isShapeProp(node) {
51-
return Boolean(
52-
node && node.callee && node.callee.property && node.callee.property.name === 'shape'
51+
return !!(
52+
node
53+
&& node.callee
54+
&& node.callee.property
55+
&& node.callee.property.name === 'shape'
5356
);
5457
}
5558

lib/util/propTypes.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ module.exports = function propTypesInstructions(context, components, utils) {
172172
ObjectTypeAnnotation(annotation, parentName, seen) {
173173
let containsUnresolvedObjectTypeSpread = false;
174174
let containsSpread = false;
175-
const containsIndexers = Boolean(annotation.indexers && annotation.indexers.length);
175+
const containsIndexers = !!annotation.indexers && annotation.indexers.length > 0;
176176
const shapeTypeDefinition = {
177177
type: 'shape',
178178
children: {},

lib/util/propTypesSort.js

+5-2
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,11 @@ function isCallbackPropName(propName) {
4949
* @returns {Boolean} true if the prop is PropTypes.shape.
5050
*/
5151
function isShapeProp(node) {
52-
return Boolean(
53-
node && node.callee && node.callee.property && node.callee.property.name === 'shape'
52+
return !!(
53+
node
54+
&& node.callee
55+
&& node.callee.property
56+
&& node.callee.property.name === 'shape'
5457
);
5558
}
5659

tests/index.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ describe('all rule files should be exported by the plugin', () => {
3434
describe('deprecated rules', () => {
3535
it('marks all deprecated rules as deprecated', () => {
3636
ruleFiles.forEach((ruleName) => {
37-
const inDeprecatedRules = Boolean(plugin.deprecatedRules[ruleName]);
37+
const inDeprecatedRules = !!plugin.deprecatedRules[ruleName];
3838
const isDeprecated = plugin.rules[ruleName].meta.deprecated;
3939
if (inDeprecatedRules) {
4040
assert(isDeprecated, `${ruleName} metadata should mark it as deprecated`);
@@ -77,7 +77,7 @@ describe('configurations', () => {
7777
});
7878

7979
ruleFiles.forEach((ruleName) => {
80-
const inDeprecatedRules = Boolean(plugin.deprecatedRules[ruleName]);
80+
const inDeprecatedRules = !!plugin.deprecatedRules[ruleName];
8181
const inConfig = typeof plugin.configs[configName].rules[`react/${ruleName}`] !== 'undefined';
8282
assert(inDeprecatedRules ^ inConfig); // eslint-disable-line no-bitwise
8383
});
@@ -91,7 +91,7 @@ describe('configurations', () => {
9191
assert.ok(ruleName.startsWith('react/'));
9292
assert.equal(plugin.configs[configName].rules[ruleName], 0);
9393

94-
const inDeprecatedRules = Boolean(plugin.deprecatedRules[ruleName]);
94+
const inDeprecatedRules = !!plugin.deprecatedRules[ruleName];
9595
const inConfig = typeof plugin.configs[configName].rules[ruleName] !== 'undefined';
9696
assert(inDeprecatedRules ^ inConfig); // eslint-disable-line no-bitwise
9797
});

0 commit comments

Comments
 (0)