Thanks to visit codestin.com
Credit goes to github.com

Skip to content

feat(compiler): add diagnostic for unused standalone imports #57605

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

Closed
wants to merge 2 commits into from

Conversation

crisbeto
Copy link
Member

@crisbeto crisbeto commented Aug 30, 2024

Adds a new diagnostic that will report cases where a declaration is in the imports array, but isn't being used anywhere. The diagnostic is reported as a warning by default and can be controlled using the following option in the tsconfig:

{
  "angularCompilerOptions": {
    "extendedDiagnostics": {
      "checks": {
        "unusedStandaloneImports": "suppress"
      }
    }
  }
}

Fixes #46766.

@crisbeto crisbeto added action: review The PR is still awaiting reviews from at least one requested reviewer target: major This PR is targeted for the next major release area: compiler Issues related to `ngc`, Angular's template compiler labels Aug 30, 2024
@ngbot ngbot bot added this to the Backlog milestone Aug 30, 2024
@angular-robot angular-robot bot added the detected: feature PR contains a feature commit label Aug 30, 2024
@crisbeto crisbeto force-pushed the unused-decls branch 2 times, most recently from c77400d to c55f855 Compare August 30, 2024 14:37
@crisbeto crisbeto marked this pull request as ready for review August 30, 2024 14:59
@pullapprove pullapprove bot requested review from alxhub, atscott and dylhunn August 30, 2024 14:59
@angular-robot angular-robot bot added the area: language-service Issues related to Angular's VS Code language service label Sep 2, 2024
@crisbeto
Copy link
Member Author

crisbeto commented Sep 2, 2024

Pushed a change to add an automatic code fix to the language service.

* Whether the rule to check for unused standalone declarations is enabled.
* Used to disable it conditionally in internal builds.
*/
export const UNUSED_STANDALONE_DECLARATIONS_RULE_ENABLED = true;
Copy link
Member Author

Choose a reason for hiding this comment

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

Context for this is that the new rule is somewhat breaking internally. This flag is in a separate file so we can easily apply a patch to disable it.

@crisbeto crisbeto added the merge: caretaker note Alert the caretaker performing the merge to check the PR for an out of normal action needed or note label Sep 2, 2024
@crisbeto
Copy link
Member Author

crisbeto commented Sep 2, 2024

Caretaker note: these changes require a new patch internally. The patch is in cl/670184686

Copy link
Member

@alxhub alxhub left a comment

Choose a reason for hiding this comment

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

Reviewed-for: public-api

Copy link
Contributor

@atscott atscott left a comment

Choose a reason for hiding this comment

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

reviewed-for: public-api

Adds a new diagnostic that will report cases where a declaration is in the `imports` array, but isn't being used anywhere. The diagnostic is reported as a warning by default and can be controlled using the following option in the tsconfig:

```
{
  "angularCompilerOptions": {
    "extendedDiagnostics": {
      "checks": {
        "unusedStandaloneImports": "suppress"
      }
    }
  }
}
```

**Note:** I'll look into a codefix for the language service in a follow-up.

Fixes angular#46766.
Adds an automatic code fix to the language service that will remove unused standalone imports.
@crisbeto crisbeto added action: merge The PR is ready for merge by the caretaker and removed action: review The PR is still awaiting reviews from at least one requested reviewer labels Sep 3, 2024
@AndrewKushnir
Copy link
Contributor

This PR was merged into the repository by commit 8da9fb4.

The changes were merged into the following branches: main

AndrewKushnir pushed a commit that referenced this pull request Sep 3, 2024
…57605)

Adds an automatic code fix to the language service that will remove unused standalone imports.

PR Close #57605
@angular-automatic-lock-bot
Copy link

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Oct 4, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
action: merge The PR is ready for merge by the caretaker area: compiler Issues related to `ngc`, Angular's template compiler area: language-service Issues related to Angular's VS Code language service detected: feature PR contains a feature commit merge: caretaker note Alert the caretaker performing the merge to check the PR for an out of normal action needed or note target: major This PR is targeted for the next major release
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Report unused standalone imports
4 participants