Skip to content

Commit

Permalink
Enforce Expo API Route response type checking (#447)
Browse files Browse the repository at this point in the history
  • Loading branch information
karlhorky authored Oct 24, 2024
1 parent 1081ba0 commit ee64bb8
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -1004,7 +1004,7 @@ const configArray = [
// Warn on restricted syntax
'no-restricted-syntax': [
...noRestrictedSyntaxOptions,
// Warn on Route Handler function without NextResponse
// Warn on Next.js Route Handler function without NextResponse
// return type annotation
{
selector:
Expand All @@ -1015,6 +1015,23 @@ const configArray = [
],
},
},
{
files: ['app/**/*+api.js', 'app/**/*+api.ts'],
rules: {
// Warn on restricted syntax
'no-restricted-syntax': [
...noRestrictedSyntaxOptions,
// Warn on Expo API Route function without ExpoApiResponse
// return type annotation
{
selector:
"FunctionDeclaration[id.name=/^(GET|POST|PUT|DELETE)$/]:not([returnType.typeAnnotation.typeName.name='Promise'][returnType.typeAnnotation.typeArguments.params.0.typeName.name='ExpoApiResponse'][returnType.typeAnnotation.typeArguments.params.0.typeArguments.params.0]):not([returnType.typeAnnotation.typeName.name='ExpoApiResponse'][returnType.typeAnnotation.typeArguments.params.0])",
message:
'API Route function missing return type annotation (eg. `async function PUT(request: Request): Promise<ExpoApiResponse<AnimalResponseBodyPut>>`)',
},
],
},
},
{
name: 'upleveled:database-auth',
files: ['database/*.ts'],
Expand Down

0 comments on commit ee64bb8

Please sign in to comment.