ObliviousHarmony / vscode-php-codesniffer

A VS Code extension for integrating PHP_CodeSniffer.
https://marketplace.visualstudio.com/items?itemName=obliviousharmony.vscode-php-codesniffer
Other
40 stars 2 forks source link

[FR] Allow separate configs for `phpcs` and `phpcbf` #56

Closed alessandro-newzoo closed 1 year ago

alessandro-newzoo commented 1 year ago

Hello,

Thank you so much for this extension, it works beautifully!

I was wondering, would it be possible to define two separate configs for phpcs and phpcbf?

Specifically, I'd like to use WordPress standard for phpcbf, and another standard for phpcs. I like WordPress' way of formatting, but the linting is way too picky to work with so I'd like to use a more common standard for that.

Something that would basically allow this kind of settings:

  "phpSniffer.phpcbf.standard": "WordPress",
  "phpSniffer.phpcs.standard": "PEAR"

Thanks! Alessandro

ObliviousHarmony commented 1 year ago

Hi @alessandro-newzoo,

Could you expand a bit on your rationale for using separate configs? You're saying that you want formatting to be done against a different standard than the one your editor shows?

Realistically speaking, the point of a linter is to enforce consistent formatting and standards. Having separate warnings and errors show in your IDE than your automatic fixing seems to run counter to that purpose.

Since you find the WordPress standard to be heavy-handed, what about configuring a phpcs.xml file that disables the rules you don't want? You can remove sniffs that don't suit your project and develop something more personalized? This is also nice to have in your repository so that anyone else working will have your modified rules to follow.

alessandro-newzoo commented 1 year ago

Hi @ObliviousHarmony !

The reason of my request was that I like how the WordPress standard formats the code, for example it formats arrays like this:

$args = array(
    'post_type'           => 'clients',
    'posts_per_page'      => 20,
    'post_status'         => 'publish',
    'orderby'             => 'rand',
    'ignore_sticky_posts' => true,
    'meta_query'          => array(
        array(
            'key'     => 'footer_slider',
            'value'   => true,
            'compare' => '=',
        ),
    ),
);

But it also shows a whopping 185 problems in the linter which I don't care about, whereas if using PSR12 it only shows 5, but the problem is that PSR12 won't care about formatting the arrays.

So to sum it up, I like how WordPress makes things look, and how PSR12 lints looking for errors in the code without caring about the formatting.

Right now to achieve this I have to use Intelephense (which follows PSR12 standards) for the linting, and PHPCS for the visual style/formatting. This combo works fine, but Intelephense is quite taxing so I would have loved to get rid of it and keep everything under the same umbrella.

Maybe I don't understand how these things work and I'm talking out of my a**, and if that's the case I apologise 😄

alessandro-newzoo commented 1 year ago

@ObliviousHarmony my God I'm such a moron, I just realised I'm using this extension and not yours: https://github.com/wongjn/vscode-php-sniffer

I have no clue how I have landed here, how embarrassing I'm sorry! :( Please disregard this!