pretty-php icon indicating copy to clipboard operation
pretty-php copied to clipboard

Add posibility to disable extensions when using preset

Open pczerkas opened this issue 1 year ago • 7 comments

This adds posibility to disable some extensions when using preset.

pczerkas avatar Aug 29 '24 22:08 pczerkas

Codecov Report

Attention: Patch coverage is 76.92308% with 3 lines in your changes missing coverage. Please review.

Project coverage is 94.80%. Comparing base (f4efe30) to head (80bedc7). Report is 30 commits behind head on main.

Files with missing lines Patch % Lines
src/App/FormatPhpCommand.php 76.92% 3 Missing :warning:
Additional details and impacted files
@@             Coverage Diff              @@
##               main     #141      +/-   ##
============================================
+ Coverage     94.43%   94.80%   +0.37%     
- Complexity     2568     2569       +1     
============================================
  Files            66       66              
  Lines          6703     6703              
============================================
+ Hits           6330     6355      +25     
+ Misses          373      348      -25     

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

codecov[bot] avatar Aug 31 '24 13:08 codecov[bot]

Thank you @lkrms - I'll try to add missing tests to cover those uncovered lines.

pczerkas avatar Aug 31 '24 14:08 pczerkas

Thank you @lkrms - I'll try to add missing tests to cover those uncovered lines.

Don't worry about that for now; CodeCov adds these comments automatically but covering every line of every PR isn't my top priority at this stage 😊

I appreciate your contribution--thank you for opening the project's first community PR! 🙏🏻

I'll come back to you once I've had a chance to weigh up the ramifications of this change from a design perspective, but in the meantime, would you mind clarifying what you're trying to achieve here? I assume there's something in the symfony preset you're wanting to enable without the limitations that (currently) come with presets, but there might be another way of approaching it.

Thanks again!

lkrms avatar Aug 31 '24 22:08 lkrms

Well, basically I need pretty-php's "symfony" preset but with imports sorted by name and not by depth.

I have other VSCode extension, which does imports sorting by name - so I thought I'll disable sorting in pretty-php and use this other extension for this.

I think it is not possible to fully reconstruct "preset" (e.g. "symfony preset") behaviour on command line basis (as a set of command line options)?

Imho, this way or another, pretty-php should either:

  • do not allow to pass mutually exclusive options (which are, in our case: "--preset" and "--no-sort-imports"; in fact any option, which disables any extension used by preset) OR
  • allow to disable some extension in conjunction with using "--preset" (which uses this particular extension)

Or maybe there is some other solution? BR

pczerkas avatar Sep 01 '24 08:09 pczerkas

@lkrms meantime I'll work on 'magento' preset (symfony based), so maybe this PR will not be needed.

pczerkas avatar Sep 02 '24 17:09 pczerkas

Thanks for clarifying what you're looking for.

pretty-php's presets aren't complete/perfect (the WordPress one is in particular need of attention), which is why they're not offered via the VS Code extension. The Symfony preset should be relatively complete, but I limited myself to requirements given here, where import order isn't mentioned. That's the only reason it maintains pretty-php's default sort order, but I'm happy to change that--in fact, I'm in the process of doing it now.

lkrms avatar Sep 02 '24 22:09 lkrms

Aside from hopefully resolving your issue, the PR I've just opened reduces the number of files in the Symfony repo that require formatting (according to pretty-php --preset=symfony) from 3302 to 2487 🙃

lkrms avatar Sep 03 '24 08:09 lkrms

Closing this because the underlying issue has been addressed separately, and because limiting the number of possible permutations of options--especially in combination with presets, which can apply internal options not surfaced via other means--is one of my goals for pretty-php as an opinionated formatter.

Happy to look at it again if a use case emerges where allowing more permutations is justified and there are no "cleaner" alternatives.

Thanks again for opening this and helping figure out a solution!

lkrms avatar Oct 09 '24 01:10 lkrms