Skip to content

Commit 9498dee

Browse files
authored
set additionalProperties: false to report unused variables (#3982)
1 parent 91a3f8b commit 9498dee

File tree

6 files changed

+26
-19
lines changed

6 files changed

+26
-19
lines changed

.changeset/few-lamps-rest.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'graphql-language-service': minor
3+
---
4+
5+
feat: set `additionalProperties: false` to report unused variables

packages/codemirror-graphql/src/utils/SchemaReference.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,6 @@ export function getEnumValueReference(typeInfo: TypeInfo): EnumValueReference {
100100
return {
101101
kind: 'EnumValue',
102102
value: typeInfo.enumValue || undefined,
103-
// $FlowFixMe
104103
type: typeInfo.inputType
105104
? (getNamedType(typeInfo.inputType) as GraphQLEnumType)
106105
: undefined,

packages/graphql-language-service-server/src/__tests__/MessageProcessor.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -359,7 +359,7 @@ describe('MessageProcessor', () => {
359359
});
360360

361361
it('properly removes from the file cache with the didClose handler', async () => {
362-
await messageProcessor.handleDidCloseNotification(initialDocument);
362+
messageProcessor.handleDidCloseNotification(initialDocument);
363363

364364
const position = { line: 4, character: 5 };
365365
const params = { textDocument: initialDocument.textDocument, position };
@@ -407,7 +407,7 @@ describe('MessageProcessor', () => {
407407
};
408408

409409
const result = await messageProcessor.handleDefinitionRequest(test);
410-
await expect(result[0].uri).toEqual(`${queryPathUri}/test3.graphql`);
410+
expect(result[0].uri).toEqual(`${queryPathUri}/test3.graphql`);
411411
});
412412

413413
it('retrieves custom results from locateCommand', async () => {

packages/graphql-language-service/src/interface/getDiagnostics.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -193,11 +193,9 @@ export function getRange(location: SourceLocation, queryText: string): IRange {
193193

194194
invariant(stream, 'Expected Parser stream to be available.');
195195
const line = location.line - 1;
196-
// @ts-ignore
197-
// https://github.com/microsoft/TypeScript/pull/32695
196+
// @ts-expect-error -- https://github.com/microsoft/TypeScript/pull/32695
198197
const start = stream.getStartOfToken();
199-
// @ts-ignore
200-
// https://github.com/microsoft/TypeScript/pull/32695
198+
// @ts-expect-error -- https://github.com/microsoft/TypeScript/pull/32695
201199
const end = stream.getCurrentPosition();
202200
return new Range(new Position(line, start), new Position(line, end));
203201
}

packages/graphql-language-service/src/interface/getHoverInformation.ts

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ export function getHoverInformation(
105105
return '';
106106
}
107107

108-
function renderMdCodeStart(into: string[], options: any) {
108+
function renderMdCodeStart(into: string[], options: HoverConfig) {
109109
if (options.useMarkdown) {
110110
text(into, '```graphql\n');
111111
}
@@ -119,7 +119,7 @@ function renderMdCodeEnd(into: string[], options: any) {
119119
export function renderField(
120120
into: string[],
121121
typeInfo: AllTypeInfo,
122-
options: any,
122+
options: HoverConfig,
123123
) {
124124
renderQualifiedField(into, typeInfo, options);
125125
renderTypeAnnotation(into, typeInfo, options, typeInfo.type!);
@@ -128,7 +128,7 @@ export function renderField(
128128
function renderQualifiedField(
129129
into: string[],
130130
typeInfo: AllTypeInfo,
131-
options: any,
131+
options: HoverConfig,
132132
) {
133133
if (!typeInfo.fieldDef) {
134134
return;
@@ -144,7 +144,7 @@ function renderQualifiedField(
144144
export function renderDirective(
145145
into: string[],
146146
typeInfo: AllTypeInfo,
147-
_options: any,
147+
_options: HoverConfig,
148148
) {
149149
if (!typeInfo.directiveDef) {
150150
return;
@@ -153,7 +153,11 @@ export function renderDirective(
153153
text(into, name);
154154
}
155155

156-
export function renderArg(into: string[], typeInfo: AllTypeInfo, options: any) {
156+
export function renderArg(
157+
into: string[],
158+
typeInfo: AllTypeInfo,
159+
options: HoverConfig,
160+
) {
157161
if (typeInfo.directiveDef) {
158162
renderDirective(into, typeInfo, options);
159163
} else if (typeInfo.fieldDef) {
@@ -174,7 +178,7 @@ export function renderArg(into: string[], typeInfo: AllTypeInfo, options: any) {
174178
function renderTypeAnnotation(
175179
into: string[],
176180
typeInfo: AllTypeInfo,
177-
options: any,
181+
options: HoverConfig,
178182
t: GraphQLType,
179183
) {
180184
text(into, ': ');
@@ -184,7 +188,7 @@ function renderTypeAnnotation(
184188
export function renderEnumValue(
185189
into: string[],
186190
typeInfo: AllTypeInfo,
187-
options: any,
191+
options: HoverConfig,
188192
) {
189193
if (!typeInfo.enumValue) {
190194
return;
@@ -198,7 +202,7 @@ export function renderEnumValue(
198202
export function renderType(
199203
into: string[],
200204
typeInfo: AllTypeInfo,
201-
options: any,
205+
options: HoverConfig,
202206
t: GraphQLType,
203207
) {
204208
if (!t) {
@@ -219,7 +223,7 @@ export function renderType(
219223

220224
function renderDescription(
221225
into: string[],
222-
options: any,
226+
options: HoverConfig,
223227
// TODO: Figure out the right type for this one
224228
def: any,
225229
) {
@@ -237,14 +241,14 @@ function renderDescription(
237241

238242
function renderDeprecation(
239243
into: string[],
240-
_options: any,
241-
def: GraphQLField<any, any> | GraphQLFieldConfig<any, any>,
244+
_options: HoverConfig,
245+
def: GraphQLField<unknown, unknown> | GraphQLFieldConfig<unknown, unknown>,
242246
) {
243247
if (!def) {
244248
return;
245249
}
246250

247-
const reason = def.deprecationReason || null;
251+
const reason = def.deprecationReason;
248252
if (!reason) {
249253
return;
250254
}

packages/graphql-language-service/src/utils/getVariablesJSONSchema.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -359,6 +359,7 @@ export function getVariablesJSONSchema(
359359
type: 'object',
360360
properties: {},
361361
required: [],
362+
additionalProperties: false,
362363
};
363364

364365
const runtimeOptions: JSONSchemaRunningOptions = {

0 commit comments

Comments
 (0)