Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
composer.phar
/vendor/
/composer.lock
/build
15 changes: 5 additions & 10 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,8 @@ env:
global:
# Name and folder of the the standard to test.
- STANDARD="GreynoiseLaravel"
# 0 For unit test without coverage 1 for unit test with coverage.
- COVERAGE="1"
# Upload covarage to clover.
- CLOVER="0"
# Upload covarage to coveralls.
- COVERALLS="1"

matrix:
fast_finish: true
Expand Down Expand Up @@ -57,16 +55,13 @@ script:
# Check for PHP syntax errors.
- find -L . -path ./vendor -prune -o -name '*.php' -print0 | xargs -0 -n 1 -P 4 php -l
# - Check files match the PHPCS standard.
# - $TRAVIS_BUILD_DIR/vendor/squizlabs/php_codesniffer/bin/phpcs --ignore=*/Tests/* $TRAVIS_BUILD_DIR/$STANDARD/ --standard=$TRAVIS_BUILD_DIR/vendor/squizlabs/php_codesniffer/phpcs.xml.dist
- ./vendor/bin/phpcs --ignore=*/Tests/* ./$STANDARD/ --standard=./vendor/squizlabs/php_codesniffer/phpcs.xml.dist
# Change the default standard.
- ./vendor/bin/phpcs --config-set installed_paths $TRAVIS_BUILD_DIR/$STANDARD
# Verify it's installed.
- ./vendor/bin/phpcs -i
# Run unit tests for the standard with coverage.
- if [[ "$COVERAGE" == "0" ]]; then ./vendor/bin/phpunit --bootstrap=./vendor/squizlabs/php_codesniffer/tests/bootstrap.php --debug --filter $STANDARD ./vendor/squizlabs/php_codesniffer/tests/AllTests.php; fi
# Or Run unit tests for the standard with coverage.
- if [[ "$COVERAGE" == "1" ]]; then ./vendor/bin/phpunit --bootstrap=./vendor/squizlabs/php_codesniffer/tests/bootstrap.php --debug --coverage-clover=$TRAVIS_BUILD_DIR/build/logs/clover.xml --filter $STANDARD ./vendor/squizlabs/php_codesniffer/tests/AllTests.php; fi
# Run unit tests for the standard.
- ./vendor/bin/phpunit --debug --filter $STANDARD

after_success:
- if [[ "$CLOVER" == "1" ]]; then ./vendor/bin/coveralls -v -x $TRAVIS_BUILD_DIR/build/logs/clover.xml; fi
- if [[ "$COVERALLS" == "1" ]]; then ./vendor/bin/coveralls -v -x ./build/logs/clover.xml; fi
134 changes: 134 additions & 0 deletions GreynoiseLaravel/Sniffs/WhiteSpace/DisallowTabsInAlignmentSniff.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
<?php
/**
* Disallow Tabs In Alignment
*
* @package GreynoiseLaravel
* @author Louis Linehan <[email protected]>
* @copyright 2017 Louis Linehan
* @license https://github.com/greynoise-design/laravel-coding-standard/blob/master/LICENSE MIT License
*/

namespace GreynoiseLaravel\Sniffs\WhiteSpace;

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

