Skip to content

Commit

Permalink
Return early, un-nest if statement
Browse files Browse the repository at this point in the history
  • Loading branch information
trevor-scheer committed Jul 23, 2019
1 parent c35f15b commit 561470f
Showing 1 changed file with 49 additions and 45 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -88,29 +88,31 @@ export function UniqueFieldDefinitionNames(
knownFieldNames[typeName] = Object.create(null);
}

if (node.fields) {
const fieldNames = knownFieldNames[typeName];

for (const fieldDef of node.fields) {
const fieldName = fieldDef.name.value;

if (hasField(existingTypeMap[typeName], fieldName)) {
context.reportError(
new GraphQLError(
existedFieldDefinitionNameMessage(typeName, fieldName),
fieldDef.name,
),
);
} else if (fieldNames[fieldName]) {
context.reportError(
new GraphQLError(
duplicateFieldDefinitionNameMessage(typeName, fieldName),
[fieldNames[fieldName], fieldDef.name],
),
);
} else {
fieldNames[fieldName] = fieldDef.name;
}
if (!node.fields) {
return false;
}

const fieldNames = knownFieldNames[typeName];

for (const fieldDef of node.fields) {
const fieldName = fieldDef.name.value;

if (hasField(existingTypeMap[typeName], fieldName)) {
context.reportError(
new GraphQLError(
existedFieldDefinitionNameMessage(typeName, fieldName),
fieldDef.name,
),
);
} else if (fieldNames[fieldName]) {
context.reportError(
new GraphQLError(
duplicateFieldDefinitionNameMessage(typeName, fieldName),
[fieldNames[fieldName], fieldDef.name],
),
);
} else {
fieldNames[fieldName] = fieldDef.name;
}
}

Expand Down Expand Up @@ -143,28 +145,30 @@ export function UniqueFieldDefinitionNames(
knownFieldNames[typeName] = Object.create(null);
}

if (node.fields) {
const fieldNames = knownFieldNames[typeName];

for (const fieldDef of node.fields) {
const fieldName = fieldDef.name.value;
if (hasField(existingTypeMap[typeName], fieldName)) {
context.reportError(
new GraphQLError(
existedFieldDefinitionNameMessage(typeName, fieldName),
fieldDef.name,
),
);
} else if (fieldNames[fieldName]) {
context.reportError(
new GraphQLError(
duplicateFieldDefinitionNameMessage(typeName, fieldName),
[fieldNames[fieldName], fieldDef.name],
),
);
} else {
fieldNames[fieldName] = fieldDef.name;
}
if (!node.fields) {
return false;
}

const fieldNames = knownFieldNames[typeName];

for (const fieldDef of node.fields) {
const fieldName = fieldDef.name.value;
if (hasField(existingTypeMap[typeName], fieldName)) {
context.reportError(
new GraphQLError(
existedFieldDefinitionNameMessage(typeName, fieldName),
fieldDef.name,
),
);
} else if (fieldNames[fieldName]) {
context.reportError(
new GraphQLError(
duplicateFieldDefinitionNameMessage(typeName, fieldName),
[fieldNames[fieldName], fieldDef.name],
),
);
} else {
fieldNames[fieldName] = fieldDef.name;
}
}

Expand Down

0 comments on commit 561470f

Please sign in to comment.