Skip to content

Use explicit comparisons instead of using Boolean constructor #2173

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 15, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/error/GraphQLError.js
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ export function GraphQLError( // eslint-disable-line no-redeclare
// By being enumerable, JSON.stringify will include `locations` in the
// resulting output. This ensures that the simplest possible GraphQL
// service adheres to the spec.
enumerable: Boolean(_locations),
enumerable: _locations != null,
},
path: {
// Coercing falsey values to undefined ensures they will not be included
Expand All @@ -166,7 +166,7 @@ export function GraphQLError( // eslint-disable-line no-redeclare
// By being enumerable, JSON.stringify will include `path` in the
// resulting output. This ensures that the simplest possible GraphQL
// service adheres to the spec.
enumerable: Boolean(path),
enumerable: path != null,
},
nodes: {
value: _nodes || undefined,
Expand All @@ -187,7 +187,7 @@ export function GraphQLError( // eslint-disable-line no-redeclare
// By being enumerable, JSON.stringify will include `path` in the
// resulting output. This ensures that the simplest possible GraphQL
// service adheres to the spec.
enumerable: Boolean(_extensions),
enumerable: _extensions != null,
},
});

Expand Down
2 changes: 1 addition & 1 deletion src/jsutils/isPromise.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@ declare function isPromise(value: mixed): boolean %checks(value instanceof

// eslint-disable-next-line no-redeclare
export default function isPromise(value) {
return Boolean(value && typeof value.then === 'function');
return value != null && typeof value.then === 'function';
}
2 changes: 1 addition & 1 deletion src/language/visitor.js
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,7 @@ export function visit(
}

function isNode(maybeNode): boolean %checks {
return Boolean(maybeNode && typeof maybeNode.kind === 'string');
return maybeNode != null && typeof maybeNode.kind === 'string';
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/type/schema.js
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ export class GraphQLSchema {
this._possibleTypeMap[abstractType.name] = map;
}

return Boolean(this._possibleTypeMap[abstractType.name][possibleType.name]);
return this._possibleTypeMap[abstractType.name][possibleType.name] != null;
}

getDirectives(): $ReadOnlyArray<GraphQLDirective> {
Expand Down
11 changes: 5 additions & 6 deletions src/validation/rules/KnownTypeNames.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export function KnownTypeNames(
const typeName = node.name.value;
if (!existingTypesMap[typeName] && !definedTypes[typeName]) {
const definitionNode = ancestors[2] || parent;
const isSDL = isSDLNode(definitionNode);
const isSDL = definitionNode != null && isSDLNode(definitionNode);
if (isSDL && isSpecifiedScalarName(typeName)) {
return;
}
Expand All @@ -73,10 +73,9 @@ function isSpecifiedScalarName(typeName) {
return specifiedScalarsNames.indexOf(typeName) !== -1;
}

function isSDLNode(value: ASTNode | $ReadOnlyArray<ASTNode> | void): boolean {
return Boolean(
value &&
!Array.isArray(value) &&
(isTypeSystemDefinitionNode(value) || isTypeSystemExtensionNode(value)),
function isSDLNode(value: ASTNode | $ReadOnlyArray<ASTNode>): boolean {
return (
!Array.isArray(value) &&
(isTypeSystemDefinitionNode(value) || isTypeSystemExtensionNode(value))
);
}