Skip to content
This repository has been archived by the owner on Oct 1, 2024. It is now read-only.

Commit

Permalink
Enable noImplicitReturns:true and allowUnreachableCode:false when typ…
Browse files Browse the repository at this point in the history
…e-checking (#2583)

* Enforce throwing type-check errors on unreachable code

Three instances of unreachable code have been removed

* Enable noImplicitReturns type-check config

Add `return undefined` to places where implict returns were present
  • Loading branch information
BPScott authored Mar 3, 2023
1 parent 2781826 commit 2aa32e8
Show file tree
Hide file tree
Showing 18 changed files with 43 additions and 9 deletions.
5 changes: 5 additions & 0 deletions .changeset/eighty-bears-leave.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@shopify/koa-shopify-graphql-proxy': patch
---

Remove unneeded return statement after a throw
12 changes: 12 additions & 0 deletions .changeset/fair-baboons-destroy.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
---
'@shopify/ast-utilities': patch
'@shopify/koa-performance': patch
'@shopify/mime-types': patch
'@shopify/react-form': patch
'@shopify/react-form-state': patch
'@shopify/react-google-analytics': patch
'@shopify/react-hooks': patch
'@shopify/react-performance': patch
---

Add explict `return undefined` to functions that had implicit returns
5 changes: 5 additions & 0 deletions .changeset/rare-jars-roll.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@shopify/mime-types': patch
---

getExtensionFromMimeType should return undefined if you pass in an unknown mime type
4 changes: 0 additions & 4 deletions config/typescript/tsconfig.base.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,7 @@
// These reach a level of pedanticness we aren't worried about
// importsNotUsedAsValues has 50 violations, but they're trivial fixes
"importsNotUsedAsValues": "remove",
// allowUnreachableCode has 3 violations, should be a quick fix
"allowUnreachableCode": true,
"noImplicitOverride": false,
// noImplicitReturns has 8 violations, should be a quick fix
"noImplicitReturns": false,
"noPropertyAccessFromIndexSignature": false,
"noUncheckedIndexedAccess": false,
"exactOptionalPropertyTypes": false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ export default function addComponentProps(
prop.value.name === attr.value.expression.name
);
}

return false;
}).length,
),
);
Expand Down
1 change: 1 addition & 0 deletions packages/koa-performance/src/middleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,7 @@ export function clientPerformanceMetrics({
const distributions = metrics.map(({name, value, tags}) => {
if (development) {
appLogger.log(`Skipping sending metric in dev ${name}: ${value}`);
return undefined;
} else {
appLogger.log(`Sending metric ${name}: ${value}`);
return statsd.distribution(name, value, tags);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ export default function shopifyGraphQLProxy(proxyOptions: ProxyOptions) {

if (accessToken == null || shop == null) {
ctx.throw(403, 'Unauthorized');
return;
}

await proxy(shop, {
Expand Down
3 changes: 0 additions & 3 deletions packages/mime-types/src/get-extension-from-mime-type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,4 @@ export function getExtensionFromMimeType(mimeType: MimeType) {
case MimeType.Svg:
return '.svg';
}

const nope: never = mimeType;
return nope;
}
4 changes: 4 additions & 0 deletions packages/mime-types/src/get-mime-type-from-filename.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ export function getMimeTypeFromFilename(filename: string) {
case 'svg':
return MimeType.Svg;
}

return undefined;
}

function getFileExtension(filename: string) {
Expand All @@ -52,4 +54,6 @@ function getFileExtension(filename: string) {
if (match) {
return match[1];
}

return undefined;
}
2 changes: 2 additions & 0 deletions packages/react-form-state/src/validators.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ export function validateList<Input extends object, Fields>(
if (errors.some((error) => error != null)) {
return errors;
}

return undefined;
};
}

Expand Down
1 change: 1 addition & 0 deletions packages/react-form/src/hooks/field/field.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ export function useField<Value = string>(
}

dispatch(updateErrorAction(undefined));
return undefined;
},
// eslint-disable-next-line react-hooks/exhaustive-deps
[state.value, ...dependencies],
Expand Down
1 change: 1 addition & 0 deletions packages/react-form/src/hooks/field/tests/field.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -442,6 +442,7 @@ describe('useField', () => {
if (someOtherFieldValue === 'radical' && value === 'pants') {
return 'no radical pants allowed';
}
return undefined;
},
};

Expand Down
2 changes: 2 additions & 0 deletions packages/react-form/src/hooks/list/tests/baselist.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,7 @@ describe('useBaseList', () => {
if (value.length < 1) {
return 'Price must be specified';
}
return undefined;
},
};

Expand Down Expand Up @@ -383,6 +384,7 @@ describe('useBaseList', () => {
if (anyDupes) {
return 'No duplicates allowed';
}
return undefined;
},
};

Expand Down
1 change: 1 addition & 0 deletions packages/react-form/src/hooks/list/utils/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,5 @@ export function runValidation<Value, Record extends object>(
}

updateError(undefined);
return undefined;
}
2 changes: 1 addition & 1 deletion packages/react-google-analytics/src/Universal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ export default function UniversalGoogleAnalytics({
onError(googleAnalytics);
}

return null;
return;
}

googleAnalytics('create', account, 'auto', options);
Expand Down
2 changes: 2 additions & 0 deletions packages/react-hooks/src/hooks/interval.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,7 @@ export function useInterval(callback: IntervalCallback, delay: IntervalDelay) {
const id = setInterval(tick, delay);
return () => clearInterval(id);
}

return undefined;
}, [delay]);
}
2 changes: 2 additions & 0 deletions packages/react-hooks/src/hooks/timeout.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,7 @@ export function useTimeout(callback: IntervalCallback, delay: IntervalDelay) {
const id = setTimeout(tick, delay);
return () => clearTimeout(id);
}

return undefined;
}, [delay]);
}
2 changes: 2 additions & 0 deletions packages/react-performance/src/performance-effect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ export function usePerformanceEffect(
if (cleanup) {
return cleanup;
}

return undefined;
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [performance, ...dependencies]);
}

0 comments on commit 2aa32e8

Please sign in to comment.