-
Notifications
You must be signed in to change notification settings - Fork 536
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
Enable no-unchecked-record-access rule for devtools-core #23718
base: main
Are you sure you want to change the base?
Enable no-unchecked-record-access rule for devtools-core #23718
Conversation
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.
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
const editorFunction = this.editors[sharedObject.attributes.type]; | ||
const editorFunction: EditSharedObject | undefined = | ||
this.editors[sharedObject.attributes.type]; |
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 is not a valid pattern. See numerous prior conversations.
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.
I didnt know whether to make this change, allow the PR to pass and write this in the Needs review section, or to not make this change and not allow CI to pass. I will remove these changes from my PRs
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.
Probably you should remove recognition of this pattern as acceptable to the lint rule - then maybe no one will try to use it and hide problems.
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.
I can do this, but if I remove recognition of it, users will keep using the pattern, right? Isnt that what we are trying to avoid?
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.
I don't know what you are asking. We thought that we could use the pattern of T | undefined
to tell TypeScript to treat the variable as possibly undefined. But that doesn't happen. TypeScript ignores the undefined because [without noUncheckedIndexAccess
] it thinks the result is always defined. Code says T | undefined
and TypeScript sees T
only.
Similar for ?
- basically ignored by TypeScript and therefore meaningless.
If someone codes foo: T | undefined =
and both the linter rule and TypeScript ignore the undefined
part, then the linter will point out the issue and the code will have to be fixed. That is the result we want.
ESLint Configuration Changes:
@fluid-internal/fluid/no-unchecked-record-access
from "warn" to "error" in the.eslintrc.cjs
file by removing the lineNeeds Review:
DataVisualization.ts
:EditSharedObject | undefined
foreditorFunction
variable to handle potential undefined values