Skip to content

Commit

Permalink
flow: Enable 'uninitialized-instance-property' lint (#2058)
Browse files Browse the repository at this point in the history
  • Loading branch information
IvanGoncharov authored Jul 27, 2019
1 parent e6725de commit fc4058d
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 24 deletions.
2 changes: 1 addition & 1 deletion .flowconfig
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ implicit-inexact-object=error
unnecessary-optional-chain=error
unnecessary-invariant=off
signature-verification-failure=error
uninitialized-instance-property=off
uninitialized-instance-property=error
non-array-spread=error

[options]
Expand Down
10 changes: 5 additions & 5 deletions src/language/parser.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// @flow strict

import inspect from '../jsutils/inspect';
import invariant from '../jsutils/invariant';
import defineToJSON from '../jsutils/defineToJSON';
import { Source } from './source';
import { type GraphQLError } from '../error/GraphQLError';
Expand Down Expand Up @@ -171,11 +172,10 @@ class Parser {

constructor(source: string | Source, options?: ParseOptions) {
const sourceObj = typeof source === 'string' ? new Source(source) : source;
if (!(sourceObj instanceof Source)) {
throw new TypeError(
`Must provide Source. Received: ${inspect(sourceObj)}`,
);
}
invariant(
sourceObj instanceof Source,
`Must provide Source. Received: ${inspect(sourceObj)}`,
);

this._lexer = createLexer(sourceObj);
this._options = options || {};
Expand Down
16 changes: 8 additions & 8 deletions src/type/definition.js
Original file line number Diff line number Diff line change
Expand Up @@ -555,13 +555,13 @@ export class GraphQLScalarType {
extensionASTNodes: ?$ReadOnlyArray<ScalarTypeExtensionNode>;

constructor(config: GraphQLScalarTypeConfig<*, *>): void {
const parseValue = config.parseValue || identityFunc;
this.name = config.name;
this.description = config.description;
this.serialize = config.serialize || identityFunc;
this.parseValue = config.parseValue || identityFunc;
this.parseValue = parseValue;
this.parseLiteral =
config.parseLiteral ||
(node => this.parseValue(valueFromASTUntyped(node)));
config.parseLiteral || (node => parseValue(valueFromASTUntyped(node)));

this.astNode = config.astNode;
this.extensionASTNodes = undefineIfEmpty(config.extensionASTNodes);
Expand Down Expand Up @@ -1155,7 +1155,7 @@ export class GraphQLEnumType /* <T> */ {
this.description = config.description;
this.astNode = config.astNode;
this.extensionASTNodes = undefineIfEmpty(config.extensionASTNodes);
this._values = defineEnumValues(this, config.values);
this._values = defineEnumValues(this.name, config.values);
this._valueLookup = new Map(
this._values.map(enumValue => [enumValue.value, enumValue]),
);
Expand Down Expand Up @@ -1232,22 +1232,22 @@ defineToStringTag(GraphQLEnumType);
defineToJSON(GraphQLEnumType);

function defineEnumValues(
type: GraphQLEnumType,
typeName: string,
valueMap: GraphQLEnumValueConfigMap /* <T> */,
): Array<GraphQLEnumValue /* <T> */> {
invariant(
isPlainObj(valueMap),
`${type.name} values must be an object with value names as keys.`,
`${typeName} values must be an object with value names as keys.`,
);
return objectEntries(valueMap).map(([valueName, value]) => {
invariant(
isPlainObj(value),
`${type.name}.${valueName} must refer to an object with a "value" key ` +
`${typeName}.${valueName} must refer to an object with a "value" key ` +
`representing an internal value but got: ${inspect(value)}.`,
);
invariant(
!('isDeprecated' in value),
`${type.name}.${valueName} should provide "deprecationReason" instead of "isDeprecated".`,
`${typeName}.${valueName} should provide "deprecationReason" instead of "isDeprecated".`,
);
return {
name: valueName,
Expand Down
15 changes: 5 additions & 10 deletions src/type/schema.js
Original file line number Diff line number Diff line change
Expand Up @@ -165,17 +165,12 @@ export class GraphQLSchema {
this.extensionASTNodes = config.extensionASTNodes;

// Build type map now to detect any errors within this schema.
let initialTypes: Array<?GraphQLNamedType> = [
this.getQueryType(),
this.getMutationType(),
this.getSubscriptionType(),
const initialTypes: Array<?GraphQLNamedType> = [
this._queryType,
this._mutationType,
this._subscriptionType,
__Schema,
];

const types = config.types;
if (types) {
initialTypes = initialTypes.concat(types);
}
].concat(config.types);

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

0 comments on commit fc4058d

Please sign in to comment.