Download the PHP package isaac/php-code-sniffer-baseliner without Composer
On this page you can find all versions of the php package isaac/php-code-sniffer-baseliner. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download isaac/php-code-sniffer-baseliner
More information about isaac/php-code-sniffer-baseliner
Files in isaac/php-code-sniffer-baseliner
Package php-code-sniffer-baseliner
Short Description ISAAC PHP Code Sniffer Baseliner
License MIT
Informations about the package php-code-sniffer-baseliner
Renamed and moved to iO CodeSniffer Standard
This repository has been archived and renamed, moved to iO PHP_CodeSniffer Baseliner. Feature sniffs and changes will be processed in the iO repository.
PHP_CodeSniffer Baseliner
This tool enables you to integrate PHP_CodeSniffer into an existing
project by automatically adding phpcs:ignore
and phpcs:disable
/phpcs:enable
instructions throughout the codebase
as a baseline. This allows you to make PHP_CodeSniffer pass without changing any source code, making it
possible to use PHP_CodeSniffer in e.g. continuous integration pipelines or git hooks. This way, you can enforce that
all new code adheres to your coding standard without touching the existing code.
Installation
Require the package with composer:
It is also possible to install this package as a global composer dependency.
Usage
In order to add phpcs:ignore
and phpcs:disable
/phpcs:enable
instructions throughout your project, run:
How does it work?
First, the tool runs vendor/bin/phpcs
and captures the report. Based on the report output, it will add
// phpcs:ignore
instructions to the source code for each violation. It will only ignore the sniffs that actually are
violated. In rare cases, adding these instructions could introduce new violations. Therefore, this process is repeated
until no violations are reported by phpcs
.
Example
Let's say we want to enforce declare(strict_types = 1);
statements and native property type hints using
PHP_CodeSniffer. The Slevomat Coding Standard has sniffs for this:
SlevomatCodingStandard.TypeHints.DeclareStrictTypes
and SlevomatCodingStandard.TypeHints.PropertyTypeHint.MissingNativeTypeHint
. We install
Slevomat Coding Standard and add the sniffs to our ruleset in phpcs.xml
.
If we now run vendor/bin/phpcs-baseliner create-baseline
in our project, it will add ignore instructions in all files
not containing declare(strict_types = 1);
statements or native property type declarations:
In some cases, it is not possible to insert a // phpcs:ignore
instruction directly above the violated line (e.g.
multi-line strings). In those cases, // phpcs:disable
and // phpcs:enable
instructions are added:
Features
- Automatic indentation
- Ignoring a group of multiple exclusions per line, e.g.
// phpcs:ignore Generic.Files.LineLength.TooLong, Generic.Arrays.DisallowLongArraySyntax -- baseline
- Merging new instructions with existing instructions
- Messages of existing instructions are merged as wel:
// phpcs:ignore Generic.Files.LineLength.TooLong, Generic.Arrays.DisallowLongArraySyntax -- existing message; baseline
- Using
phpcs:disable
/phpcs:enable
when insertingphpcs:ignore
is not possible (i.e. for multi-line strings, including HEREDOCs and NOWDOCs) -
Adding a star prefix when a violation is found within a comment block with stars, e.g.:
- All features are unit tested, see the
AddBaselineProcessorTestDataProvider
class for an extensive test data set.
Roadmap
- Support processing files that do not start with ``.
-
Support ignoring violations on the first line of a file that end with a multi-line string, example:
- Support detection of and merging with older types of ignore instructions, such as
@phpcsSuppress
.
All versions of php-code-sniffer-baseliner with dependencies
ext-dom Version *
ext-json Version *
ext-simplexml Version *
squizlabs/php_codesniffer Version ^3.5