Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Any way to ignore Missing file doc comment errors #1348

Closed
ankitjain28may opened this issue Feb 14, 2017 · 14 comments
Closed

Any way to ignore Missing file doc comment errors #1348

ankitjain28may opened this issue Feb 14, 2017 · 14 comments

Comments

@ankitjain28may
Copy link

No description provided.

@nisevi
Copy link

nisevi commented Feb 14, 2017

@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

@gsherwood
Copy link
Member

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).

@nisevi
Copy link

nisevi commented Feb 14, 2017

@gsherwood I will try to do it as you say 👍 ... I haven't realized that this was no more a way to go.

@ankitjain28may
Copy link
Author

Can you please post an example to ignore the doc's errors

@gsherwood
Copy link
Member

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

@dhirans65
Copy link

@gsherwood can you please explain every single procedure to use that ruleset.xml with PHPCS.
thank you

@gsherwood
Copy link
Member

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

@cwilby
Copy link

cwilby commented Feb 2, 2020

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>

@bilalkhan13
Copy link

bilalkhan13 commented Feb 3, 2020

Thank You!

@ankitjain28may
Copy link
Author

You can also try something like this--

php vendor/bin/phpcs --standard=PSR2 ./app

@rendybiz
Copy link

rendybiz commented Jan 26, 2021

I just need to put "phpcs.xml" to my root project folder.
below is my phpcs.xml

<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>```

@joemags-apps
Copy link

<?xml version="1.0"?>
<ruleset name="CustomStandard">
    <description>Custom laravel coding standard.</description>
    <rule ref="PEAR">
        <exclude name="PEAR.Commenting.FileComment.Missing"/>
    </rule>
</ruleset>

This worked for me.

@emersonTeixeiraDev
Copy link

onde eu coloco esse código ?

@jrfnl
Copy link
Contributor

jrfnl commented Mar 21, 2023

@emersonTeixeiraDev If you expect an answer, you may want to try to write the question in English....

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

10 participants