Skip to content
This repository has been archived by the owner on Aug 31, 2023. It is now read-only.

fix(rome_js_analyze): fix for unused flag on functional types on ts #3860

Merged
merged 13 commits into from
Dec 5, 2022

Conversation

xunilrj
Copy link
Contributor

@xunilrj xunilrj commented Nov 25, 2022

Summary

Fixes #3669.
This PR also:

  • reorganizes all the tests for noUnusedVariables;
  • improves suggestion to rename unused variables (taking into consideration pattern matching, for example).

I have also implemented the navigation from JsIdentifierBinding to its declaration and from parameters to its parent function. These will not only simplify lint rules, but also help in edgy and forgotten cases.

This PR also implements a hardfail for valid tests that contains "/* should not gnerate diagnostics */", but that still generate them.

Test Plan

> cargo test -p rome_js_analyze -- no_unused_variables

@netlify
Copy link

netlify bot commented Nov 25, 2022

Deploy Preview for docs-rometools canceled.

Name Link
🔨 Latest commit de7d4fe
🔍 Latest deploy log https://app.netlify.com/sites/docs-rometools/deploys/638b96c8619be500084db57f

@xunilrj
Copy link
Contributor Author

xunilrj commented Nov 25, 2022

!bench_analyzer

@github-actions
Copy link

github-actions bot commented Nov 25, 2022

Parser conformance results on ubuntu-latest

js/262

Test result main count This PR count Difference
Total 45879 45879 0
Passed 44936 44936 0
Failed 943 943 0
Panics 0 0 0
Coverage 97.94% 97.94% 0.00%

jsx/babel

Test result main count This PR count Difference
Total 39 39 0
Passed 36 36 0
Failed 3 3 0
Panics 0 0 0
Coverage 92.31% 92.31% 0.00%

symbols/microsoft

Test result main count This PR count Difference
Total 5946 5946 0
Passed 1757 1707 ❌ ⏬ -50
Failed 4189 4239 ❌ ⏫ +50
Panics 0 0 0
Coverage 29.55% 28.71% -0.84%
🔥 Regression (50):
asOperator3.symbols
asOperatorASI.symbols
blockScopedBindingsReassignedInLoop1.symbols
capturedLetConstInLoop1.symbols
capturedLetConstInLoop3.symbols
capturedLetConstInLoop3_ES6.symbols
commentOnAmbientfunction.symbols
conditionalTypeBasedContextualTypeReturnTypeWidening.symbols
conditionallyDuplicateOverloadsCausedByOverloadResolution.symbols
constraintSatisfactionWithAny2.symbols
contextualSigInstantiationRestParams.symbols
contextualSignatureInstantiation4.symbols
contextualTypingFunctionReturningFunction2.symbols
contravariantTypeAliasInference.symbols
controlFlowCommaExpressionAssertionWithinTernary.symbols
controlFlowTruthiness.symbols
downlevelLetConst17.symbols
exportEqualsOfModule.symbols
externFunc.symbols
fallFromLastCase1.symbols
fallbackToBindingPatternForTypeInference.symbols
freshLiteralTypesInIntersections.symbols
functionExpressionContextualTyping3.symbols
importCallExpressionDeclarationEmit1.symbols
inferentialTypingWithFunctionType.symbols
inferentiallyTypingAnEmptyArray.symbols
keyofModuleObjectHasCorrectKeys.symbols
letConstMatchingParameterNames.symbols
noImplicitReturnsWithProtectedBlocks1.symbols
nullishCoalescingOperator10.symbols
overloadsAndTypeArgumentArity.symbols
partiallyAnnotatedFunctionWitoutTypeParameter.symbols
propagateNonInferrableType.symbols
reachabilityCheckWithEmptyDefault.symbols
selfReference.symbols
shebangBeforeReferences.symbols
strictNullChecksNoWidening.symbols
stringLiteralTypesAndParenthesizedExpressions01.symbols
stringLiteralTypesOverloads04.symbols
subtypingWithConstructSignatures.symbols
taggedTemplateStringWithSymbolExpression01.symbols
tupleTypeInference2.symbols
typeGuardNarrowsToLiteralType.symbols
typeGuardNarrowsToLiteralTypeUnion.symbols
typeInferenceFixEarly.symbols
typeInferenceTypePredicate.symbols
typeInferenceWithTypeAnnotation.symbols
typePredicatesInUnion2.symbols
untypedArgumentInLambdaExpression.symbols
wideningTuples1.symbols

ts/babel

Test result main count This PR count Difference
Total 588 588 0
Passed 519 519 0
Failed 69 69 0
Panics 0 0 0
Coverage 88.27% 88.27% 0.00%

ts/microsoft

Test result main count This PR count Difference
Total 16257 16257 0
Passed 12397 12397 0
Failed 3860 3860 0
Panics 0 0 0
Coverage 76.26% 76.26% 0.00%

@github-actions
Copy link

Analyzer Benchmark Results

group                     main                                   pr
-----                     ----                                   --
analyzer/css.js           1.00      2.4±0.03ms     4.9 MB/sec    1.00      2.4±0.03ms     4.9 MB/sec
analyzer/index.js         1.00      6.2±0.01ms     5.3 MB/sec    1.00      6.3±0.05ms     5.2 MB/sec
analyzer/lint.ts          1.01      2.8±0.02ms    14.7 MB/sec    1.00      2.8±0.02ms    14.8 MB/sec
analyzer/parser.ts        1.00      7.1±0.02ms     6.8 MB/sec    1.02      7.3±0.04ms     6.7 MB/sec
analyzer/router.ts        1.00      3.1±0.01ms    11.1 MB/sec    1.01      3.1±0.02ms    11.0 MB/sec
analyzer/statement.ts     1.00      6.9±0.01ms     5.2 MB/sec    1.00      6.9±0.03ms     5.1 MB/sec
analyzer/typescript.ts    1.00     10.1±0.09ms     5.4 MB/sec    1.00     10.2±0.03ms     5.4 MB/sec

@xunilrj xunilrj marked this pull request as ready for review November 28, 2022 10:43
@xunilrj xunilrj requested review from leops, ematipico and a team as code owners November 28, 2022 10:43
@calibre-analytics
Copy link

calibre-analytics bot commented Nov 28, 2022

Comparing fix(rome_js_analyze): fix for unused flag on functional types on ts Snapshot #12 to median since last deploy of rome.tools.

LCP? CLS? TBT?
Overall
Median across all pages and test profiles
2.65s
from 282ms
0.0
no change
138ms
no change
Chrome Desktop
Chrome Desktop • Cable
2.65s
from 282ms
0.0
no change
376ms
from 22ms
iPhone, 4G LTE
iPhone 12 • 4G LTE
1.18s
from 240ms
0.0
no change
21ms
no change
Motorola Moto G Power, 3G connection
Motorola Moto G Power • Regular 3G
19.3s
from 1.07s
0.0
no change
138ms
no change

1 page tested

 Home

Browser previews

Chrome Desktop iPhone, 4G LTE Motorola Moto G Power, 3G connection
Chrome Desktop iPhone, 4G LTE Motorola Moto G Power, 3G connection

Most significant changes

Value Budget
Total JavaScript Size in Bytes
Chrome Desktop
5.67 MB
from 86.8 KB
Total JavaScript Size in Bytes
iPhone, 4G LTE
5.67 MB
from 86.8 KB
Total JavaScript Size in Bytes
Motorola Moto G Power, 3G connection
5.67 MB
from 86.8 KB
JS Parse & Compile
Motorola Moto G Power, 3G connection
1.67s
from 28ms
JS Parse & Compile
iPhone, 4G LTE
511ms
from 12ms

27 other significant changes: JS Parse & Compile on Chrome Desktop, Largest Contentful Paint on Motorola Moto G Power, 3G connection, First Contentful Paint on Motorola Moto G Power, 3G connection, Total Blocking Time on Chrome Desktop, Time to Interactive on Motorola Moto G Power, 3G connection, Total Page Size in Bytes on Chrome Desktop, Total Page Size in Bytes on iPhone, 4G LTE, Total Page Size in Bytes on Motorola Moto G Power, 3G connection, Total CSS Size in Bytes on Chrome Desktop, Total CSS Size in Bytes on iPhone, 4G LTE, Total CSS Size in Bytes on Motorola Moto G Power, 3G connection, Time to Interactive on Chrome Desktop, First Contentful Paint on Chrome Desktop, Largest Contentful Paint on Chrome Desktop, Number of Requests on Motorola Moto G Power, 3G connection, Number of Requests on Chrome Desktop, Number of Requests on iPhone, 4G LTE, Speed Index on Motorola Moto G Power, 3G connection, Time to Interactive on iPhone, 4G LTE, First Contentful Paint on iPhone, 4G LTE, Largest Contentful Paint on iPhone, 4G LTE, Speed Index on Chrome Desktop, Total HTML Size in Bytes on Chrome Desktop, Total HTML Size in Bytes on iPhone, 4G LTE, Total HTML Size in Bytes on Motorola Moto G Power, 3G connection, Lighthouse Performance Score on Motorola Moto G Power, 3G connection, Lighthouse Performance Score on Chrome Desktop

Calibre: Site dashboard | View this PR | Edit settings | View documentation

// Some parameters are ok to not be used
JsAnyBindingDeclaration::TsPropertyParameter(parameter) => {
let is_binding_ok =
is_ok_to_be_unused(parameter.parent_function()) || is_public_or_private(parameter)?;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm struggling to understand what the return value of is_public_or_private is. Does it return true if it is private or when it is public.

Suggestion:

  • rename to is_public or is_private
  • Add a visibility enum and change it to visibility(parameter).is_public()

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed the name. Hopefully makes more sense now.

crates/rome_js_syntax/src/binding_ext.rs Outdated Show resolved Hide resolved
crates/rome_js_syntax/src/binding_ext.rs Outdated Show resolved Hide resolved
crates/rome_js_syntax/src/binding_ext.rs Show resolved Hide resolved
@xunilrj xunilrj force-pushed the fix/3669-no-unused-variables branch 2 times, most recently from a73de33 to 6f7a386 Compare November 30, 2022 16:32
1 │ // used function declaration
> 2 │ function a() {}
│ ^
3 │ a()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This one seems to be a false positive too, the function is being used on the next line

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You have keen eyes! 👀
This was actually a scope resolution bug. Thanks!

@xunilrj xunilrj force-pushed the fix/3669-no-unused-variables branch from 259278d to bfb7632 Compare December 2, 2022 13:07
@xunilrj
Copy link
Contributor Author

xunilrj commented Dec 3, 2022

We don't suggest renaming imports anymore, so we fix the broken suggestion at #3786.

@xunilrj xunilrj merged commit 8b6b6d0 into main Dec 5, 2022
@xunilrj xunilrj deleted the fix/3669-no-unused-variables branch December 5, 2022 11:44
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

🐛 noUnusedVariables incorrectly flags types, possible improvements
4 participants