-
Notifications
You must be signed in to change notification settings - Fork 27
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
no-default-id-values rule #137
Conversation
All contributors have signed the CLA ✍️ ✅ |
I have read the CLA Document and I hereby sign the CLA |
Opened PR to review cc @neil-marcellini @iwiznia @paultsimura |
Should we catch assignments of default values too? e.g. let currentUserAccountID = -1;
let transactionID = '-1'; |
IMO, this is not a common case in the App, so we shouldn't worry about it. However, I'll leave the decision to @iwiznia or @neil-marcellini. |
I'll treat the 👍 from Ionatan as approval for #137 (comment). |
@paultsimura and @fabioh8010 I believe this was correctly spotted, but the original issue isn't too clear. Empty strings are also being disallowed for defaults with this, right? I think I saw @fabioh8010 correctly spot that the danger of empty strings is subscribing to the entire collection. |
That is correct, and this rule will catch these situations too 👍 |
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.
@iwiznia, @neil-marcellini, @tgolen, please proceed with your review. |
@iwiznia, @neil-marcellini, @tgolen could you have a look here? Thanks! |
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 looks good, but hard to tell if it will generate a lot of false positives, can you make this new rule run in App and see if it does?
|
||
const disallowedNumberDefaults = [ | ||
'ID ?? -1', | ||
'id ?? -1', |
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.
Rather than having all case-sensitive options, can we just make the check be cause-insensitive?
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.
@fabioh8010 bump on this question
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 would like to keep them all separated for all, just in case we discover that some string match is being problematic, but it happens to be case sensitive. Is that ok for you?
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.
OK, yeah. That's fine. Thanks for explaining and documenting the analysis you did!
@iwiznia I analysed all search results by string match and here are the possible false-positives for each one:
Most of these possible false-positives are based on my own doubts if that ID could be of an entity or Onyx data, so the real number can be smaller. Anyway, I think the results here show us that we have few ones compared to the total of results of each string match. |
So if we update the config in App, all PRs will start failing on those files? |
The PRs will fail if they have changed files that have one of the matches described in the rule, it could be any .ts/.tsx file. |
This PR implements a new ESLint rule to detect and restricts usage of default number/string IDs in E/App. It's intended to be used on
.eslintrc.changed.js
, that will only run for the changes files of a PR.This ESLint rule does a simple string match check to look for ID defaults in E/App, while it is not an optimal solution it should be enough for us to detect these situations.
Issue: Expensify/App#50360
Tests
eslint-config-expensify
repo to E/App:npx link publish <path-to-eslint-repo>/
rulesdir/no-default-id-values
rule to.eslintrc.changed.js
and set it toerror
.src/libs/ReportUtils.ts
, and commit that file.npm run lint-changed
, assert the errors were reported.