-
I was working on a standard with some custiom sniffs and I (finally) have it loading and running, however when using an option that outputs the sniff name such as --report-source it isn't outputting the name like I would like. .phpcs.xml<?xml version="1.0"?>
<ruleset xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" name="mLinks Coding Standard" xsi:noNamespaceSchemaLocation="vendor/squizlabs/php_codesniffer/phpcs.xsd">
<description>The coding standard for mLinks.</description>
<arg name="extensions" value="php" />
<arg name="basepath" value="."/>
<!-- Makes it so that warnings don't impact the exit code of phpcs -->
<config name="ignore_warnings_on_exit" value="1"/>
<rule ref="./plugins/cs/Mlinks" />
</ruleset> plugins/cs/Mlinks/ruleset.xml<?xml version="1.0"?>
<ruleset xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" name="mLinks Coding Standard" namespace="mlinks\cs" xsi:noNamespaceSchemaLocation="../../../vendor/squizlabs/php_codesniffer/phpcs.xsd">
<description>The coding standard for mLinks.</description>
<arg name="extensions" value="php" />
<arg name="basepath" value="."/>
<rule ref="mlinks.NameValidation.ValidVariableName" />
</ruleset> When I run this on a file that reports an error and use --report-source, I get the following output:
I was hoping that the first part that reads "standard" would instead show the standard's name: Mlinks. Did I miss this in the documentation as well? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 6 replies
-
@kczx3 Please have a look at https://github.com/PHPCSStandards/PHP_CodeSniffer/wiki/Coding-Standard-Tutorial and https://github.com/PHPCSStandards/PHP_CodeSniffer/wiki/Annotated-Ruleset (bit at the very top) The naming conventions have to be strictly followed for things to work as expected. Based on the above, I can already see two things wrong in the
Other things to double-check:
If you would have posted a link to the project, I could have given you more specific information. As it is, these are the hints I can give you based on the above. |
Beta Was this translation helpful? Give feedback.
-
Namespace for ValidFunctionNameSniff is I think I've got it now. |
Beta Was this translation helpful? Give feedback.
Hmm... that doesn't sound right.
As per the links I gave you before, there are strict naming requirements, so basically your file, directory and namespace structure should look like this:
ruleset.xml
mlinks\Sniffs\*
*Sniff.php
NameValidation
, the * in the file name is the sniff name, likeValidVariableName
If you want a prefix for your namespace name, so
Something\mlinks\Sniffs\Category
, you can indicate that in thenamespace
attribute in theruleset.xml
fi…