/**
* Disallow Tabs In Alignment Sniff
*
* Checks for use of tabs after indendation.
*
* @author Louis Linehan <[email protected]>
*/
class DisallowTabsInAlignmentSniff implements Sniff
{

/**
* The --tab-width CLI value that is being used.
*
* @var integer
*/
private $tabWidth = null;


/**
* Returns an array of tokens this test wants to listen for.
*
* @return array
*/
public function register()
{
return array(T_OPEN_TAG);

}//end register()


/**
* Processes this test, when one of its tokens is encountered.
*
* @param \PHP_CodeSniffer\Files\File $phpcsFile All the tokens found in the document.
* @param int $stackPtr The position of the current token in
* the stack passed in $tokens.
*
* @return void
*/
public function process(File $phpcsFile, $stackPtr)
{

if ($this->tabWidth === null) {
if (isset($phpcsFile->config->tabWidth) === false || $phpcsFile->config->tabWidth === 0) {
// We have no idea how wide tabs are, so assume 4 spaces for fixing.
// It shouldn't really matter because alignment and spacing sniffs
// elsewhere in the standard should fix things up.
$this->tabWidth = 4;
} else {
$this->tabWidth = $phpcsFile->config->tabWidth;
}
}

$checkTokens = array(
T_WHITESPACE => true,
T_INLINE_HTML => true,
T_DOC_COMMENT_WHITESPACE => true,
);

$tokens = $phpcsFile->getTokens();

for ($i = ($stackPtr); $i < $phpcsFile->numTokens; $i++) {
// Skip whitespace at the start of a new line and tokens not consdered white space.
if ($tokens[$i]['column'] === 1 || isset($checkTokens[$tokens[$i]['code']]) === false) {
continue;
}

// If tabs are being converted to spaces by the tokeniser, the
// original content should be checked instead of the converted content.
if (isset($tokens[$i]['orig_content']) === true) {
$content = $tokens[$i]['orig_content'];
} else {
$content = $tokens[$i]['content'];
}

if (strpos($content, "\t") !== false) {
// Try to maintain intended alignment by counting tabs and spaces.
$countTabs = substr_count($content, "\t");
$countSpaces = substr_count($content, " ");

if ($countTabs === 1) {
$tabsPlural = '';
} else {
$tabsPlural = 's';
}

if ($countSpaces === 1) {
$spacesPlural = '';
} else {
$spacesPlural = 's';
}

$data = array(
$countTabs,
$tabsPlural,
$countSpaces,
$spacesPlural,
);
$error = 'Spaces must be used for alignment; %s tab%s and %s space%s found';

// The fix might make some lines misaligned if the tab didn't fill the number
// of 'tabWidth' spaces, other alignment and spacing sniffs should fix that.
$fix = $phpcsFile->addFixableError($error, $i, 'TabsUsedInAlignment', $data);
if ($fix === true) {
$phpcsFile->fixer->beginChangeset();
$spaces = str_repeat(' ', (($this->tabWidth * $countTabs) + $countSpaces));
$phpcsFile->fixer->replaceToken($i, $spaces);
$phpcsFile->fixer->endChangeset();
}//end if
}//end if
}//end for

// Ignore the rest of the file.
return ($phpcsFile->numTokens + 1);

}//end process()


}//end class
182 changes: 98 additions & 84 deletions GreynoiseLaravel/ruleset.xml
Original file line number Diff line number Diff line change
@@ -1,87 +1,101 @@
<?xml version="1.0"?>
<ruleset name="GreynoiseLaravel">
<description>Greynoise Laravel 5 standard for PHP_CodeSniffer.</description>
<arg name="tab-width" value="4"/>
<!-- Include the whole PSR-2 standard -->
<rule ref="PSR2"/>

<!--
Files MUST have a doc block comment.
Checks file comment tag format and order.
-->
<rule ref="GreynoiseLaravel.Commenting.FileComment">
<properties>
<property name="error" value="true"/>
</properties>
</rule>
<!--
Classes MUST have a doc block comment.
-->
<rule ref="Squiz.Commenting.ClassComment"/>
<!--
Checks class comment tag format and order.
-->
<rule ref="GreynoiseLaravel.Commenting.ClassComment"/>
<!--
Allow class tags.
-->
<rule ref="Squiz.Commenting.ClassComment.TagNotAllowed">
<severity>0</severity>
</rule>
<!--
Properties MUST have a doc block comment.
-->
<rule ref="Squiz.Commenting.VariableComment"/>
<!--
Methods and functions MUST have a doc block comment.
-->
<rule ref="Squiz.Commenting.FunctionComment"/>
<rule ref="Squiz.Commenting.FunctionComment.ParamCommentFullStop">
<severity>0</severity>
</rule>
<!--
Doc block comment alignment.
-->
<rule ref="Squiz.Commenting.DocCommentAlignment"/>
<!--
Warn about //... comments after statments.
-->
<rule ref="Squiz.Commenting.PostStatementComment">
<type>warning</type>
<exclude phpcbf-only="true" name="Squiz.Commenting.PostStatementComment.Found"/>
</rule>
<!--
Change the error message.
-->
<rule ref="Squiz.Commenting.PostStatementComment.Found">
<message>Comments should not appear after statements</message>
</rule>
<!--
Doc block comment format and spacing.
-->
<rule ref="Generic.Commenting.DocComment"/>

