Skip to content
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

flow: Enable 'uninitialized-instance-property' lint #2058

Merged
merged 1 commit into from Jul 27, 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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion .flowconfig
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
@@ -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
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
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