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

Report unused standalone imports #46766

Closed
Lonli-Lokli opened this issue Jul 9, 2022 · 25 comments
Closed

Report unused standalone imports #46766

Lonli-Lokli opened this issue Jul 9, 2022 · 25 comments
Assignees
Labels
area: core Issues related to the framework runtime area: language-service Issues related to Angular's VS Code language service core: directive matching cross-cutting: standalone Issues related to the NgModule-less world feature: under consideration Feature request for which voting has completed and the request is now under consideration feature Issue that requests a new feature
Milestone

Comments

@Lonli-Lokli
Copy link

Which @angular/* package(s) are relevant/related to the feature request?

common

Description

With the popularity of standalone components (pipes/directives), powered by Angular as well, there is a possibility that some components will be unused in templates while still imported by parent component, and so will increase bundle

Proposed solution

Report during the build that some.pipe/directive is imported but not used.
It can be controlled via angulqrCompilerOptions of tsconfig

Alternatives considered

Nothing

@pkozlowski-opensource
Copy link
Member

It is in the works :-)

@jessicajaniuk jessicajaniuk added the area: common Issues related to APIs in the @angular/common package label Jul 11, 2022
@ngbot ngbot bot added this to the needsTriage milestone Jul 11, 2022
@pkozlowski-opensource pkozlowski-opensource added area: core Issues related to the framework runtime core: directive matching cross-cutting: standalone Issues related to the NgModule-less world and removed area: common Issues related to APIs in the @angular/common package labels Jul 12, 2022
@pkozlowski-opensource pkozlowski-opensource added feature Issue that requests a new feature area: language-service Issues related to Angular's VS Code language service labels Sep 28, 2022
@ngbot ngbot bot modified the milestones: needsTriage, Backlog Sep 28, 2022
@angular-robot angular-robot bot added the feature: votes required Feature request which is currently still in the voting phase label Sep 28, 2022
@angular-robot
Copy link
Contributor

angular-robot bot commented Sep 28, 2022

Just a heads up that we kicked off a community voting process for your feature request. There are 20 days until the voting process ends.

Find more details about Angular's feature request process in our documentation.

@angular-robot
Copy link
Contributor

angular-robot bot commented Oct 17, 2022

Thank you for submitting your feature request! Looks like during the polling process it didn't collect a sufficient number of votes to move to the next stage.

We want to keep Angular rich and ergonomic and at the same time be mindful about its scope and learning journey. If you think your request could live outside Angular's scope, we'd encourage you to collaborate with the community on publishing it as an open source package.

You can find more details about the feature request process in our documentation.

@angular-robot angular-robot bot added feature: insufficient votes Label to add when the not a sufficient number of votes or comments from unique authors and removed feature: votes required Feature request which is currently still in the voting phase labels Oct 17, 2022
@MaximSagan
Copy link

@pkozlowski-opensource Is this still in the works, or should we take @angular-robot's comment to mean that this won't be done?

@pkozlowski-opensource
Copy link
Member

@MaximSagan I've removed the angular-robot comment - this is something we would love to address.

@pkozlowski-opensource pkozlowski-opensource removed the feature: insufficient votes Label to add when the not a sufficient number of votes or comments from unique authors label Nov 11, 2022
@Lonli-Lokli
Copy link
Author

@pkozlowski-opensource do you know the statistics of issues which pass votes? Seems like 20 votes is too much...

@angular-robot angular-robot bot added the feature: votes required Feature request which is currently still in the voting phase label Nov 11, 2022
@angular-robot

This comment was marked as outdated.

@angular-robot angular-robot bot added feature: insufficient votes Label to add when the not a sufficient number of votes or comments from unique authors and removed feature: votes required Feature request which is currently still in the voting phase labels Nov 11, 2022
@Lonli-Lokli
Copy link
Author

Seems like script for bot wasn't tested enough;)

@MaximSagan
Copy link

Seems like script for bot wasn't tested enough;)

@pkozlowski-opensource

@JoostK JoostK added feature: under consideration Feature request for which voting has completed and the request is now under consideration and removed feature: insufficient votes Label to add when the not a sufficient number of votes or comments from unique authors labels Nov 11, 2022
@DaSchTour
Copy link

Will this also be possible for NgModules?

@mpontreau
Copy link

Any news about this cool feature ? :)

@crowmagnumb
Copy link

I want to reopen the pollling! I wasn't using Stand-Alone components until now and now I really want to have an auto-cleanup of unused components. :)

@DanKing123
Copy link

DanKing123 commented Jul 11, 2023

This seems like it should be a pretty major thing now, especially with more and more people moving to standalone components?

So easy to end up with left-over imports hanging around that aren't needed anymore - especially if/when code gets copy-pasted from one component to another - and no easy way to auto-detect these, unless there is some other way I don't know about?

It's also quite difficult to do manually - especially if you have a lot of components, and especially since the imports and the templates that use them are usually in different files.

@JoostK
Copy link
Member

JoostK commented Jul 11, 2023

This seems like it should be a pretty major thing now, especially with more and more people moving to standalone components?

So easy to end up with left-over imports hanging around that aren't needed anymore - especially if/when code gets copy-pasted from one component to another - and no easy way to auto-detect these, unless there is some other way I don't know about?

It's also quite difficult to do manually - especially if you have a lot of components, and especially since the imports and the templates that use them are usually in different files.

This problem is not new to standalone; NgModules have always had those same challenges.

@crowmagnumb
Copy link

This seems like it should be a pretty major thing now, especially with more and more people moving to standalone components?
So easy to end up with left-over imports hanging around that aren't needed anymore - especially if/when code gets copy-pasted from one component to another - and no easy way to auto-detect these, unless there is some other way I don't know about?
It's also quite difficult to do manually - especially if you have a lot of components, and especially since the imports and the templates that use them are usually in different files.

This problem is not new to standalone; NgModules have always had those same challenges.

Yes but this one is more easily solvable it seems. Also not an excuse. :)

@styriandev
Copy link

Yes, I would also like to mention that this is getting more important because of standalone components being used by more people. Here in my company, as we like to don't have imports that we do actually not need we have an additional code review step to check if the components imported by a component are actually used. That takes some time and I guess in terms of dev experience it would be great to instantly know if an import is used or not. This becomes important especially in projects where there is some continues refactoring going on. We had that for example when we migrated components to use the standalone paradigm and by that we also tried to refactor some parts, that ended up in some imports not needed anymore and it was some effort to find these imports...

So to sum up, I would also vote for this issue from the current point of view.

@xinthose
Copy link

standalone is default in Angular v17 now, so this warning would be convenient

@jahusa02
Copy link

Are there any updates?

@eglove

This comment was marked as off-topic.

@n0futur3
Copy link

n0futur3 commented May 6, 2024

Definitively a MUST HAVE these days with Angular 17+
Come on!

@s0h311
Copy link

s0h311 commented May 21, 2024

@pkozlowski-opensource Any news about this?

@kelvinsleonardo
Copy link

Any updates on this?

@PowerKiKi
Copy link
Contributor

PowerKiKi commented Jun 13, 2024

This issue is annoying, because it possibly increases the compile time and bundle size. But the other side of this issue, where an import is missing, as reported in #46351, is much more critical, because it can lead to runtime "missing behavior" without any errors or warnings, neither at build time or at runtime.

@clem4net
Copy link

clem4net commented Jun 24, 2024

I think this is an important feature for projects.
It does not necessarily need to be in simple compilation (to maintain performance) => This could be an option or an specific command.

@t-mish

This comment has been minimized.

crisbeto added a commit to crisbeto/angular that referenced this issue 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": {
        "unusedStandaloneDeclarations": "suppress"
      }
    }
  }
}
```

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

Fixes angular#46766.
@crisbeto crisbeto self-assigned this Aug 30, 2024
crisbeto added a commit to crisbeto/angular that referenced this issue 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": {
        "unusedStandaloneDeclarations": "suppress"
      }
    }
  }
}
```

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

Fixes angular#46766.
crisbeto added a commit to crisbeto/angular that referenced this issue 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": {
        "unusedStandaloneDeclarations": "suppress"
      }
    }
  }
}
```

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

Fixes angular#46766.
crisbeto added a commit to crisbeto/angular that referenced this issue Sep 2, 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": {
        "unusedStandaloneDeclarations": "suppress"
      }
    }
  }
}
```

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

Fixes angular#46766.
crisbeto added a commit to crisbeto/angular that referenced this issue Sep 3, 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"
      }
    }
  }
}
```

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

Fixes angular#46766.
crisbeto added a commit to crisbeto/angular that referenced this issue Sep 3, 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"
      }
    }
  }
}
```

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

Fixes angular#46766.
mvdluit pushed a commit to mvdluit/angular that referenced this issue Sep 5, 2024
…#57605)

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.

PR Close angular#57605
and-oli pushed a commit to and-oli/angular that referenced this issue Sep 30, 2024
…#57605)

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.

PR Close angular#57605
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: core Issues related to the framework runtime area: language-service Issues related to Angular's VS Code language service core: directive matching cross-cutting: standalone Issues related to the NgModule-less world feature: under consideration Feature request for which voting has completed and the request is now under consideration feature Issue that requests a new feature
Projects
None yet
Development

Successfully merging a pull request may close this issue.