Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings
This repository was archived by the owner on Mar 20, 2023. It is now read-only.

Commita427761

Browse files
ESLint: Enable 'no-unnecessary-condition' rule (#737)
1 parent20e3466 commita427761

File tree

2 files changed

+16
-9
lines changed

2 files changed

+16
-9
lines changed

‎.eslintrc.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -491,7 +491,7 @@ overrides:
491491
'@typescript-eslint/no-throw-literal':error
492492
'@typescript-eslint/no-type-alias':off# TODO consider
493493
'@typescript-eslint/no-unnecessary-boolean-literal-compare':error
494-
'@typescript-eslint/no-unnecessary-condition':off# TODO blocked by https://github.com/typescript-eslint/typescript-eslint/issues/2752
494+
'@typescript-eslint/no-unnecessary-condition':error
495495
'@typescript-eslint/no-unnecessary-qualifier':error
496496
'@typescript-eslint/no-unnecessary-type-arguments':error
497497
'@typescript-eslint/no-unnecessary-type-assertion':error

‎src/index.ts

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ type Middleware = (request: Request, response: Response) => Promise<void>;
187187
* configure behavior, and returns an express middleware.
188188
*/
189189
exportfunctiongraphqlHTTP(options:Options):Middleware{
190-
devAssert(options!=null,'GraphQL middleware requires options.');
190+
devAssertIsNonNullable(options,'GraphQL middleware requires options.');
191191

192192
returnasyncfunctiongraphqlMiddleware(
193193
request:Request,
@@ -239,9 +239,8 @@ export function graphqlHTTP(options: Options): Middleware {
239239
optionsData.formatError??
240240
formatErrorFn;
241241

242-
// Assert that schema is required.
243-
devAssert(
244-
schema!=null,
242+
devAssertIsObject(
243+
schema,
245244
'GraphQL middleware options must contain a schema.',
246245
);
247246

@@ -432,8 +431,8 @@ export function graphqlHTTP(options: Options): Middleware {
432431
:options,
433432
);
434433

435-
devAssert(
436-
optionsResult!=null&&typeofoptionsResult==='object',
434+
devAssertIsObject(
435+
optionsResult,
437436
'GraphQL middleware option function must return an options object or a promise which will be resolved to an options object.',
438437
);
439438

@@ -533,9 +532,17 @@ function sendResponse(response: Response, type: string, data: string): void {
533532
response.end(chunk);
534533
}
535534

536-
functiondevAssert(condition:unknown,message:string): assertscondition{
535+
functiondevAssertIsObject(value:unknown,message:string):void{
536+
devAssert(value!=null&&typeofvalue==='object',message);
537+
}
538+
539+
functiondevAssertIsNonNullable(value:unknown,message:string):void{
540+
devAssert(value!=null,message);
541+
}
542+
543+
functiondevAssert(condition:unknown,message:string):void{
537544
constbooleanCondition=Boolean(condition);
538545
if(!booleanCondition){
539-
thrownewError(message);
546+
thrownewTypeError(message);
540547
}
541548
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp