Skip to content

Commit 552cb20

Browse files
committed
flow: Enable 'uninitialized-instance-property' lint
1 parent e6725de commit 552cb20

File tree

4 files changed

+19
-24
lines changed

4 files changed

+19
-24
lines changed

.flowconfig

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ implicit-inexact-object=error
2828
unnecessary-optional-chain=error
2929
unnecessary-invariant=off
3030
signature-verification-failure=error
31-
uninitialized-instance-property=off
31+
uninitialized-instance-property=error
3232
non-array-spread=error
3333

3434
[options]

src/language/parser.js

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// @flow strict
22

33
import inspect from '../jsutils/inspect';
4+
import invariant from '../jsutils/invariant';
45
import defineToJSON from '../jsutils/defineToJSON';
56
import { Source } from './source';
67
import { type GraphQLError } from '../error/GraphQLError';
@@ -171,11 +172,10 @@ class Parser {
171172

172173
constructor(source: string | Source, options?: ParseOptions) {
173174
const sourceObj = typeof source === 'string' ? new Source(source) : source;
174-
if (!(sourceObj instanceof Source)) {
175-
throw new TypeError(
176-
`Must provide Source. Received: ${inspect(sourceObj)}`,
177-
);
178-
}
175+
invariant(
176+
sourceObj instanceof Source,
177+
`Must provide Source. Received: ${inspect(sourceObj)}`,
178+
);
179179

180180
this._lexer = createLexer(sourceObj);
181181
this._options = options || {};

src/type/definition.js

+8-8
Original file line numberDiff line numberDiff line change
@@ -555,13 +555,13 @@ export class GraphQLScalarType {
555555
extensionASTNodes: ?$ReadOnlyArray<ScalarTypeExtensionNode>;
556556

557557
constructor(config: GraphQLScalarTypeConfig<*, *>): void {
558+
const parseValue = config.parseValue || identityFunc;
558559
this.name = config.name;
559560
this.description = config.description;
560561
this.serialize = config.serialize || identityFunc;
561-
this.parseValue = config.parseValue || identityFunc;
562+
this.parseValue = parseValue;
562563
this.parseLiteral =
563-
config.parseLiteral ||
564-
(node => this.parseValue(valueFromASTUntyped(node)));
564+
config.parseLiteral || (node => parseValue(valueFromASTUntyped(node)))
565565

566566
this.astNode = config.astNode;
567567
this.extensionASTNodes = undefineIfEmpty(config.extensionASTNodes);
@@ -1155,7 +1155,7 @@ export class GraphQLEnumType /* <T> */ {
11551155
this.description = config.description;
11561156
this.astNode = config.astNode;
11571157
this.extensionASTNodes = undefineIfEmpty(config.extensionASTNodes);
1158-
this._values = defineEnumValues(this, config.values);
1158+
this._values = defineEnumValues(this.name, config.values);
11591159
this._valueLookup = new Map(
11601160
this._values.map(enumValue => [enumValue.value, enumValue]),
11611161
);
@@ -1232,22 +1232,22 @@ defineToStringTag(GraphQLEnumType);
12321232
defineToJSON(GraphQLEnumType);
12331233

12341234
function defineEnumValues(
1235-
type: GraphQLEnumType,
1235+
typeName: string,
12361236
valueMap: GraphQLEnumValueConfigMap /* <T> */,
12371237
): Array<GraphQLEnumValue /* <T> */> {
12381238
invariant(
12391239
isPlainObj(valueMap),
1240-
`${type.name} values must be an object with value names as keys.`,
1240+
`${typeName} values must be an object with value names as keys.`,
12411241
);
12421242
return objectEntries(valueMap).map(([valueName, value]) => {
12431243
invariant(
12441244
isPlainObj(value),
1245-
`${type.name}.${valueName} must refer to an object with a "value" key ` +
1245+
`${typeName}.${valueName} must refer to an object with a "value" key ` +
12461246
`representing an internal value but got: ${inspect(value)}.`,
12471247
);
12481248
invariant(
12491249
!('isDeprecated' in value),
1250-
`${type.name}.${valueName} should provide "deprecationReason" instead of "isDeprecated".`,
1250+
`${typeName}.${valueName} should provide "deprecationReason" instead of "isDeprecated".`,
12511251
);
12521252
return {
12531253
name: valueName,

src/type/schema.js

+5-10
Original file line numberDiff line numberDiff line change
@@ -165,17 +165,12 @@ export class GraphQLSchema {
165165
this.extensionASTNodes = config.extensionASTNodes;
166166

167167
// Build type map now to detect any errors within this schema.
168-
let initialTypes: Array<?GraphQLNamedType> = [
169-
this.getQueryType(),
170-
this.getMutationType(),
171-
this.getSubscriptionType(),
168+
const initialTypes: Array<?GraphQLNamedType> = [
169+
this._queryType,
170+
this._mutationType,
171+
this._subscriptionType,
172172
__Schema,
173-
];
174-
175-
const types = config.types;
176-
if (types) {
177-
initialTypes = initialTypes.concat(types);
178-
}
173+
].concat(config.types);
179174

180175
// Keep track of all types referenced within the schema.
181176
let typeMap: TypeMap = Object.create(null);

0 commit comments

Comments
 (0)