ikappas / vscode-phpcs

PHP CodeSniffer for Visual Studio Code
MIT License
128 stars 56 forks source link

Add "extensions" configuration setting #172

Open theteknocat opened 4 years ago

theteknocat commented 4 years ago

Offer this to resolve #159. I'm not 100% sure if I got it right. I was able to hack my installed version of the extension to make this work, and did my best to copy those changes to the source code.

I hope this can be modified to work and accepted, as many people will find this helpful, especially those who work with Drupal that uses a number of different file extensions for PHP code.

davids4 commented 4 years ago

Thanks for that @theteknocat, I think that's what I've been looking for a while. The patch looks good, but how can we test it or use it? I'm installing the extension through the VS Code installer. Is there another way I could install the extension from your pull request? Thanks again!

theteknocat commented 4 years ago

@davids4 that's a great question. I don't actually know how the source code for the extensions gets compiled out into the final shipping version of the Javascript code that's used for the VSCode extension. I haven't built extensions for VSCode before, nor worked with this particular kind of codebase.

What I did was modified my copy of the extension first, by going into ~/.vscode/extensions/ikappas.phpcs-1.0.5 and editing the appropriate files. I then cloned a copy of the git repo and made the same kinds of changes in the source code files so that I could commit that and create this pull request.

If anyone knows how to compile it into the ready to use VSCode extension, I'd love to hear about it too.

In the meantime, I have attached a zipped up copy of my modified extension that you can use right now until such time as this (hopefully) gets merged and included in a future version of the extension that you can just install/update with VSCode extension manager. Unzip the attached file and overwrite ~/.vscode/extensions/ikappas.phpcs-1.0.5 with the contents of the zip.

Unfortunately if you reinstall via the extension manager, or install an update that way later on, this will be overwritten.

ikappas.phpcs-1.0.5.zip

davids4 commented 4 years ago

Thanks so much @theteknocat! I was doing just that :D :+1: haha Using your commit to patch the extension locally, based on the file names, paths, etc... :D

You saved me quite some time and during which I was able to test your zipped package of the patched extension. I set my configuration in my vscode settings.json as follows: "phpcs.extensions": [ "engine", "inc", "install", "make", "module", "profile", "theme", "tpl.php", "test", "php", ], and everything seems to be working fine for all of my file extensions.

I have attached a patch as well to the VSCode extension: ikappas-vscode-phpcs-pullr-172-1.zip

Hopefully your pull request will be approved and we'll be able to use this feature as part of the next update in vscode's marketplace. Thanks again very much! Cheers!

theteknocat commented 2 years ago

@ikappas any chance you will consider accepting this pull request and including this feature in a future release of the VSCode extension?

wakkoism commented 2 years ago

Is there a reason not used a phpcs.xml file for adding extension in the working project directory? I've used the zipped file at one point and it worked great, but really not needed as you can get around that by defining how you want your phpcs to code sniff.

theteknocat commented 2 years ago

Is there a reason not used a phpcs.xml file for adding extension in the working project directory? I've used the zipped file at one point and it worked great, but really not needed as you can get around that by defining how you want your phpcs to code sniff.

Oh, ha! No reason at all, I just wasn't aware of that. Perhaps that actually makes more sense.

jaybabak commented 1 year ago

I think for many people as #159 points out, it is problematic to add a phpcs.xml file and better to provide a configurable form/option to choose which extensions should be checked through the UI - better user experience over all since this is an extension and can provide this added functionality. User can always add a phpcs.xml file so this is an enhancement over existing functionality.

theteknocat commented 1 year ago

@jaybabak that's true, though there are so many different configuration options you may need, depending on your specific situation, plus the configuration is often project-specific. If you work with a team of people and you need to ensure that everyone is using the same PHPCS configuration for each project, then the best option is to use phpcs.xml file in the repository that you commit or setup a pre-commit hook to do the linting with your specified configuration to ensure everyone on the team is meeting the right coding standards. Those solutions are great especially if different devs on the team aren't all using the same coding software or IDE. We have a contractor, for example, who uses PHPStorm. So we just require that he has PHPCS installed and configured and the phpcs.xml file will allow it to correctly lint his code.

However, as you say that is not necessarily feasible for everyone. So if the vscode extension also allowed every conceivable configuration option, including this one in particular, then any given developer can use whatever means works best for them in their situation.