Skip to content

Commit fa87ceb

Browse files
authored
1.0.0 (#6)
* Added covearge * Feature/coverage (#2) * Travis build * Coveralls * Added coverage and build badges * Feature/exclude patterns (#3) * Added exclude-patterns * Added usage and config instructions * Switched tabs to spaces * Updated ruleset (#4) * Bumped version to 1.0.0 (#5)
1 parent bc15057 commit fa87ceb

File tree

8 files changed

+2518
-97
lines changed

8 files changed

+2518
-97
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
composer.phar
22
/vendor/
3-
/composer.lock
3+
/build

.travis.yml

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,8 @@ env:
1212
global:
1313
# Name and folder of the the standard to test.
1414
- STANDARD="GreynoiseLaravel"
15-
# 0 For unit test without coverage 1 for unit test with coverage.
16-
- COVERAGE="1"
17-
# Upload covarage to clover.
18-
- CLOVER="0"
15+
# Upload covarage to coveralls.
16+
- COVERALLS="1"
1917

2018
matrix:
2119
fast_finish: true
@@ -57,16 +55,13 @@ script:
5755
# Check for PHP syntax errors.
5856
- find -L . -path ./vendor -prune -o -name '*.php' -print0 | xargs -0 -n 1 -P 4 php -l
5957
# - Check files match the PHPCS standard.
60-
# - $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
6158
- ./vendor/bin/phpcs --ignore=*/Tests/* ./$STANDARD/ --standard=./vendor/squizlabs/php_codesniffer/phpcs.xml.dist
6259
# Change the default standard.
6360
- ./vendor/bin/phpcs --config-set installed_paths $TRAVIS_BUILD_DIR/$STANDARD
6461
# Verify it's installed.
6562
- ./vendor/bin/phpcs -i
66-
# Run unit tests for the standard with coverage.
67-
- 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
68-
# Or Run unit tests for the standard with coverage.
69-
- 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
63+
# Run unit tests for the standard.
64+
- ./vendor/bin/phpunit --debug --filter $STANDARD
7065

7166
after_success:
72-
- if [[ "$CLOVER" == "1" ]]; then ./vendor/bin/coveralls -v -x $TRAVIS_BUILD_DIR/build/logs/clover.xml; fi
67+
- if [[ "$COVERALLS" == "1" ]]; then ./vendor/bin/coveralls -v -x ./build/logs/clover.xml; fi
Lines changed: 134 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,134 @@
1+
<?php
2+
/**
3+
* Disallow Tabs In Alignment
4+
*
5+
* @package GreynoiseLaravel
6+
* @author Louis Linehan <[email protected]>
7+
* @copyright 2017 Louis Linehan
8+
* @license https://github.com/greynoise-design/laravel-coding-standard/blob/master/LICENSE MIT License
9+
*/
10+
11+
namespace GreynoiseLaravel\Sniffs\WhiteSpace;
12+
13+
use PHP_CodeSniffer\Sniffs\Sniff;
14+
use PHP_CodeSniffer\Files\File;
15+
16+
/**
17+
* Disallow Tabs In Alignment Sniff
18+
*
19+
* Checks for use of tabs after indendation.
20+
*
21+
* @author Louis Linehan <[email protected]>
22+
*/
23+
class DisallowTabsInAlignmentSniff implements Sniff
24+
{
25+
26+
/**
27+
* The --tab-width CLI value that is being used.
28+
*
29+
* @var integer
30+
*/
31+
private $tabWidth = null;
32+
33+
34+
/**
35+
* Returns an array of tokens this test wants to listen for.
36+
*
37+
* @return array
38+
*/
39+
public function register()
40+
{
41+
return array(T_OPEN_TAG);
42+
43+
}//end register()
44+
45+
46+
/**
47+
* Processes this test, when one of its tokens is encountered.
48+
*
49+
* @param \PHP_CodeSniffer\Files\File $phpcsFile All the tokens found in the document.
50+
* @param int $stackPtr The position of the current token in
51+
* the stack passed in $tokens.
52+
*
53+
* @return void
54+
*/
55+
public function process(File $phpcsFile, $stackPtr)
56+
{
57+
58+
if ($this->tabWidth === null) {
59+
if (isset($phpcsFile->config->tabWidth) === false || $phpcsFile->config->tabWidth === 0) {
60+
// We have no idea how wide tabs are, so assume 4 spaces for fixing.
61+
// It shouldn't really matter because alignment and spacing sniffs
62+
// elsewhere in the standard should fix things up.
63+
$this->tabWidth = 4;
64+
} else {
65+
$this->tabWidth = $phpcsFile->config->tabWidth;
66+
}
67+
}
68+
69+
$checkTokens = array(
70+
T_WHITESPACE => true,
71+
T_INLINE_HTML => true,
72+
T_DOC_COMMENT_WHITESPACE => true,
73+
);
74+
75+
$tokens = $phpcsFile->getTokens();
76+
77+
for ($i = ($stackPtr); $i < $phpcsFile->numTokens; $i++) {
78+
// Skip whitespace at the start of a new line and tokens not consdered white space.
79+
if ($tokens[$i]['column'] === 1 || isset($checkTokens[$tokens[$i]['code']]) === false) {
80+
continue;
81+
}
82+
83+
// If tabs are being converted to spaces by the tokeniser, the
84+
// original content should be checked instead of the converted content.
85+
if (isset($tokens[$i]['orig_content']) === true) {
86+
$content = $tokens[$i]['orig_content'];
87+
} else {
88+
$content = $tokens[$i]['content'];
89+
}
90+
91+
if (strpos($content, "\t") !== false) {
92+
// Try to maintain intended alignment by counting tabs and spaces.
93+
$countTabs = substr_count($content, "\t");
94+
$countSpaces = substr_count($content, " ");
95+
96+
if ($countTabs === 1) {
97+
$tabsPlural = '';
98+
} else {
99+
$tabsPlural = 's';
100+
}
101+
102+
if ($countSpaces === 1) {
103+
$spacesPlural = '';
104+
} else {
105+
$spacesPlural = 's';
106+
}
107+
108+
$data = array(
109+
$countTabs,
110+
$tabsPlural,
111+
$countSpaces,
112+
$spacesPlural,
113+
);
114+
$error = 'Spaces must be used for alignment; %s tab%s and %s space%s found';
115+
116+
// The fix might make some lines misaligned if the tab didn't fill the number
117+
// of 'tabWidth' spaces, other alignment and spacing sniffs should fix that.
118+
$fix = $phpcsFile->addFixableError($error, $i, 'TabsUsedInAlignment', $data);
119+
if ($fix === true) {
120+
$phpcsFile->fixer->beginChangeset();
121+
$spaces = str_repeat(' ', (($this->tabWidth * $countTabs) + $countSpaces));
122+
$phpcsFile->fixer->replaceToken($i, $spaces);
123+
$phpcsFile->fixer->endChangeset();
124+
}//end if
125+
}//end if
126+
}//end for
127+
128+
// Ignore the rest of the file.
129+
return ($phpcsFile->numTokens + 1);
130+
131+
}//end process()
132+
133+
134+
}//end class

GreynoiseLaravel/ruleset.xml

Lines changed: 98 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -1,87 +1,101 @@
11
<?xml version="1.0"?>
22
<ruleset name="GreynoiseLaravel">
3-
<description>Greynoise Laravel 5 standard for PHP_CodeSniffer.</description>
4-
<arg name="tab-width" value="4"/>
5-
<!-- Include the whole PSR-2 standard -->
6-
<rule ref="PSR2"/>
7-
8-
<!--
9-
Files MUST have a doc block comment.
10-
Checks file comment tag format and order.
11-
-->
12-
<rule ref="GreynoiseLaravel.Commenting.FileComment">
13-
<properties>
14-
<property name="error" value="true"/>
15-
</properties>
16-
</rule>
17-
<!--
18-
Classes MUST have a doc block comment.
19-
-->
20-
<rule ref="Squiz.Commenting.ClassComment"/>
21-
<!--
22-
Checks class comment tag format and order.
23-
-->
24-
<rule ref="GreynoiseLaravel.Commenting.ClassComment"/>
25-
<!--
26-
Allow class tags.
27-
-->
28-
<rule ref="Squiz.Commenting.ClassComment.TagNotAllowed">
29-
<severity>0</severity>
30-
</rule>
31-
<!--
32-
Properties MUST have a doc block comment.
33-
-->
34-
<rule ref="Squiz.Commenting.VariableComment"/>
35-
<!--
36-
Methods and functions MUST have a doc block comment.
37-
-->
38-
<rule ref="Squiz.Commenting.FunctionComment"/>
39-
<rule ref="Squiz.Commenting.FunctionComment.ParamCommentFullStop">
40-
<severity>0</severity>
41-
</rule>
42-
<!--
43-
Doc block comment alignment.
44-
-->
45-
<rule ref="Squiz.Commenting.DocCommentAlignment"/>
46-
<!--
47-
Warn about //... comments after statments.
48-
-->
49-
<rule ref="Squiz.Commenting.PostStatementComment">
50-
<type>warning</type>
51-
<exclude phpcbf-only="true" name="Squiz.Commenting.PostStatementComment.Found"/>
52-
</rule>
53-
<!--
54-
Change the error message.
55-
-->
56-
<rule ref="Squiz.Commenting.PostStatementComment.Found">
57-
<message>Comments should not appear after statements</message>
58-
</rule>
59-
<!--
60-
Doc block comment format and spacing.
61-
-->
62-
<rule ref="Generic.Commenting.DocComment"/>
63-
64-
<!--
65-
Warning for todo items.
66-
-->
67-
<rule ref="Generic.Commenting.Todo"/>
68-
69-
<!--
70-
Checks array bracket spaces.
71-
-->
72-
<rule ref="Squiz.Arrays.ArrayBracketSpacing"/>
73-
<!--
74-
Check array declaration, indentation, alignment and that the last item
75-
has a trailing comma.
76-
Checks arrays are declared as "[]" not "array()".
77-
-->
78-
<rule ref="GreynoiseLaravel.Arrays.ArrayDeclaration"/>
79-
<!--
80-
Checks statments on subsequent lines are aligned. (line up the "=").
81-
-->
82-
<rule ref="Generic.Formatting.MultipleStatementAlignment">
83-
<properties>
84-
<property name="error" value="true"/>
85-
</properties>
86-
</rule>
3+
<description>Greynoise Laravel 5 standard for PHP_CodeSniffer.</description>
4+
<arg name="tab-width" value="4"/>
5+
<exclude-pattern>*/config/*</exclude-pattern>
6+
<exclude-pattern>*/cache/*</exclude-pattern>
7+
<exclude-pattern>*/database/*</exclude-pattern>
8+
<exclude-pattern>*/docs/*</exclude-pattern>
9+
<exclude-pattern>*/migrations/*</exclude-pattern>
10+
<exclude-pattern>*/public/index.php</exclude-pattern>
11+
<exclude-pattern>*/vendor/*</exclude-pattern>
12+
<exclude-pattern>*/storage/*</exclude-pattern>
13+
<exclude-pattern>*/*.blade.php</exclude-pattern>
14+
<exclude-pattern>*/*.css</exclude-pattern>
15+
<exclude-pattern>*/*.js</exclude-pattern>
16+
<exclude-pattern>*/*.xml</exclude-pattern>
17+
<exclude-pattern>*/autoload.php</exclude-pattern>
18+
<!-- Include the whole PSR-2 standard -->
19+
<rule ref="PSR2"/>
20+
<!--
21+
Files MUST have a doc block comment.
22+
Checks file comment tag format and order.
23+
-->
24+
<rule ref="GreynoiseLaravel.Commenting.FileComment">
25+
<properties>
26+
<property name="error" value="true"/>
27+
</properties>
28+
</rule>
29+
<!--
30+
Classes MUST have a doc block comment.
31+
-->
32+
<rule ref="Squiz.Commenting.ClassComment"/>
33+
<!--
34+
Checks class comment tag format and order.
35+
-->
36+
<rule ref="GreynoiseLaravel.Commenting.ClassComment"/>
37+
<!--
38+
Allow class tags.
39+
-->
40+
<rule ref="Squiz.Commenting.ClassComment.TagNotAllowed">
41+
<severity>0</severity>
42+
</rule>
43+
<!--
44+
Properties MUST have a doc block comment.
45+
-->
46+
<rule ref="Squiz.Commenting.VariableComment"/>
47+
<!--
48+
Methods and functions MUST have a doc block comment.
49+
-->
50+
<rule ref="Squiz.Commenting.FunctionComment"/>
51+
<rule ref="Squiz.Commenting.FunctionComment.ParamCommentFullStop">
52+
<severity>0</severity>
53+
</rule>
54+
<!--
55+
Doc block comment alignment.
56+
-->
57+
<rule ref="Squiz.Commenting.DocCommentAlignment"/>
58+
<!--
59+
Warn about //... comments after statments.
60+
-->
61+
<rule ref="Squiz.Commenting.PostStatementComment">
62+
<type>warning</type>
63+
<exclude phpcbf-only="true" name="Squiz.Commenting.PostStatementComment.Found"/>
64+
</rule>
65+
<!--
66+
Change the error message.
67+
-->
68+
<rule ref="Squiz.Commenting.PostStatementComment.Found">
69+
<message>Comments should not appear after statements</message>
70+
</rule>
71+
<!--
72+
Doc block comment format and spacing.
73+
-->
74+
<rule ref="Generic.Commenting.DocComment"/>
75+
<!--
76+
Warning for todo items.
77+
-->
78+
<rule ref="Generic.Commenting.Todo"/>
79+
<!--
80+
Checks array bracket spaces.
81+
-->
82+
<rule ref="Squiz.Arrays.ArrayBracketSpacing"/>
83+
<!--
84+
Check array declaration, indentation, alignment and that the last item
85+
has a trailing comma.
86+
Checks arrays are declared as "[]" not "array()".
87+
-->
88+
<rule ref="GreynoiseLaravel.Arrays.ArrayDeclaration"/>
89+
<!--
90+
Checks statments on subsequent lines are aligned. (line up the "=").
91+
-->
92+
<!-- <rule ref="Generic.Formatting.MultipleStatementAlignment">
93+
<properties>
94+
<property name="error" value="true"/>
95+
</properties>
96+
</rule> -->
97+
<!--
98+
Checks tabs are not used in alignment.
99+
-->
100+
<rule ref="GreynoiseLaravel.WhiteSpace.DisallowTabsInAlignment"/>
87101
</ruleset>

0 commit comments

Comments
 (0)