Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
coder
Manage
Activity
Members
Labels
Plan
Wiki
Custom issue tracker
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Model registry
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
project
coder
Commits
2caa5e7b
Commit
2caa5e7b
authored
13 years ago
by
Klaus Purer
Browse files
Options
Downloads
Patches
Plain Diff
Fixed coding style for line ending sniff and added CSS and JS support.
parent
303d460c
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
DrupalCodingStandard/Sniffs/WhiteSpace/LineEndingSniff.php
+58
-46
58 additions, 46 deletions
DrupalCodingStandard/Sniffs/WhiteSpace/LineEndingSniff.php
with
58 additions
and
46 deletions
DrupalCodingStandard/Sniffs/WhiteSpace/LineEndingSniff.php
+
58
−
46
View file @
2caa5e7b
<?php
class
DrupalCodingStandard_Sniffs_WhiteSpace_LineEndingSniff
implements
PHP_CodeSniffer_Sniff
{
/**
* A list of tokenizers this sniff supports.
*
* @var array
*/
public
$supportedTokenizers
=
array
(
'PHP'
);
/**
* Returns an array of tokens this test wants to listen for.
*
* @return array
*/
public
function
register
()
{
return
array
(
class
DrupalCodingStandard_Sniffs_WhiteSpace_LineEndingSniff
implements
PHP_CodeSniffer_Sniff
{
/**
* A list of tokenizers this sniff supports.
*
* @var array
*/
public
$supportedTokenizers
=
array
(
'PHP'
,
'JS'
,
'CSS'
,
);
/**
* Returns an array of tokens this test wants to listen for.
*
* @return array
*/
public
function
register
()
{
return
array
(
T_OPEN_TAG
,
T_CLOSE_TAG
,
T_WHITESPACE
,
T_COMMENT
,
T_DOC_COMMENT
,
);
}
/**
* Processes this sniff, 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.
*
* @return void
*/
public
function
process
(
PHP_CodeSniffer_File
$phpcsFile
,
$stackPtr
)
{
$tokens
=
$phpcsFile
->
getTokens
();
// Check for end of line whitespace.
if
(
strpos
(
$tokens
[
$stackPtr
][
'content'
],
$phpcsFile
->
eolChar
)
===
FALSE
)
{
return
;
}
$tokenContent
=
rtrim
(
$tokens
[
$stackPtr
][
'content'
],
$phpcsFile
->
eolChar
);
if
(
empty
(
$tokenContent
)
===
FALSE
)
{
if
(
preg_match
(
'|^.*\s+$|'
,
$tokenContent
)
!==
0
)
{
$phpcsFile
->
addError
(
'Whitespace found at end of line'
,
$stackPtr
,
'EndLine'
);
}
}
}
}
?>
\ No newline at end of file
}
//end register()
/**
* Processes this sniff, 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.
*
* @return void
*/
public
function
process
(
PHP_CodeSniffer_File
$phpcsFile
,
$stackPtr
)
{
$tokens
=
$phpcsFile
->
getTokens
();
// Check for end of line whitespace.
if
(
strpos
(
$tokens
[
$stackPtr
][
'content'
],
$phpcsFile
->
eolChar
)
===
false
)
{
return
;
}
$tokenContent
=
rtrim
(
$tokens
[
$stackPtr
][
'content'
],
$phpcsFile
->
eolChar
);
if
(
empty
(
$tokenContent
)
===
false
)
{
if
(
preg_match
(
'|^.*\s+$|'
,
$tokenContent
)
!==
0
)
{
$phpcsFile
->
addError
(
'Whitespace found at end of line'
,
$stackPtr
,
'EndLine'
);
}
}
}
//end process()
}
//end class
?>
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment