Skip to content
This repository has been archived by the owner on Sep 19, 2023. It is now read-only.

Commit

Permalink
Reconfigured code sniffer to use vendor libs for wpcs and phpcs, upda…
Browse files Browse the repository at this point in the history
…te PSR2 to make comment required
  • Loading branch information
aprokopenko committed Nov 15, 2017
1 parent f3b2d16 commit b86aa57
Show file tree
Hide file tree
Showing 597 changed files with 99 additions and 77,251 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
.DS_Store
.idea
.idea
/vendor
/composer.lock
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@
Installation instructions:

1. Clone repository on your drive
2. Run `composer install`
2. Run: `chmod +x phpcsx phpmd`
3. Configure your PhpStorm to use both scripts
22 changes: 22 additions & 0 deletions bin/phpcsx-init
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#!/usr/bin/env php
<?php

$root = dirname(__FILE__) . '/..';

require_once $root . '/vendor/squizlabs/php_codesniffer/autoload.php';

$argv = [
$_SERVER['argv'][0],
'--config-set',
'installed_paths',
implode(',', array(
$root . '/vendor/wp-coding-standards/wpcs/',
$root . '/justcoded/',
)),
];
$_SERVER['argv'] = $argv;
$_SERVER['argc'] = count($argv);

$runner = new PHP_CodeSniffer\Runner();
$exitCode = $runner->runPHPCS();
exit($exitCode);
9 changes: 7 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,14 @@
"php": ">=5.4.0",
"ext-tokenizer": "*",
"ext-xmlwriter": "*",
"ext-simplexml": "*"
"ext-simplexml": "*",
"wp-coding-standards/wpcs": "~0.14.0"
},
"scripts": {
"post-install-cmd": "phpcsx-init",
"post-update-cmd": "phpcsx-init"
},
"bin": [
"phpcsx"
"bin/phpcsx-init"
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,15 @@
/**
* Ensures doc blocks follow basic formatting.
*
* PHP version 5
*
* @category PHP
* @package PHP_CodeSniffer
* @author Greg Sherwood <[email protected]>
* @copyright 2006-2012 Squiz Pty Ltd (ABN 77 084 670 600)
* @copyright 2006-2015 Squiz Pty Ltd (ABN 77 084 670 600)
* @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence
* @link http://pear.php.net/package/PHP_CodeSniffer
*/

/**
* Ensures doc blocks follow basic formatting.
*
* @category PHP
* @package PHP_CodeSniffer
* @author Greg Sherwood <[email protected]>
* @copyright 2006-2012 Squiz Pty Ltd (ABN 77 084 670 600)
* @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence
* @version Release: @package_version@
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
class Generic_Sniffs_Commenting_DocCommentSniff implements PHP_CodeSniffer_Sniff
use PHP_CodeSniffer\Sniffs\Sniff;
use PHP_CodeSniffer\Files\File;

class JustcodedPSR2_Sniffs_Commenting_DocCommentSniff extends \PHP_CodeSniffer\Standards\Generic\Sniffs\Commenting\DocCommentSniff
{

/**
Expand All @@ -50,15 +37,15 @@ public function register()


/**
* Processes this test, when one of its tokens is encountered.
*
* @param PHP_CodeSniffer_File $phpcsFile The file being scanned.
* @param int $stackPtr The position of the current token
* in the stack passed in $tokens.
*
* @param \PHP_CodeSniffer\Files\File $phpcsFile The file being scanned.
* @param int $stackPtr The position of the current token
* in the stack passed in $tokens.
*
* @return void
*/
public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
public function process(File $phpcsFile, $stackPtr)
{
$tokens = $phpcsFile->getTokens();
$commentStart = $stackPtr;
Expand Down Expand Up @@ -119,8 +106,11 @@ public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)

// Check for a comment description.
if ($tokens[$short]['code'] !== T_DOC_COMMENT_STRING) {
$error = 'Missing short description in doc comment';
$phpcsFile->addError($error, $stackPtr, 'MissingShort');
// @inheritdoc hotfix
if (stripos($tokens[$short]['content'], '@inheritdoc') === false) {
$error = 'Missing short description in doc comment';
$phpcsFile->addError($error, $stackPtr, 'MissingShort');
}
return;
}

Expand Down
9 changes: 8 additions & 1 deletion justcoded/JustcodedPSR2/ruleset.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,12 @@
<!-- Covers rule: Use real tabs and not spaces. -->
<arg name="tab-width" value="4"/>
<rule ref="Generic.WhiteSpace.DisallowSpaceIndent"/>


<rule ref="WordPress-Docs">
<exclude name="Squiz.Commenting.FileComment"/>
<exclude name="Squiz.Commenting.FunctionComment.ParamCommentFullStop"/>
<exclude name="Squiz.Commenting.FunctionComment.SpacingAfterParamType"/>
<exclude name="Generic.Commenting.DocComment"/>
</rule>
<rule ref="JustcodedPSR2.Commenting.DocComment" />
</ruleset>
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,6 @@
* @license https://opensource.org/licenses/MIT MIT
*/

if ( ! class_exists( 'WordPress_Sniffs_NamingConventions_ValidVariableNameSniff', true ) ) {
throw new PHP_CodeSniffer_Exception( 'Class WordPress_Sniffs_NamingConventions_ValidVariableNameSniff not found' );
}

/**
* Checks the naming of variables and member variables.
*
Expand All @@ -23,19 +19,27 @@
* Last synced with base class July 2014 at commit ed257ca0e56ad86cd2a4d6fa38ce0b95141c824f.
* @link https://github.com/squizlabs/PHP_CodeSniffer/blob/master/CodeSniffer/Standards/Squiz/Sniffs/NamingConventions/ValidVariableNameSniff.php
*/
class JustcodedWordpress_Sniffs_NamingConventions_ValidVariableNameSniff extends WordPress_Sniffs_NamingConventions_ValidVariableNameSniff
class JustcodedWordpress_Sniffs_NamingConventions_ValidVariableNameSniff extends \WordPress\Sniffs\NamingConventions\ValidVariableNameSniff
{

/**
* Custom list of variables which can have mixed case.
*
* @since 0.10.0
*
* @var string[]
*/
public $customPropertiesWhitelist = array(
'SLUG',
'TITLE',
);
/**
* List of member variables that can have mixed case.
*
* @since 0.9.0
* @since 0.11.0 Changed from public to protected.
*
* @var array
*/
protected $whitelisted_mixed_case_member_var_names = array(
'ID' => true,
'comment_ID' => true,
'comment_post_ID' => true,
'post_ID' => true,
'comment_author_IP' => true,
'cat_ID' => true,

'SLUG' => true,
'TITLE' => true,
);

}
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,12 @@
* WordPress Coding Standard, Justcoded edition.
*/

if ( ! class_exists( 'WordPress_Sniffs_XSS_EscapeOutputSniff', true ) ) {
throw new PHP_CodeSniffer_Exception( 'Class WordPress_Sniffs_XSS_EscapeOutputSniff not found' );
}

/**
* Verifies that all outputted strings are escaped.
*
* @link http://codex.wordpress.org/Data_Validation Data Validation on WordPress Codex
*/
class JustcodedWordpress_Sniffs_XSS_EscapeOutputSniff extends WordPress_Sniffs_XSS_EscapeOutputSniff {
class JustcodedWordpress_Sniffs_XSS_EscapeOutputSniff extends \WordPress\Sniffs\XSS\EscapeOutputSniff {

/**
* Custom list of functions which escape values for output.
Expand Down
13 changes: 0 additions & 13 deletions phpcs/.gitattributes

This file was deleted.

6 changes: 0 additions & 6 deletions phpcs/.gitignore

This file was deleted.

13 changes: 0 additions & 13 deletions phpcs/CONTRIBUTING.md

This file was deleted.

9 changes: 0 additions & 9 deletions phpcs/CodeSniffer.conf.dist

This file was deleted.

Loading

0 comments on commit b86aa57

Please sign in to comment.