-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #8 from HydraWiki/develop
Fix Tab handling and array formatting
- Loading branch information
Showing
10 changed files
with
969 additions
and
124 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
# EditorConfig is awesome: http://EditorConfig.org | ||
|
||
# top-most EditorConfig file | ||
root = true | ||
|
||
# Unix-style newlines with a newline ending every file | ||
[*] | ||
end_of_line = lf | ||
insert_final_newline = true | ||
|
||
# Matches multiple files with brace expansion notation | ||
# Set default charset | ||
[*.{js,php,css}] | ||
charset = utf-8 | ||
|
||
# 4 space indentation | ||
[*.php] | ||
indent_style = tab | ||
indent_size = 4 | ||
|
||
# Tab indentation (no size specified) | ||
[Makefile] | ||
indent_style = tab | ||
|
||
|
||
# Matches the exact files either package.json or .travis.yml | ||
[{package.json,.travis.yml}] | ||
indent_style = space | ||
indent_size = 2 |
106 changes: 106 additions & 0 deletions
106
HydraWiki/Sniffs/Arrays/NoExtraSpacesSingleLineSniff.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
<?php | ||
/** | ||
* Curse Inc. | ||
* NoExtraSpacesSniff | ||
* | ||
* This file was copied from PHP_CodeSniffer before being modified | ||
* File: Standards/Generic/Sniffs/Arrays/ArrayIndentSniff.php | ||
* From repository: https://github.com/squizlabs/PHP_CodeSniffer | ||
* | ||
* Ensures there is no extra space in single line arrays. | ||
* | ||
* @author Greg Sherwood <[email protected]> | ||
* @copyright 2006-2015 Squiz Pty Ltd (ABN 77 084 670 600) | ||
* @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD-3-Clause | ||
*/ | ||
|
||
namespace HydraWiki\Sniffs\Arrays; | ||
|
||
use PHP_CodeSniffer\Sniffs\AbstractArraySniff; | ||
|
||
class NoExtraSpacesSingleLineSniff extends AbstractArraySniff { | ||
|
||
/** | ||
* The number of spaces each array key should be indented. | ||
* | ||
* @var integer | ||
*/ | ||
public $indent = 4; | ||
|
||
/** | ||
* Processes a single-line array definition. | ||
* | ||
* @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. | ||
* @param int $arrayStart The token that starts the array definition. | ||
* @param int $arrayEnd The token that ends the array definition. | ||
* @param array $indices An array of token positions for the array keys, double arrows, and values. | ||
* | ||
* @return void | ||
*/ | ||
public function processSingleLineArray($phpcsFile, $stackPtr, $arrayStart, $arrayEnd, $indices) { | ||
$this->handleArrayStart($phpcsFile, $arrayStart); | ||
$this->handleArrayEnd($phpcsFile, $arrayEnd); | ||
} | ||
|
||
/** | ||
* Processes a multi-line array definition. | ||
* | ||
* @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. | ||
* @param int $arrayStart The token that starts the array definition. | ||
* @param int $arrayEnd The token that ends the array definition. | ||
* @param array $indices An array of token positions for the array keys, double arrows, and values. | ||
* | ||
* @return void | ||
*/ | ||
public function processMultiLineArray($phpcsFile, $stackPtr, $arrayStart, $arrayEnd, $indices) { | ||
// No multiline processing. | ||
} | ||
|
||
/** | ||
* Process the starting brace of a short array | ||
* | ||
* @param \PHP_CodeSniffer\Files\File $phpcsFile | ||
* @param int $arrayStart | ||
* @return void | ||
*/ | ||
private function handleArrayStart($phpcsFile, $arrayStart) { | ||
$tokens = $phpcsFile->getTokens(); | ||
$spacing = 0; | ||
if ($tokens[($arrayStart + 1)]['code'] === T_WHITESPACE) { | ||
$spacing = $tokens[($arrayStart + 1)]['length']; | ||
} | ||
if ($spacing == 0) { | ||
return; | ||
} | ||
$message = 'No Spaces allowed after the opening brace of a single-line short array; %s found'; | ||
$fix = $phpcsFile->addFixableError($message, $arrayStart, 'SpaceAfterOpeningBrace', [$spacing]); | ||
if ($fix === true) { | ||
$phpcsFile->fixer->replaceToken(($arrayStart + 1), ''); | ||
} | ||
} | ||
|
||
/** | ||
* Process the closing brace of a short array | ||
* | ||
* @param \PHP_CodeSniffer\Files\File $phpcsFile | ||
* @param int $arrayEnd | ||
* @return void | ||
*/ | ||
private function handleArrayEnd($phpcsFile, $arrayEnd) { | ||
$tokens = $phpcsFile->getTokens(); | ||
$spacing = 0; | ||
if ($tokens[($arrayEnd - 1)]['code'] === T_WHITESPACE) { | ||
$spacing = $tokens[($arrayEnd - 1)]['length']; | ||
} | ||
if ($spacing == 0) { | ||
return; | ||
} | ||
$message = 'No Spaces allowed before the closing brace of a single-line short array; %s found'; | ||
$fix = $phpcsFile->addFixableError($message, $arrayEnd, 'SpaceBeforeClosingBrace', [$spacing]); | ||
if ($fix === true) { | ||
$phpcsFile->fixer->replaceToken(($arrayEnd - 1), ''); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.