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

feat: Ability to remove unused imports from multi-use statements #7815

Merged

Conversation

Wirone
Copy link
Member

@Wirone Wirone commented Feb 4, 2024

Built on top of #7814 and that PR must be merged before.

This utilises chunk-based NamespaceUseAnalysis to remove parts of the multi-use statements and can also clean whole statement if every chunk was removed.

@Wirone Wirone added kind/feature topic/fqcn Fully Qualified Class Name usage and conversions labels Feb 4, 2024
@Wirone Wirone self-assigned this Feb 4, 2024
@Wirone Wirone force-pushed the codito/grouped-unused-imports branch 2 times, most recently from f4f9b7c to e909081 Compare February 6, 2024 01:27
@Wirone Wirone marked this pull request as ready for review February 6, 2024 01:31
@coveralls
Copy link

coveralls commented Feb 6, 2024

Coverage Status

coverage: 94.78% (+0.006%) from 94.774%
when pulling 99aa87b on Wirone:codito/grouped-unused-imports
into e383c84 on PHP-CS-Fixer:master.

It was working anyway, since `$hasNonEmptyTokenBefore[0]` was always an int (first token in current line or PHP open tag's index), and when `$hasNonEmptyTokenAfter[0]` was null (nothing after an import statement) it tried to clear range with `-1` as end index, which effectively led to 0 steps in for loop. With explicit condition we only avoid stepping into `clearRange()`, but still it's better 🙂.
@Wirone Wirone force-pushed the codito/grouped-unused-imports branch from a7c6d87 to 99aa87b Compare February 8, 2024 17:04
@julienfalque julienfalque merged commit 8210c16 into PHP-CS-Fixer:master Feb 9, 2024
25 checks passed
@Wirone Wirone deleted the codito/grouped-unused-imports branch February 9, 2024 09:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/feature topic/fqcn Fully Qualified Class Name usage and conversions
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants