Skip to content
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

More typescript eslint rules #1119

Merged
merged 8 commits into from
Apr 19, 2022

Conversation

zakpatterson
Copy link
Collaborator

@zakpatterson zakpatterson commented Apr 15, 2022

  • First commit: Adds the typescript-eslint rules that are recommended, which consider type information. This fixes numerous different potential bugs and points of confusion. For example:

    • Floating promises are explicitly marked. These are promises that are created where it's not possible to await them. This would always be a potential bug, except in the case of user events. onClick expects a method returning void, but often we want to do something asynchronously. So these cases are marked with a new function intentionallyFloat.
    • Many cases in tests where functions were declared as async but didn't await anything.
    • Created a new type for a SoldAsset, which requires a closeDate and a closePrice. Eliminates lots of unnecessary undefined checking.
    • Improves generic form elements so there's better typechecking around the values and names, based on the type of the form data coming in from context.
  • Second commit: Adds a (not officially recommended but perfect for this project) no-unnecessary-condition rule. Benefits:

    • We have a lot of fields that return number and lots that return number | undefined. The basic rules catch cases where we're treating a field incorrectly as a field returning number when it can be undefined. This rule makes sure we're not needlessly checking for undefined when the types say undefined is not possible. In the future if we remove | undefined from a field, the linter will find all the places where we were doing something like ?? 0.
    • This also catches cases where we wrote something like: x() ?? 0 > 0! ?? is lower precedence than > so that expression for x: () => A would have type A | boolean and might not behave as expected.

What kind of change does this PR introduce? (delete not applicable)

  • Bugfix
  • Build-related changes

We have a lot of fields that return number, and lots
that return number | undefined.
This rule helps us track down cases where we're checking
if a value is undefined when the types assert the value
cannot be undefined.
Match is equivalent to exec if the entire string is
to be searched for one match. See

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/exec
@codecov
Copy link

codecov bot commented Apr 15, 2022

Codecov Report

Merging #1119 (26865c8) into master (5008161) will increase coverage by 0.81%.
The diff coverage is 64.26%.

@@            Coverage Diff             @@
##           master    #1119      +/-   ##
==========================================
+ Coverage   52.41%   53.22%   +0.81%     
==========================================
  Files         235      235              
  Lines       11352    11329      -23     
  Branches     1600     1516      -84     
==========================================
+ Hits         5950     6030      +80     
+ Misses       5388     5285     -103     
  Partials       14       14              
Impacted Files Coverage Δ
src/components/DataPropagator.tsx 0.00% <0.00%> (ø)
src/components/FormContainer.tsx 95.60% <ø> (ø)
src/components/RefundBankAccount.tsx 5.55% <ø> (ø)
src/components/SummaryData.ts 17.39% <0.00%> (-0.80%) ⬇️
src/components/TaxPayer/PersonFields.tsx 25.00% <0.00%> (ø)
src/components/YearDropDown.tsx 94.11% <ø> (-0.33%) ⬇️
src/components/deductions/F1098eInfo.tsx 16.00% <ø> (ø)
src/components/deductions/ItemizedDeductions.tsx 15.38% <ø> (ø)
src/components/income/F1099Info.tsx 56.81% <ø> (ø)
src/components/income/OtherInvestments.tsx 7.50% <ø> (ø)
... and 84 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 07e4adc...26865c8. Read the comment docs.

# Conflicts:
#	src/tests/components/Menu.test.tsx
Comparing two enums when there's only one value makes no sense
@zakpatterson zakpatterson marked this pull request as draft April 19, 2022 01:45
@zakpatterson zakpatterson marked this pull request as ready for review April 19, 2022 03:30
@zakpatterson
Copy link
Collaborator Author

Intermittent issue came up in build, present on master, added failing test as #1129.

This one should be ready.

@thegrims thegrims merged commit 7725363 into ustaxes:master Apr 19, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants