-
Notifications
You must be signed in to change notification settings - Fork 42
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
chore: prevent unchecked index access #1612
base: master
Are you sure you want to change the base?
Conversation
26bf15b
to
9e12340
Compare
size-limit report 📦
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nice!
const tmp = arr[i] as T; | ||
arr[i] = arr[j] as T; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
does it not automatically infer the type? arr
is of the type T[]
🤔
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
noUncheckedIndexedAccess
makes so anything that is accepted by index becomes T | undefined
const clusterId = parseInt(parts[4] as string); | ||
const shard = parseInt(parts[5] as string); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: similar comment as above of not automatically inferring the types
@@ -3,6 +3,7 @@ | |||
"compilerOptions": { | |||
"module": "ESNext", | |||
"moduleResolution": "Bundler", | |||
"noEmit": true | |||
"noEmit": true, | |||
"noUncheckedIndexedAccess": false, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why is this false here? 🤔
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
tsconfig.dev
is used for tests where we don't really need to enforce this rule
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
wouldn't it be still good to have tests with no unchecked index access? can see it infact being more useful because it would spot errors before execution level :D
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not sure, let's discuss
I can enable it for tests but in that case many utilities we write would need to be compliant with more eager checks
I am in favor of enabling it for tests too tbh
@adklempner wdyt?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sounds beneficial but warrants a separate PR imo
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
^ agree
{ | ||
test: /\.([cm]?ts|tsx)$/, | ||
loader: "ts-loader", | ||
options: { configFile: tsConfigFile }, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This change makes tests running in with tsconfig.dev.json
which makes sense as we do have a lower bar for linting tests.
@waku-org/js-waku-developers
"test": "NODE_ENV=test npm run test --workspaces --if-present", | ||
"test:browser": "NODE_ENV=test npm run test:browser --workspaces --if-present", | ||
"test:node": "NODE_ENV=test npm run test:node --workspaces --if-present", | ||
"test": "npm run test --workspaces --if-present", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is not needed as each of internal commands should be worrying about supplying ENV flags
fyi @danisharora099
Problem
When access happens by index it is possible to hit a case when no value returned.
With no proper handling of such edge case it's easy to hit a problem in run time and increase amount of problems for consumers.
Examples of such issue is here - #1562
Solution
Enable TypeScript to check for such a case
Notes