ikappas / vscode-phpcs

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

How to configure this rule: SpaceAfterNot #178

Closed yamenarahman closed 4 years ago

yamenarahman commented 4 years ago

How can I add this rule: <rule ref="Generic.Formatting.SpaceAfterNot" />

eclipxe13 commented 4 years ago

Hi @yamenarahman, check the documentation on https://github.com/squizlabs/PHP_CodeSniffer/wiki/Customisable-Sniff-Properties#genericformattingspaceafternot

You can use it on your configuration file phpcs.xml like this:

<?xml version="1.0"?>
<ruleset name="PersonalPhpCs">
  <rule ref="PSR2"/> <!-- based on PSR2 -->
  <!-- ... more configuration ... -->
  <rule ref="Generic.Formatting.SpaceAfterNot"/>
</ruleset>

Here's a working example with many other rules: https://github.com/eclipxe13/enum/blob/master/phpcs.xml.dist

yamenarahman commented 4 years ago

@eclipxe13 Thanks for your reply, one last question:

How can I make this rule global so I don't have to put phpcs.xml in every project?

Where can I find the root file or global phpcs.xml? if it's located in composer global packages, how can I protect this file from resetting when I self-update or upgrade composer global packages?

Thanks.

eclipxe13 commented 4 years ago

How can I make this rule global so I don't have to put phpcs.xml in every project?

I don't like globals, but that is not the point. Make your own standard and put the rules equally available as PSR2, I think doctrine/coding-standard might inspire you. So, If you are installing phpcs globally your standards can also be installed the same way.

Where can I find the root file or global phpcs.xml?

phpcs includes some standards, check vendor/squizlabs/php_codesniffer/src/Standards/

how can I protect this file from resetting when I self-update or upgrade composer global packages?

When run phpcs (globally or locally installed) it will search for different config files (ruleset.xml, ruleset.xml.dist, phpcs.xml, phpcs.xml.dist) and will take the first it can find. It is a configuration file, so it will not be overriden or removed, but it could be incompatible with new phpcs versions.

A few notes:

I hope I provided you some guidance, but I will not answer a very off-topic issue.

yamenarahman commented 4 years ago

Thanks for your time @eclipxe13 Appreciated!