Skip to content

Commit

Permalink
[Refactor] use !! over Boolean()
Browse files Browse the repository at this point in the history
  • Loading branch information
ljharb committed Jul 22, 2024
1 parent a90aa6a commit 6421386
Show file tree
Hide file tree
Showing 8 changed files with 20 additions and 20 deletions.
2 changes: 1 addition & 1 deletion lib/rules/no-direct-mutation-state.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ module.exports = {
* @returns {Boolean} True if the component is valid, false if not.
*/
function isValid(component) {
return Boolean(component && !component.mutateSetState);
return !!component && !component.mutateSetState;
}

/**
Expand Down
2 changes: 1 addition & 1 deletion lib/rules/no-set-state.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ module.exports = {
* @returns {Boolean} True if the component is valid, false if not.
*/
function isValid(component) {
return Boolean(component && !component.useSetState);
return !!component && !component.useSetState;
}

/**
Expand Down
5 changes: 1 addition & 4 deletions lib/rules/no-unused-prop-types.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,7 @@ module.exports = {
* @returns {Boolean} True if the component must be validated, false if not.
*/
function mustBeValidated(component) {
return Boolean(
component
&& !component.ignoreUnusedPropTypesValidation
);
return !!component && !component.ignoreUnusedPropTypesValidation;
}

/**
Expand Down
9 changes: 3 additions & 6 deletions lib/rules/require-optimization.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,10 +104,7 @@ module.exports = {
* @returns {Boolean} True if we are declaring a shouldComponentUpdate method, false if not.
*/
function isSCUDeclared(node) {
return Boolean(
node
&& node.name === 'shouldComponentUpdate'
);
return !!node && node.name === 'shouldComponentUpdate';
}

/**
Expand All @@ -126,8 +123,8 @@ module.exports = {
}
}

return Boolean(
node
return (
!!node
&& node.key.name === 'mixins'
&& hasPR
);
Expand Down
7 changes: 5 additions & 2 deletions lib/rules/sort-prop-types.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,11 @@ function isRequiredProp(node) {
}

function isShapeProp(node) {
return Boolean(
node && node.callee && node.callee.property && node.callee.property.name === 'shape'
return !!(
node
&& node.callee
&& node.callee.property
&& node.callee.property.name === 'shape'
);
}

Expand Down
2 changes: 1 addition & 1 deletion lib/util/propTypes.js
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ module.exports = function propTypesInstructions(context, components, utils) {
ObjectTypeAnnotation(annotation, parentName, seen) {
let containsUnresolvedObjectTypeSpread = false;
let containsSpread = false;
const containsIndexers = Boolean(annotation.indexers && annotation.indexers.length);
const containsIndexers = !!annotation.indexers && annotation.indexers.length > 0;
const shapeTypeDefinition = {
type: 'shape',
children: {},
Expand Down
7 changes: 5 additions & 2 deletions lib/util/propTypesSort.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,11 @@ function isCallbackPropName(propName) {
* @returns {Boolean} true if the prop is PropTypes.shape.
*/
function isShapeProp(node) {
return Boolean(
node && node.callee && node.callee.property && node.callee.property.name === 'shape'
return !!(
node
&& node.callee
&& node.callee.property
&& node.callee.property.name === 'shape'
);
}

Expand Down
6 changes: 3 additions & 3 deletions tests/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ describe('all rule files should be exported by the plugin', () => {
describe('deprecated rules', () => {
it('marks all deprecated rules as deprecated', () => {
ruleFiles.forEach((ruleName) => {
const inDeprecatedRules = Boolean(plugin.deprecatedRules[ruleName]);
const inDeprecatedRules = !!plugin.deprecatedRules[ruleName];
const isDeprecated = plugin.rules[ruleName].meta.deprecated;
if (inDeprecatedRules) {
assert(isDeprecated, `${ruleName} metadata should mark it as deprecated`);
Expand Down Expand Up @@ -77,7 +77,7 @@ describe('configurations', () => {
});

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

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

0 comments on commit 6421386

Please sign in to comment.