Skip to content

Commit

Permalink
Merge pull request #101 from ongr-io/master
Browse files Browse the repository at this point in the history
2.1.0 Release request
  • Loading branch information
saimaz committed Apr 20, 2015
2 parents 2b3b607 + c2fd59c commit d06defc
Show file tree
Hide file tree
Showing 22 changed files with 1,051 additions and 66 deletions.
26 changes: 13 additions & 13 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,9 @@ Ever wanted to standardize your team's code style? This is a **PSR-2 compliant c
}
}
.. warning::
No more code like this!
..
**No more code like this!**

After ONGR Strict Standard validation:

Expand Down Expand Up @@ -97,7 +98,7 @@ Requirements
Acknowledgement
---------------
Our work is based solely on Squiz Labs [Squiz coding standard](https://github.com/squizlabs/PHP_CodeSniffer) and [opensky Symfony2 coding standard](https://github.com/escapestudios/Symfony2-coding-standard).
Our work is based solely on Squiz Labs `Squiz coding standard <https://github.com/squizlabs/PHP_CodeSniffer>`_ and `opensky Symfony2 coding standard <https://github.com/escapestudios/Symfony2-coding-standard>`_.
Installation
------------
Expand All @@ -118,14 +119,13 @@ Or optionally you can install globally to all projects at `~/.composer/composer.
Then: `composer global update`.
.. warning::
If you are planing on developing, then sources should be located in `ONGR` directory.
**Warning:** if you are planing on developing, then sources should be located in `ONGR` directory.
For example, when cloning add target directory:
For example, when cloning add target directory:
.. code:: bash
.. code:: bash
git clone [email protected]:<username>/ongr-strict-standard.git ONGR
git clone [email protected]:<username>/ongr-strict-standard.git ONGR
Running
Expand All @@ -134,11 +134,11 @@ Running
vendor/bin/phpcs -p --standard=/home/<user>/.composer/vendor/ongr/ongr-strict-standard/ONGR --ignore=vendor/,Tests/app/,Resources/public/ ./
.. note::
Do not use `~` for HOME parameter, as PHPCS will not expand it.
..
**Note:** Do not use `~` for HOME parameter, as PHPCS will not expand it.
.. note::
**IDEs also support running Code Sniffer** and adding error annotations directly on editor's source code (e.g. PHPStorm). Please see your IDE's documentation on how to add standard from custom directory.
**Note:** IDEs also support running Code Sniffer and adding error annotations directly on editor's source code (e.g. PHPStorm). Please see your IDE's documentation on how to add standard from custom directory.
PHPStorm Helper
---------------
Expand All @@ -158,4 +158,4 @@ License
-------
This bundle is under the MIT license. Please, see the complete license
in the bundle ``LICENSE`` file.
in the bundle ``LICENSE`` file.
36 changes: 34 additions & 2 deletions Sniffs/Arrays/ArrayDeclarationSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -812,12 +812,13 @@ public function processMultiLineArray(PHP_CodeSniffer_File $phpcsFile, $stackPtr
// }
// }//end if
//ongr end
// Check each line ends in a comma.
// Check each line ends in a comma or dot (string concat).
// if ($tokens[$index['value']]['code'] !== T_ARRAY
// && $tokens[$index['value']]['code'] !== T_OPEN_SHORT_ARRAY
// ) {
$valueLine = $tokens[$index['value']]['line'];
$nextComma = false;
$nextDot = false;
for ($i = ($index['value'] + 1); $i < $arrayEnd; $i++) {
// Skip bracketed statements, like function calls.
if ($tokens[$i]['code'] === T_OPEN_PARENTHESIS) {
Expand All @@ -830,9 +831,16 @@ public function processMultiLineArray(PHP_CodeSniffer_File $phpcsFile, $stackPtr
$nextComma = $i;
break;
}
else if($tokens[$i]['code'] === T_STRING_CONCAT) {
$nextDot = $i;
break;
}
}

if (($nextComma === false) || ($tokens[$nextComma]['line'] !== $valueLine) && $tokens[$index['value']]['code'] !== T_OPEN_SHORT_ARRAY) {
if (($nextComma === false && $nextDot === false)
|| ($tokens[$nextComma]['line'] !== $valueLine && $tokens[$nextDot]['line'] !== $valueLine)
&& $tokens[$index['value']]['code'] !== T_OPEN_SHORT_ARRAY
) {
$error = 'Each line in an array declaration must end in a comma';
$fix = $phpcsFile->addFixableError($error, $index['value'], 'NoComma');

Expand Down Expand Up @@ -863,6 +871,30 @@ public function processMultiLineArray(PHP_CodeSniffer_File $phpcsFile, $stackPtr
$phpcsFile->fixer->replaceToken(($nextComma - 1), '');
}
}

if ($nextDot !== false) {
$spacesExpected = $this->getStatementStartColumn($phpcsFile, $nextDot) + 3;

$indentation = $nextDot;
while($tokens[$nextDot]['line'] == $tokens[$indentation]['line']) {
$indentation++;
}

$spacesFound = 0;
if ($tokens[$indentation]['code'] == T_WHITESPACE) {
$spacesFound = $tokens[$indentation]['length'];
}

if ($spacesExpected != $spacesFound) {
$error = 'Array value not aligned correctly; expected %s spaces but found %s';
$data = array(
$spacesExpected,
$spacesFound,
);

$phpcsFile->addError($error, $indentation, 'ValueNotAligned', $data);
}
}
// }//end if
}//end foreach

Expand Down
66 changes: 27 additions & 39 deletions Sniffs/Commenting/BlockCommentSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -153,16 +153,16 @@ public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
return;
}
// ONGR we use single line block comments generated from IDE
// if (count($commentLines) === 1) {
// $error = 'Single line block comment not allowed; use inline ("// text") comment instead';
// $fix = $phpcsFile->addFixableError($error, $stackPtr, 'SingleLine');
// if ($fix === true) {
// $comment = '// '.$commentText.$phpcsFile->eolChar;
// $phpcsFile->fixer->replaceToken($stackPtr, $comment);
// }
//
// return;
// }
if (count($commentLines) === 1 && substr($tokens[$stackPtr]['content'], 0, 2) !== '/**') {
$error = 'Single line block comment must start with "/**"';
$fix = $phpcsFile->addFixableError($error, $stackPtr, 'SingleLine');
if ($fix === true) {
$comment = '/** '.$commentText. ' */';
$phpcsFile->fixer->replaceToken($stackPtr, $comment);
}

return;
}

$content = trim($tokens[$stackPtr]['content']);
if ($content !== '/*' && $content !== '/**') {
Expand All @@ -183,43 +183,30 @@ public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)

//ONGR Allow '/*' as block comments with no space at the beginning
$starColumn = ($tokens[$stackPtr]['column']);

// Make sure first line isn't blank.
if (trim($tokens[$commentLines[1]]['content']) === '') {
$error = 'Empty line not allowed at start of comment';
$fix = $phpcsFile->addFixableError($error, $commentLines[1], 'HasEmptyLine');
if ($fix === true) {
$phpcsFile->fixer->replaceToken($commentLines[1], '');
}
$phpcsFile->addError($error, $commentLines[1], 'HasEmptyLine');
} else {
// Check indentation of first line.
$content = $tokens[$commentLines[1]]['content'];
$commentText = ltrim($content);
$content = $tokens[$commentLines[1]]['content'];
$commentText = ltrim($content);
$leadingSpace = (strlen($content) - strlen($commentText));
if ($leadingSpace !== $starColumn) {
$expected = $starColumn.' space';
if ($starColumn !== 1) {
$expected .= 's';
}

$data = array(
if ($leadingSpace !== $starColumn && trim($content)[0] !== '*') {
$expected = $starColumn;
$expected .= ($starColumn === 1) ? ' space' : ' spaces';
$data = [
$expected,
$leadingSpace,
);

];
$error = 'First line of comment not aligned correctly; expected %s but found %s';
$fix = $phpcsFile->addFixableError($error, $commentLines[1], 'FirstLineIndent', $data);
if ($fix === true) {
$newContent = str_repeat(' ', $starColumn).ltrim($content);
$phpcsFile->fixer->replaceToken($commentLines[1], $newContent);
}
$phpcsFile->addError($error, $commentLines[1], 'FirstLineIndent', $data);
}

if (preg_match('/\p{Lu}|\P{L}/u', $commentText[0]) === 0) {
if (preg_match('#\p{Lu}|\*#u', $commentText[0]) === 0) {
$error = 'Block comments must start with a capital letter';
$phpcsFile->addError($error, $commentLines[1], 'NoCapital');
}
}//end if
}

// Check that each line of the comment is indented past the star.
foreach ($commentLines as $line) {
Expand Down Expand Up @@ -251,11 +238,12 @@ public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
);

$error = 'Comment line indented incorrectly; expected at least %s but found %s';
$fix = $phpcsFile->addFixableError($error, $line, 'LineIndent', $data);
if ($fix === true) {
$newContent = str_repeat(' ', $starColumn).ltrim($tokens[$line]['content']);
$phpcsFile->fixer->replaceToken($line, $newContent);
}
//Ongr Disabled autofix.
$fix = $phpcsFile->addError($error, $line, 'LineIndent', $data);
// if ($fix === true) {
// $newContent = str_repeat(' ', $starColumn).ltrim($tokens[$line]['content']);
// $phpcsFile->fixer->replaceToken($line, $newContent);
// }
}
}//end foreach

Expand Down
Loading

0 comments on commit d06defc

Please sign in to comment.