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

fix(select-style): remove unused imports after fixing violations #218

Conversation

rafaelss95
Copy link
Collaborator

@rafaelss95 rafaelss95 commented Sep 19, 2021

@timdeschryver I took the liberty of submitting this PR as a draft in an attempt to finally clean up any traces of unused imports.

In a short, it basically lookup for the node import import { ..., select } from '@ngrx/platform' and then it grab the references that points to this node. Note that the same approach could be used for no-effect-creator-and-decorator, no-effect-decorator and prefer-concat-latest-from. Let me know what you think.

Comment on lines 184 to 185
fixer.remove(parent),
...(nextToken ? [fixer.remove(nextToken)] : []),
fixer.insertTextAfter(storeNode, `.${text}`),
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I've improved the fixers so it's not dependant on a well-formatted code, instead of decreasing -1 or adding +1 to find the expected range (which may cause a lot of breakage - because it all depends on how one format their code), it looks for the closest node through the souceCode.getTokenBefore/After.

@rafaelss95 rafaelss95 force-pushed the fix/maybe-finally-remove-unused-imports branch 5 times, most recently from 437abd0 to f8869a7 Compare September 19, 2021 04:06
Copy link
Owner

@timdeschryver timdeschryver left a comment

Choose a reason for hiding this comment

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

I like this a lot, smart!
I think it's much better than what we currently have and what was proposed before.

The only downside is that if someone fixes the import, they will get errors because select is still being used, correct?
I'm fine with that though, just wanted to make sure.

EDIT: Or should the import fix and the usage fix be separated in order to fix this? E.g. that the import fix is only proposed when there are no declared variables 🤔

@rafaelss95
Copy link
Collaborator Author

Hmm.. I got your concern, but IMHO, fixes, unlike suggestions are usually applied automatically, by saving a file if you've configured your IDE for that, or running via the CLI (manual or pre-commit hook or something like that)... so I assume that it's only a problem if you try to fix every occurrence by hand 🤔.

I don't know... should we bother with this? 😅

@timdeschryver
Copy link
Owner

We shouldn't be bothered with this, at least not for now.
This can be shipped for me 🚀

@rafaelss95 rafaelss95 force-pushed the fix/maybe-finally-remove-unused-imports branch from f8869a7 to 778f4b8 Compare September 23, 2021 19:36
@rafaelss95 rafaelss95 marked this pull request as ready for review September 23, 2021 19:38
@timdeschryver timdeschryver merged commit add14de into timdeschryver:main Sep 24, 2021
@github-actions
Copy link

🎉 This PR is included in version 1.42.1 🎉

The release is available on:

Your semantic-release bot 📦🚀

@rafaelss95 rafaelss95 deleted the fix/maybe-finally-remove-unused-imports branch September 24, 2021 11:40
@timdeschryver
Copy link
Owner

Fyi, I just tested this in a real application and it works as a charm! Thanks @rafaelss95 🏆

@rafaelss95
Copy link
Collaborator Author

How dare you not believe only in tests? Hahaha, just kidding. Glad to see that it works in a real app 😄

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

Successfully merging this pull request may close these issues.

None yet

2 participants