ObliviousHarmony / vscode-php-codesniffer

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

Support PHPCS Default Standard #1

Closed ObliviousHarmony closed 3 years ago

ObliviousHarmony commented 3 years ago

Users should be able to automatically select the standard and executable using a configuration option that scans for composer.json and standard PHPCS ruleset files.

Edit: After Dan's suggestion below it makes more sense for now to just have an option that passes no standard at all and allow phpcs to decide what the default. While it would also be nice to automatically discover the phpcs executable this is less important at the moment.

ObliviousHarmony commented 3 years ago

At first glance this sounds relatively trivial thanks to our Configuration abstraction and its associated cache. We can start in the file's directory and traverse upwards until we find the root. When this doesn't work we can just fall back to the configuration options the user has set.

dhrrgn commented 3 years ago

I honestly think it could be even easier than that:

Add a new value to the StandardType enum, like Default. Then, in the worker, only add the --standard arg if request.options.standard !== 'Default'. No need to check for the config file's existence...let phpcs do that.

It might make sense to also make this the default value if phpCodeSniffer.standard is falsey (https://github.com/ObliviousHarmony/vscode-php-codesniffer/blob/main/src/configuration.ts#L106)

ObliviousHarmony commented 3 years ago

Hey @dhrrgn,

That's a pretty good idea. My thinking was we could kill two birds with one stone here by also inferring the phpcs location, but either way that is a good suggestion.