@ankitjain28may I just found a nice way to setup a custom standard
Go to the directory where the phpcs coding standards are defined:
> cd /usr/share/php/PHP/CodeSniffer/Standards
Create a new directory for your new standard:
> sudo mkdir PEARish
> cd PEARish
Create your new standard by saving the following in the file:
> sudo emacs PEARishCodingStandard.php
<?php
class PHP_CodeSniffer_Standards_PEARish_PEARishCodingStandard extends PHP_CodeSniffer_Standards_CodingStandard
{
public function getIncludedSniffs()
{
return array('PEAR');
}
public function getExcludedSniffs()
{
return array('PEAR/Sniffs/Commenting/FileCommentSniff.php');
}
}
?>
Test your new customised coding standard by invoking phpcs using the --standard flag. For example:
> phpcs --standard=PEARish Test.php
Once it is working you can set your new standard as the default which means you don't need to type the --standard flag each time you use phpcs:
> sudo phpcs --config-set default_standard PEARish
That information is very very old. You use a ruleset.xml file since version 1.3.
Take a look at the annotated ruleset in the wiki and exclude the specific error codes you don't want to use.
If you can't figure it out, I'll post an example tomorrow (it's late where I am, and I'm on a phone).
@gsherwood I will try to do it as you say :+1: ... I haven't realized that this was no more a way to go.
Can you please post an example to ignore the doc's errors
Can you please post an example to ignore the doc's errors
I don't know what coding standard you are currently using, so this example assumes you are using the default standard (PEAR).
<?xml version="1.0"?>
<ruleset name="MyStandard">
<description>My custom coding standard.</description>
<rule ref="PEAR">
<exclude name="PEAR.Commenting.FileComment.Missing"/>
</rule>
</ruleset>
Save that as a file called ruleset.xml and use that with PHPCS: phpcs --standard=ruleset.xml /path/to/code
@gsherwood can you please explain every single procedure to use that ruleset.xml with PHPCS.
thank you
can you please explain every single procedure to use that ruleset.xml with PHPCS
The comment above was basically everything. You create a new file called ruleset.xml (or whatever name you want) and make the contents what I posted.
When running PHPCS, you use the --standard command line argument to tell PHPCS where the file is. So if you created your file at /home/jsmith/project/ruleset.xml then you run phpcs using the command phpcs --standard=/home/jsmith/project/ruleset.xml
You can also use a specific ruleset by adding a phpcs.xml to your project. Here's one I'm using in a Laravel project, works in Visual Studio Code with PHPCS extension installed.
<?xml version="1.0" ?>
<ruleset name="PSR2">
<description>The PSR2 coding standard.</description>
<rule ref="PSR2" />
<file>app/</file>
<exclude-pattern>vendor</exclude-pattern>
<exclude-pattern>resources</exclude-pattern>
<exclude-pattern>database/</exclude-pattern>
<exclude-pattern>storage/</exclude-pattern>
<exclude-pattern>node_modules/</exclude-pattern>
</ruleset>
Thank You!
You can also try something like this--
php vendor/bin/phpcs --standard=PSR2 ./app
I just need to put "phpcs.xml" to my root project folder.
below is my phpcs.xml
<?xml version="1.0"?>
<ruleset name="MyStandard">
<description>My custom coding standard.</description>
<rule ref="PEAR">
<exclude name="PEAR.NamingConventions.ValidFunctionName"/>
<exclude name="PEAR.NamingConventions.ValidVariableName"/>
<exclude name="PEAR.Commenting.ClassComment"/>
<exclude name="Generic.Commenting.DocComment.MissingShort"/>
<exclude name="PEAR.Commenting.ClassComment.Missing"/>
<exclude name="PEAR.Commenting.FileComment.Missing"/>
<exclude name="PEAR.Commenting.FunctionComment.Missing"/>
<exclude name="PEAR.Functions.FunctionCallSignature.ContentAfterOpenBracket"/>
<exclude name="PEAR.Functions.FunctionCallSignature.CloseBracketLine"/>
<exclude name="PEAR.NamingConventions.ValidFunctionName.PrivateNoUnderscore"/>
<exclude name="PEAR.Commenting.FileComment.MissingCategoryTag"/>
<exclude name="PEAR.Commenting.FileComment.MissingPackageTag"/>
<exclude name="PEAR.Commenting.FileComment.MissingLinkTag"/>
<exclude name="PEAR.Commenting.FileComment.MissingVersion"/>
<exclude name="PEAR.Commenting.InlineComment"/>
</rule>
</ruleset>
Most helpful comment
You can also use a specific ruleset by adding a
phpcs.xmlto your project. Here's one I'm using in a Laravel project, works in Visual Studio Code with PHPCS extension installed.