squizlabs / PHP_CodeSniffer

PHP_CodeSniffer tokenizes PHP files and detects violations of a defined set of coding standards.
BSD 3-Clause "New" or "Revised" License
10.66k stars 1.48k forks source link

Getting started with my own coding standard #1468

Closed GrahamLab closed 7 years ago

GrahamLab commented 7 years ago

Hi I am just starting to write my own coding standard and have followed the tutorial However when I run phpcs against the standard no error is detected What would be the best way debug this? This is my ruleset.xml and sniff

<?xml version="1.0"?>
<ruleset name="CardstreamCodingStandard">
  <description>>Rule set to implement the Cardstream coding standard</description>
</ruleset>

<?php /**

namespace PHP_CodeSniffer\Standards\MyStandard\Sniffs\Commenting;

use PHP_CodeSniffer\Sniffs\Sniff; use PHP_CodeSniffer\Files\File;

class DisallowHashCommentsSniff implements Sniff {

/**
 * Returns the token types that this sniff is interested in.
 *
 * @return array(int)
 */
public function register()
{
echo ("register")
    return array(T_COMMENT);

}//end register()

/**
 * Processes this sniff, when one of its tokens is encountered.
 *
 * @param \PHP_CodeSniffer\Files\File $phpcsFile The current file being checked.
 * @param int                         $stackPtr  The position of the current token in the
 *                                               stack passed in $tokens.
 *
 * @return void
 */
public function process(File $phpcsFile, $stackPtr)
{
echo ("process")
    $tokens = $phpcsFile->getTokens();

/ if ($tokens[$stackPtr]['content']{0} === '#') {/ $error = 'Hash comments are prohibited; found %s'; $data = array(trim($tokens[$stackPtr]['content'])); $phpcsFile->addError($error, $stackPtr, 'Found', $data); / }/

}//end process()

}//end class

?>

GrahamLab commented 7 years ago

I had named my subdirectory Snif and not Sniffs