<!--
Warning for todo items.
-->
<rule ref="Generic.Commenting.Todo"/>

<!--
Checks array bracket spaces.
-->
<rule ref="Squiz.Arrays.ArrayBracketSpacing"/>
<!--
Check array declaration, indentation, alignment and that the last item
has a trailing comma.
Checks arrays are declared as "[]" not "array()".
-->
<rule ref="GreynoiseLaravel.Arrays.ArrayDeclaration"/>
<!--
Checks statments on subsequent lines are aligned. (line up the "=").
-->
<rule ref="Generic.Formatting.MultipleStatementAlignment">
<properties>
<property name="error" value="true"/>
</properties>
</rule>
<description>Greynoise Laravel 5 standard for PHP_CodeSniffer.</description>
<arg name="tab-width" value="4"/>
<exclude-pattern>*/config/*</exclude-pattern>
<exclude-pattern>*/cache/*</exclude-pattern>
<exclude-pattern>*/database/*</exclude-pattern>
<exclude-pattern>*/docs/*</exclude-pattern>
<exclude-pattern>*/migrations/*</exclude-pattern>
<exclude-pattern>*/public/index.php</exclude-pattern>
<exclude-pattern>*/vendor/*</exclude-pattern>
<exclude-pattern>*/storage/*</exclude-pattern>
<exclude-pattern>*/*.blade.php</exclude-pattern>
<exclude-pattern>*/*.css</exclude-pattern>
<exclude-pattern>*/*.js</exclude-pattern>
<exclude-pattern>*/*.xml</exclude-pattern>
<exclude-pattern>*/autoload.php</exclude-pattern>
<!-- Include the whole PSR-2 standard -->
<rule ref="PSR2"/>
<!--
Files MUST have a doc block comment.
Checks file comment tag format and order.
-->
<rule ref="GreynoiseLaravel.Commenting.FileComment">
<properties>
<property name="error" value="true"/>
</properties>
</rule>
<!--
Classes MUST have a doc block comment.
-->
<rule ref="Squiz.Commenting.ClassComment"/>
<!--
Checks class comment tag format and order.
-->
<rule ref="GreynoiseLaravel.Commenting.ClassComment"/>
<!--
Allow class tags.
-->
<rule ref="Squiz.Commenting.ClassComment.TagNotAllowed">
<severity>0</severity>
</rule>
<!--
Properties MUST have a doc block comment.
-->
<rule ref="Squiz.Commenting.VariableComment"/>
<!--
Methods and functions MUST have a doc block comment.
-->
<rule ref="Squiz.Commenting.FunctionComment"/>
<rule ref="Squiz.Commenting.FunctionComment.ParamCommentFullStop">
<severity>0</severity>
</rule>
<!--
Doc block comment alignment.
-->
<rule ref="Squiz.Commenting.DocCommentAlignment"/>
<!--
Warn about //... comments after statments.
-->
<rule ref="Squiz.Commenting.PostStatementComment">
<type>warning</type>
<exclude phpcbf-only="true" name="Squiz.Commenting.PostStatementComment.Found"/>
</rule>
<!--
Change the error message.
-->
<rule ref="Squiz.Commenting.PostStatementComment.Found">
<message>Comments should not appear after statements</message>
</rule>
<!--
Doc block comment format and spacing.
-->
<rule ref="Generic.Commenting.DocComment"/>
<!--
Warning for todo items.
-->
<rule ref="Generic.Commenting.Todo"/>
<!--
Checks array bracket spaces.
-->
<rule ref="Squiz.Arrays.ArrayBracketSpacing"/>
<!--
Check array declaration, indentation, alignment and that the last item
has a trailing comma.
Checks arrays are declared as "[]" not "array()".
-->
<rule ref="GreynoiseLaravel.Arrays.ArrayDeclaration"/>
<!--
Checks statments on subsequent lines are aligned. (line up the "=").
-->
<!-- <rule ref="Generic.Formatting.MultipleStatementAlignment">
<properties>
<property name="error" value="true"/>
</properties>
</rule> -->
<!--
Checks tabs are not used in alignment.
-->
<rule ref="GreynoiseLaravel.WhiteSpace.DisallowTabsInAlignment"/>
</ruleset>
Loading