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

[feature_request] A way to find all unused assets #69

Open
kaciula opened this issue Nov 15, 2022 · 6 comments
Open

[feature_request] A way to find all unused assets #69

kaciula opened this issue Nov 15, 2022 · 6 comments

Comments

@kaciula
Copy link

kaciula commented Nov 15, 2022

I wish there was a way to find out if an asset is not being used anywhere in the app. If it's not being used, it makes sense for me to manually delete it and shrink the app's size.

Is this possible to be implemented? I am imagining we should somehow rely on the compiler warning that a particular generated field for an asset is not being used anywhere inside the app. What do you think?

@BirjuVachhani
Copy link
Owner

Hey, @kaciula

Thank you for opening this issue.

This sounds like a pretty useful thing. However, this is quite complicated. We can't rely on compiler warnings but we will have to run dart analyzer on the whole project and then process the result of it and look for issues in generated files to determine which assets are not being used.

I wish there was a way to find out if an asset is not being used anywhere in the app.

The analyzer shows this if you open the generated files. [If implemented] we can also show this in the terminal when build is complete (or could have separate command as well) but that's it, unless, we delete those files and references (which seems handy but I am not sure).

Despite all the complications, this sounds like a fun project and seems almost feasible. However, I don't have bandwidth to do this in near future. If someone is willing to implement then I am more than happy to guide and review it. If I get some time and by then if no one has done it then I may pick it up and do it. Or maybe not. I can't promise anything solid yet.

For that, I am keeping this issue open.

Thanks.

@BirjuVachhani BirjuVachhani added the feature indicates that a feature is requested label Nov 18, 2022
@kaciula
Copy link
Author

kaciula commented Nov 18, 2022

@BirjuVachhani Thanks for the response.

The analyzer shows this if you open the generated files.

I don't see any warnings for unused assets when I open the generated file. Please see the attachment. The playing.png asset is not being used anywhere and I do not see any warning. Am I missing something? Should it show?

Also, you don't have to manually run the analyzer. It runs automatically on the whole project. The idea however is that the analyzer does not show unused variable warning for public variables anywhere in the project. It only shows for unused private variables. So I don't know how this limitation can be overcome.

Screenshot 2022-11-18 at 14 04 16

@BirjuVachhani
Copy link
Owner

Ah! You're right! I never noticed it. I looked up this on internet and found these threads:

dart-lang/linter#1034

dart-lang/sdk#42358

Haven't read all of them comments but seems like it is kind of a big deal that no one has yet solved perfectly(except dart metrics package)

@BirjuVachhani BirjuVachhani removed the feature indicates that a feature is requested label Nov 21, 2022
@Chaitanyabsprip
Copy link

Can you not just search for Images.email in the project. It's not an optimal solution, but it is a solution.

@kaciula
Copy link
Author

kaciula commented Feb 22, 2023

Can you not just search for Images.email in the project. It's not an optimal solution, but it is a solution.

Of course. But when you have 100 images you do not have the time to go through each and every one.

@BirjuVachhani
Copy link
Owner

@kaciula is right! It may take huge amount of time to evaluate all the assets to see if they are being used or not!

Another challenge is, this cannot be done efficiently by just looking into project files programmatically. It could be that Images.email is being used in a dart file but that dart file in turn is not being used anywhere! It would be nearly impossible account for cases like this without using dart analyzer!

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

No branches or pull requests

3 participants