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

[New Analyzer] Ability to check for unused assets #816

Open
AbhishekDoshi26 opened this issue Apr 27, 2022 · 4 comments
Open

[New Analyzer] Ability to check for unused assets #816

AbhishekDoshi26 opened this issue Apr 27, 2022 · 4 comments
Assignees
Labels

Comments

@AbhishekDoshi26
Copy link

Summary

So one of the main reasons for increased app size is assets. While developing, we constantly keep on adding some images or fonts that our client wants and when it changes, we forget to remove the unused assets.
This analyzer (not linter rule) would provide the list of all the assets that we have not used in the project.

Possible Solution

  • Fetch the list of assets available in pubspec.yaml or assets folder (if the developer has simply imported assets/).
  • Search for the relative path or file name in the entire project to find its usage.
  • If the developer has used asset generation packages, we can check for the unused asset variables.

What category of rule is this? (place an "X" next to just one item)

[ ] Warns about a potential error (problem)
[ ] Suggests an alternate way of doing something (suggestion)
[x] Other (please specify:)

Are you willing to submit a pull request to implement this rule? I don't have much idea about how to write the script but if guided, definitely!

@incendial
Copy link
Member

So, the problem we got stuck earlier is - if a path to asset is combined with variables and the user has several assets having the same name, but located in different sub-directories, then how to properly notify the user, which one of the assets is not used?

For example,

  • first asset assets/icons/settings.png
  • second asset assets/background/settings.png

and then in code

final path = '...'
final pathToAsset = '$path/settings.png'

What if even the path variable is combined from other variables?

@incendial incendial added type: enhancement New feature or request area-commands labels Apr 28, 2022
@AbhishekDoshi26
Copy link
Author

Okk yes this can be possible. So I think in this case, we will have to use the concept of macros (not exactly macros, but just an example) so if the analyzer finds that the path is containing a variable or a non-constant string, replace that variable with the value of variable.

I understand this can be real challenging.

@talisk
Copy link

talisk commented May 6, 2022

Okk yes this can be possible. So I think in this case, we will have to use the concept of macros (not exactly macros, but just an example) so if the analyzer finds that the path is containing a variable or a non-constant string, replace that variable with the value of variable.

I understand this can be real challenging.

Maybe there is something wrong with your thinking? How to determine the value of variable or a non-constant string? And what value we should use? The value may be requested from the server.

@talisk
Copy link

talisk commented May 6, 2022

I think the analyzer should determine which assets must be used. Then the others may not be used. But we have no way to confirm. Because the factors that affect the variables may be the data from server, or the user's operation.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

4 participants