PHP_CodeSniffer tokenizes PHP files and detects violations of a defined set of coding standards.
BSD-3-CLAUSE License
Bot releases are hidden (Show)
Published by gsherwood about 6 years ago
Support for HHVM has been dropped due to recent unfixed bugs and HHVM's refocus on Hack only. Thanks to Walt Sorensen and Juliette Reinders Folmer for helping to remove all HHVM exceptions from the core.
full
report (the default report) now has improved word wrapping for multi-line messages and sniff codes
summary
report now sorts files based on their directory location instead of just a basic string sort
source
report now orders error codes by name when they have the same number of errors
junit
report no longer generates validation errors with the Jenkins xUnit plugin
Generic.Commenting.DocComment
no longer generates the SpacingBeforeTags
error if tags are the first content in the docblock
MissingShort
error if there is no short commentMissingShort
error to be suppressed in a ruleset to make short descriptions optionalGeneric.Functions.FunctionCallArgumentSpacing
now properly fixes multi-line function calls with leading commas
Generic.PHP.Syntax
will now use PHP_BINARY
instead of trying to discover the executable path
php_path
config var will still override this value as normalPSR2.Namespaces.UseDeclaration
now supports commas at the end of group use declarations
Squiz.Arrays.ArrayDeclaration
no longer removes the array opening brace while fixing
KeyNotAligned
error message being incorrectly reported in these casesSquiz.Arrays.ArrayDeclaration
no longer tries to change multi-line arrays to single line when they contain comments
Squiz.Classes.ClassDeclaration
no longer enforces spacing rules when a class is followed by a function
Squiz.WhiteSpace.FunctionSpacing
sniffSquiz.Classes.ValidClassName.NotCamelCaps
message now references PascalCase instead of CamelCase
CamelCase class name
metric produced by the sniff has been changed to PascalCase class name
Squiz.Commenting.InlineComment
no longer enforces spacing rules when an inline comment is followed by a docblock
Squiz.WhiteSpace.FunctionSpacing
sniffSquiz.WhiteSpace.OperatorSpacing
no longer tries to fix operator spacing if the next content is a comment on a new line
Squiz.Commenting.PostStatementComment
sniffSquiz.WhiteSpace.FunctionSpacing
no longer checks spacing of functions at the top of an embedded PHP block
Squiz.PHP.EmbeddedPHP
sniffSquiz.WhiteSpace.MemberVarSpacing
no longer checks spacing before member vars that come directly after methods
Squiz.WhiteSpace.FunctionSpacing
sniffSquiz.WhiteSpace.SuperfluousWhitespace
now recognizes unicode whitespace at the start and end of a file
Published by gsherwood over 6 years ago
The Squiz.WhiteSpace.LanguageConstructSpacing
sniff has been deprecated and will be removed in version 4.
The sniff has been moved to the Generic standard, with a new code of Generic.WhiteSpace.LanguageConstructSpacing
. The new Generic sniff now also checks many more language constructs to enforce additional spacing rules. The existing Squiz sniff will continue to work until version 4 has been released. Thanks to Mponos George for the contribution.
As soon as possible, replace all instances of the old sniff code with the new sniff code in your ruleset.xml files.
The current method for setting array properties in ruleset files has been deprecated and will be removed in version 4.
Currently, setting an array value uses the string syntax print=>echo,create_function=>null
. Now, individual array elements are specified using a new element
tag with key
and value
attributes.
For example, the following array of forbidden functions:
<property name="forbiddenFunctions" type="array" value="sizeof=>count,delete=>unset,print=>echo,is_null=>null,create_function=>null"/>
Will be rewritten using this format:
<property name="forbiddenFunctions" type="array">
<element key="sizeof" value="count"/>
<element key="delete" value="unset"/>
<element key="print" value="echo"/>
<element key="is_null" value="null"/>
<element key="create_function" value="null"/>
</property>
Thanks to Michał Bundyra for the patch.
The T_ARRAY_HINT
token has been deprecated and will be removed in version 4.
The token was used to ensure array type hints were not tokenized as T_ARRAY
, but no other type hints were given a special token. Array type hints now use the standard T_STRING
token instead.
Sniffs referencing this token type will continue to run without error until version 4, but will not find any T_ARRAY_HINT
tokens.
The T_RETURN_TYPE token has been deprecated and will be removed in version 4.
The token was used to ensure array/self/parent/callable return types were tokenized consistently. But for namespaced return types, only the last part of the string (the class name) was tokenized as T_RETURN_TYPE
. This was not consistent and so return types are now left using their original token types so they are not skipped by sniffs. The exception are array return types, which are tokenized as T_STRING
instead of T_ARRAY
, as they are used for type hints.
Sniffs referencing this token type will continue to run without error until version 4, but will not find any T_RETUTN_TYPE
tokens.
To get the return type of a function, use the File::getMethodProperties()
method, which now contains a return_type
array index. This index contains the return type of the function or closer, or a blank string if not specified. If the return type is nullable, the return type will contain the leading ?
and a nullable_return_type
array index in the return value will also be set to true
. If the return type contains namespace information, it will be cleaned of whitespace and comments. To access the original return value string, use the main tokens array.
This release contains an incomplete version of the PSR-12 coding standard. Errors found using this standard should be valid, but it will miss a lot of violations until it is complete. If you'd like to test and help, you can use the standard by running PHPCS with --standard=PSR12
Published by gsherwood over 6 years ago
phpcs:
comment syntax can now be prefixed with an at symbol ( @phpcs:
)
Tokens::$phpcsCommentTokens
array is now available for sniff developers to detect phpcs:
comment syntax
Generic.CodeAnalysis.EmptyStatement
are no longer all-uppercase
Generic.CodeAnalysis.EmptyStatement.DetectedCATCH
becomes Generic.CodeAnalysis.EmptyStatement.DetectedCatch
PEAR.Commenting.FunctionComment.Missing
error message now includes the name of the function
PEAR.Commenting.ClassComment.Missing
and Squiz.Commenting.ClassComment.Missing
error messages now include the name of the class
PEAR.Functions.FunctionCallSignature
now only forces alignment at a specific tab stop while fixing
Generic.Files.LineLength
now ignores lines that only contain phpcs:
annotation comments
Generic.Formatting.MultipleStatementAlignment
now skips over arrays containing comments
Generic.PHP.Syntax
now forces display_errors
to ON
when linting
PSR2.Namespaces.UseDeclaration
has improved syntax error handling and closure detection
Squiz.PHP.CommentedOutCode
now has improved comment block detection for improved accuracy
Squiz.PHP.NonExecutableCode
could fatal error while fixing file with syntax errorSquiz.PHP.NonExecutableCode
now detects unreachable code after a goto statement
Squiz.WhiteSpace.LanguageConstructSpacing
has improved syntax error handling while fixing
phpcs:
annotation syntax handling for a number of sniffs
Published by gsherwood almost 7 years ago
Published by gsherwood almost 7 years ago
Generic.Functions.OpeningFunctionBraceKernighanRitchie
no longer complains when the open brace is followed by a close tag
Published by gsherwood almost 7 years ago
This release deprecates the @codingStandards
comment syntax used for sending commands to PHP_CodeSniffer. The existing syntax will continue to work in all version 3 releases, but will be removed in version 4
The comment formats have been replaced by a shorter syntax:
@codingStandardsIgnoreFile
becomes phpcs:ignoreFile
@codingStandardsIgnoreStart
becomes phpcs:disable
@codingStandardsIgnoreEnd
becomes phpcs:enable
@codingStandardsIgnoreLine
becomes phpcs:ignore
@codingStandardsChangeSetting
becomes phpcs:set
The new syntax allows for additional developer comments to be added after a --
separator. This is useful for describing why a code block is being ignored, or why a setting is being changed. E.g., // phpcs:disable -- This code block must be left as-is.
Comments using the new syntax are assigned new comment token types to allow them to be detected:
phpcs:ignoreFile
has the token T_PHPCS_IGNORE_FILE
phpcs:disable
has the token T_PHPCS_DISABLE
phpcs:enable
has the token T_PHPCS_ENABLE
phpcs:ignore
has the token T_PHPCS_IGNORE
phpcs:set
has the token T_PHPCS_SET
phpcs:disable
and phpcs:ignore
comments can now selectively ignore specific sniffs (request #604)
// phpcs:disable Generic.Commenting.Todo.Found
for a specific message// phpcs:disable Generic.Commenting.Todo
for a whole sniff// phpcs:disable Generic.Commenting
for a whole category of sniffs// phpcs:disable Generic
for a whole standard// phpcs:disable Generic.Commenting.Todo,PSR1.Files
@codingStandardsIgnoreLine
comments now only ignore the following line if they are on a line by themselves
PSR1.Files.SideEffects
now respects the new phpcs:disable
comment syntax
phpcs:disable
and phpcs:enable
commentsphpcs:ignore
; you must wrap code structures with disable/enable commentsphpcs.xsd
to allow validation of ruleset XML files
--stdin-path
can now point to fake file locations (request #1488)
--basepath=
) on the CLI will now clear a basepath set directly in a ruleset
AbstractVariableSniff
abstract sniff now supports anonymous classes and nested functions
Squiz.Scope.MemberVarScope
where member vars of anonymous classes were not being checkedAbstractArraySniff
to make it easier to create sniffs that check array formatting
Generic.Arrays.ArrayIndent
to enforce a single tab stop indent for array keys in multi-line arrays
indent
property of the sniffGeneric.PHP.DiscourageGoto
to warn about the use of the GOTO language construct
Generic.Debug.ClosureLinter
was not running the gjslint
command
Generic.WhiteSpace.DisallowSpaceIndent
now fixes space indents in multi-line block comments
Generic.WhiteSpace.DisallowSpaceIndent
now fixes mixed space/tab indents more accurately
Generic.WhiteSpace.DisallowTabIndent
now fixes tab indents in multi-line block comments
PEAR.Functions.FunctionDeclaration
no longer errors when a function declaration is the first content in a JS file
PEAR.Functions.FunctionCallSignature
now requires the function name to be indented to an exact tab stop
PEAR.Functions.FunctionCallSignature.OpeningIndent
for this errorSquiz.Functions.FunctionDeclarationArgumentSpacing
is no longer confused about comments in function declarations
Squiz.PHP.NonExecutableCode
error messages now indicate which line the code block ending is on
Squiz.Commenting.FunctionComment
now supports nullable type hintsSquiz.Commenting.FunctionCommentThrowTag
no longer assigns throw tags inside anon classes to the enclosing functionSquiz.WhiteSpace.SemicolonSpacing
now ignores semicolons used for empty statements inside FOR conditions
Squiz.ControlStructures.ControlSignature
now allows configuring the number of spaces before the colon in alternative syntax
requiredSpacesBeforeColon
setting in a ruleset.xml file to change1
Published by gsherwood about 7 years ago
phpcs.xml
and phpcs.xml.dist
.phpcs.xml
, phpcs.xml
, .phpcs.xml.dist
, phpcs.xml.dist
Squiz.Commenting.InlineComment
incorrectly identified comment blocks in some cases, muting some errors
Published by gsherwood about 7 years ago
phpunit --bootstrap=/path/to/phpcs/tests/bootstrap.php
phpcs.xml
or phpcs.xml.dist
file now takes precedence over the default_standard config setting
phpcs.xml
and phpcs.xml.dist
files can now be prefixed with a dot (request #1566)
.phpcs.xml
, .phpcs.xml.dist
, phpcs.xml
, phpcs.xml.dist
OR
logic instead of AND
logic
--config-show
, --config-set
, and --config-delete
now includes the path to the loaded config file/**
are now always tokenized as docblocks
T_YIELD
and T_YIELD_FROM
tokens have been replicated for older PHP versions
Generic.CodeAnalysis.AssignmentInCondition
sniff to warn about variable assignments inside conditions
Generic.Files.OneObjectStructurePerFile
sniff to ensure there is a single class/interface/trait per file
Generic.Functions.FunctionCallArgumentSpacing
, PEAR.Functions.FunctionCallSignature
, and PSR2.Methods.FunctionCallSignature
Generic.Files.LineLength
can now be configured to ignore all comment lines, no matter their length
ignoreComments
property to TRUE
(default is FALSE
) in your ruleset.xml
file to enable thisGeneric.PHP.LowerCaseKeyword
now checks self, parent, yield, yield from, and closure (function) keywords
PEAR.Functions.FunctionDeclaration
now removes a blank line if it creates one by moving the curly brace during fixingSquiz.Commenting.FunctionCommentThrowTag
now supports PHP 7.1 multi catch exceptionsSquiz.Formatting.OperatorBracket
no longer throws errors for PHP 7.1 multi catch exceptionsSquiz.Commenting.LongConditionClosingComment
now supports finally statementsSquiz.Formatting.OperatorBracket
now correctly fixes pipe separated flagsSquiz.Formatting.OperatorBracket
now correctly fixes statements containing short array syntaxSquiz.PHP.EmbeddedPhp
now properly fixes cases where the only content in an embedded PHP block is a comment
Squiz.WhiteSpace.ControlStructureSpacing
now ignores comments when checking blank lines at the top of control structuresSquiz.WhiteSpace.ObjectOperatorSpacing
now detects and fixes spaces around double colons
Squiz.WhiteSpace.MemberVarSpacing
can now be configured to check any number of blank lines between member vars
spacing
property (default is 1
) in your ruleset.xml
file to set the spacingSquiz.WhiteSpace.MemberVarSpacing
can now be configured to check a different number of blank lines before the first member var
spacingBeforeFirst
property (default is 1
) in your ruleset.xml
file to set the spacingPHP_CodeSniffer\Util\Tokens::$ooScopeTokens
static member var for quickly checking object scope
T_CLASS
, T_ANON_CLASS
, T_INTERFACE
, and T_TRAIT
PHP_CodeSniffer\Files\File::findExtendedClassName()
now supports extended interfaces
Published by gsherwood over 7 years ago
--cache=/path/to/cachefile
CLI argument was not workingRunner::runPHPCS()
or Runner::runPHPCBF()
directly, you will get back the full range of exit codesDeepExitException
to get the error message ($e->getMessage()
) and exit code ($e->getCode()
)--suffix
argument
// comment
before PHP close tag
Published by gsherwood over 7 years ago
--filter=gitmodified
command line option--stdin-path
CLI option to --help
--file-list
and --bootstrap
CLI options to --help
Runner::runPHPCS()
and Runner::runPHPCBF()
now return an exit code instead of exiting directly (request #1484)class_alias()
\Sniffs\
)MyProject\CS\Standard\Sniffs\Category
set the namespace to MyProject\CS\Standard
<ruleset name="My Coding Standard" namespace="MyProject\CS\Standard">
$config->unknown
Published by gsherwood over 7 years ago
Published by gsherwood over 7 years ago
This is the first stable release of the 3.0 branch, and is a large refactoring of the code base. It breaks backwards compatibility for all custom sniffs and custom reports. An upgrade guide for sniff and report developers is available here: https://github.com/squizlabs/PHP_CodeSniffer/wiki/Version-3.0-Upgrade-Guide
Note: If you only use the built-in coding standards (such as PEAR or PSR2), or you have a custom ruleset.xml file that only makes use of the sniffs and reports distributed with PHP_CodeSniffer, you do not need to make any changes to begin using the 3.0.0 version.
There are no future planned releases for the 2.x branch, but there may still be additional 2.9.x versions released for a time due to the number of changes required to upgrade custom sniffs for 3.0. The intention is to limit 2.9.x releases to serious bug and security fixes only.
For a full list of changes from the 2.x version, please review the following changelogs:
https://github.com/squizlabs/PHP_CodeSniffer/releases/tag/3.0.0a1
https://github.com/squizlabs/PHP_CodeSniffer/releases/tag/3.0.0RC1
https://github.com/squizlabs/PHP_CodeSniffer/releases/tag/3.0.0RC2
https://github.com/squizlabs/PHP_CodeSniffer/releases/tag/3.0.0RC3
https://github.com/squizlabs/PHP_CodeSniffer/releases/tag/3.0.0RC4
Published by gsherwood over 7 years ago
Published by gsherwood over 7 years ago
Published by gsherwood over 7 years ago
Published by gsherwood over 7 years ago
Published by gsherwood over 7 years ago
Published by gsherwood almost 8 years ago
Published by gsherwood almost 8 years ago