Add diagnostic to flag unsupported usages of initializer APIs#54993
Closed
crisbeto wants to merge 5 commits intoangular:mainfrom
Closed
Add diagnostic to flag unsupported usages of initializer APIs#54993crisbeto wants to merge 5 commits intoangular:mainfrom
crisbeto wants to merge 5 commits intoangular:mainfrom
Conversation
crisbeto
commented
Mar 22, 2024
packages/compiler-cli/src/ngtsc/validation/src/rules/initializer_api_usage_rule.ts
Outdated
Show resolved
Hide resolved
73124f5 to
1920539
Compare
devversion
approved these changes
Mar 22, 2024
packages/compiler-cli/src/ngtsc/validation/src/rules/initializer_api_usage_rule.ts
Outdated
Show resolved
Hide resolved
packages/compiler-cli/src/ngtsc/validation/src/rules/initializer_api_usage_rule.ts
Outdated
Show resolved
Hide resolved
packages/compiler-cli/src/ngtsc/validation/src/rules/initializer_api_usage_rule.ts
Outdated
Show resolved
Hide resolved
AndrewKushnir
approved these changes
Mar 23, 2024
Contributor
AndrewKushnir
left a comment
There was a problem hiding this comment.
Reviewed-for: public-api
atscott
approved these changes
Mar 23, 2024
Contributor
atscott
left a comment
There was a problem hiding this comment.
Reviewed-for: public-api
pkozlowski-opensource
approved these changes
Mar 25, 2024
Member
pkozlowski-opensource
left a comment
There was a problem hiding this comment.
LGTM
Reviewed-for: public-api
Adds a couple of APIs to the `ImportedSymbolsTracker` that allow us to quickly check if a specific symbol is imported in a file.
…al checks against TypeScript files Adds the new `SourceFileValidator` that will be used to check for file-level issues that may prevent Angular from working, like invoking the `input()` function outside of an initializer. Currently only one check is planned, but this setup will allow us to easily add more in the future.
…of an initializer Adds a rule that will produce a diagnostic when an initializer-based API is used outside of an initializer. Fixes angular#54381.
…non-directive class Expands the check for initializer APIs to also flag when the function is called on a class that isn't a component or directive.
… single diagnostic Allows for `SourceFileValidatorRule.checkNode` to produce a single diagnostic. The most common case should be one diagnostic per node so this allows us to save some array allocations.
1920539 to
de4d76b
Compare
Member
Author
|
This change should be ready to go now. I've rebased, addressed the feedback and expanded the check to also cover classes that aren't components/directives. |
devversion
approved these changes
Mar 28, 2024
Contributor
|
This PR was merged into the repository by commit 336916c. |
dylhunn
pushed a commit
that referenced
this pull request
Mar 28, 2024
…al checks against TypeScript files (#54993) Adds the new `SourceFileValidator` that will be used to check for file-level issues that may prevent Angular from working, like invoking the `input()` function outside of an initializer. Currently only one check is planned, but this setup will allow us to easily add more in the future. PR Close #54993
|
This issue has been automatically locked due to inactivity. Read more about our automatic conversation locking policy. This action has been performed automatically by a bot. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Adds a diagnostic that will flag any usages of initializer APIs outside of initializers. Includes the following changes:
refactor(compiler-cli): add API to check if imports exist
Adds a couple of APIs to the
ImportedSymbolsTrackerthat allow us to quickly check if a specific symbol is imported in a file.refactor(compiler-cli): introduce infrastructure for running additional checks against TypeScript files
Adds the new
SourceFileValidatorthat will be used to check for file-level issues that may prevent Angular from working, like invoking theinput()function outside of an initializer. Currently only one check is planned, but this setup will allow us to easily add more in the future.fix(compiler-cli): add diagnostic if initializer API is used outside of an initializer
Adds a rule that will produce a diagnostic when an initializer-based API is used outside of an initializer.
fix(compiler-cli): report cases where initializer APIs are used in a non-directive class
Expands the check for initializer APIs to also flag when the function is called on a class that isn't a component or directive.
refactor(compiler-cli): allow source file validator rule to produce a single diagnostic
Allows for
SourceFileValidatorRule.checkNodeto produce a single diagnostic. The most common case should be one diagnostic per node so this allows us to save some array allocations.Fixes #54381.