-
Notifications
You must be signed in to change notification settings - Fork 1
Comprehensive update: use PSR12, PHPCompatibility, add Readme, add QA #1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
In contrast to plain ruleset, a PHPCS "standard" can: * Be registered with PHPCS and used by name, both on the command line as well as in custom rulesets. * Contain custom sniffs, if so desired. For a ruleset to be recognized as a standard by PHPCS, it should: * Live in a folder which matches the name of the standard * That folder must contain a `ruleset.xml` file. By moving the `ruleset.xml` file to a `PHPParallelLint` folder and changing the name of the standard to `PHPParallelLint`, this ruleset should now be usable as a standard. Includes updating the description to match the current reality.
As things were, this package contained a ruleset, but did not declare its dependency on PHP_CodeSniffer, so the package would not be usable without the dependant declaring a dependency on PHPCS. This commit fixes this by: 1. Declaring PHPCS as a dependency in the `composer.json` file. 2. Declaring a dependency on the DealerDirect Composer plugin which can automatically handle the registration of PHPCS standards with PHPCS. With these two dependencies in place, the package can be used as a self-contained package. Includes adding a `.gitignore` file to prevent the `composer.lock` and `vendor` directory from being committed, as well as a `.gitattributes` file to prevent the `.gitignore` (and `.gitattributes`) file from being included in distributed packages.
This workflow will check that: * The `composer.json` is valid. * The declared dependencies install without problems. * The PHPCS ruleset validates against the XML scheme for PHPCS rulesets. * The PHPCS ruleset is consistent in code-style. Includes adding the `.github` directory to the `.gitattributes` file to be excluded from distribution packages.
This commit: * Adds the complete PSR12 ruleset to this standard. * Excludes one PSR12 sniff which requires a higher minimum PHP version (PHP 7.1), than the projects in the organisation support. * Removes any individual sniff inclusions for sniffs also included in PSR12. This can be verified by running the following command which shows exactly which sniffs are included in PSR12: ```bash vendor/bin/phpcs --standard=PSR12 -e ```
* The `PEAR.Functions.FunctionDeclaration` sniff can be removed as the PSR12 standard contains the following sniffs which together provide the same safeguards and more: `Squiz.Functions.FunctionDeclaration` and `Squiz.Functions.MultiLineFunctionDeclaration` * The `PEAR.Functions.FunctionCallSignature` sniff can be removed as the PSR12 standard contains the semi-equivalent `PSR2.Methods.FunctionCallSignature` sniff. Note: I'm also removing the exclusions from the standard. IMO, the standard should not have an opinion on this. A custom ruleset for an individual project can bring these exclusions back if/when needed. * The `PEAR.WhiteSpace.ScopeClosingBrace` sniff can be removed as the PSR12 standard contains the semi-equivalent `Squiz.WhiteSpace.ScopeClosingBrace` sniff. * The `PEAR.Classes.ClassDeclaration` sniff can be removed as the PSR12 standard contains the more comprehensive `PSR2.Classes.ClassDeclaration` sniff. * The `PEAR.ControlStructures.ControlSignature` sniff can be removed as the PSR12 standard contains the more comprehensive `Squiz.ControlStructures.ControlSignature` sniff. * The `Zend.Files.ClosingTag` sniff can be removed as the PSR12 standard contains the semi-equivalent `PSR2.Files.ClosingTag` sniff.
* The `PSR12.ControlStructures.BooleanOperatorPlacement` sniffs checks for consistent placement of boolean operators in control structure conditions. The extra property enforces that these are always placed at the start of a line. * PSR12 has no opinion on array formatting. The `Generic.Arrays.ArrayIndent` sniff will at least safeguard some semblance of normalized arrays. * The `Generic.CodeAnalysis.EmptyPHPStatement` prevents empty PHP statements, like when there is a duplicate semi-colon at the end of a statement. * The `Generic.ControlStructures.DisallowYodaConditions` ensures that conditions never use Yoda. * Additionally, the `Generic.CodeAnalysis.ForLoopShouldBeWhileLoop`, `Generic.CodeAnalysis.JumbledIncrementer`, `Generic.CodeAnalysis.UnconditionalIfStatement`, `Generic.CodeAnalysis.UnnecessaryFinalModifier`, `Generic.PHP.ForbiddenFunctions` and the `Squiz.WhiteSpace.SemicolonSpacing` sniffs, which were already in use in the PHP Parallel Lint repo, but not in the other repos, have also been added. Note: the `Generic.PHP.DeprecatedFunctions` sniff, as used in the PHP Parallel Lint repo, has **not** been added as the PHPCompatibility standard included a far more comprehensive and stable sniff for the same.
The PHPCompatibility standard can detect a large range of PHP cross-version incompatibilities and flag these, to prevent code being committed to the projects which is incompatible with the minimum supported PHP version of those projects. For optimal results, the projects using this standard should set a `testVersion` to inform PHPCompatibility which PHP versions the code should be compatible with. For more information, see the README of the project. Ref: https://github.com/PHPCompatibility/PHPCompatibility/
... with the most basic information about the coding standard.
* Add a `description`, so the `composer.json` will validate. * Remove the `version` key as recommended by Composer.
Thank you :-) |
@grogy Shall I tag version 2.0.0 for this repo ? We can then start using these changes with the other repos via managed updates. |
@jrfnl yes, current state of code-style looks good. Real using in repositories will help. Please, create tag new version |
When tagging I realized I'd still forgotten one tiny change which was still needed - see the extra commit I've just pushed. I've now tagged 2.0 and will pull the first PR to start using it to the Console Color repo. |
PR with upgrade library is merged, thank you. |
Ruleset: allow for usage as a standard
In contrast to plain ruleset, a PHPCS "standard" can:
For a ruleset to be recognized as a standard by PHPCS, it should:
ruleset.xml
file.By moving the
ruleset.xml
file to aPHPParallelLint
folder and changing the name of the standard toPHPParallelLint
, this ruleset should now be usable as a standard.Includes updating the description to match the current reality.
Make the PHPCS standard self-contained
As things were, this package contained a ruleset, but did not declare its dependency on PHP_CodeSniffer, so the package would not be usable without the dependant declaring a dependency on PHPCS.
This commit fixes this by:
composer.json
file.With these two dependencies in place, the package can be used as a self-contained package.
Includes adding a
.gitignore
file to prevent thecomposer.lock
andvendor
directory from being committed, as well as a.gitattributes
file to prevent the.gitignore
(and.gitattributes
) file from being included in distributed packages.GH Actions: add a basic QA workflow
This workflow will check that:
composer.json
is valid.Includes adding the
.github
directory to the.gitattributes
file to be excluded from distribution packages.Ruleset: check code style against PSR12
This commit:
This can be verified by running the following command which shows exactly which sniffs are included in PSR12:
Ruleset: remove more redundant rules
PEAR.Functions.FunctionDeclaration
sniff can be removed as the PSR12 standard contains the following sniffs which together provide the same safeguards and more:Squiz.Functions.FunctionDeclaration
andSquiz.Functions.MultiLineFunctionDeclaration
PEAR.Functions.FunctionCallSignature
sniff can be removed as the PSR12 standard contains the semi-equivalentPSR2.Methods.FunctionCallSignature
sniff.Note: I'm also removing the exclusions from the standard. IMO, the standard should not have an opinion on this. A custom ruleset for an individual project can bring these exclusions back if/when needed.
PEAR.WhiteSpace.ScopeClosingBrace
sniff can be removed as the PSR12 standard contains the semi-equivalentSquiz.WhiteSpace.ScopeClosingBrace
sniff.PEAR.Classes.ClassDeclaration
sniff can be removed as the PSR12 standard contains the more comprehensivePSR2.Classes.ClassDeclaration
sniff.PEAR.ControlStructures.ControlSignature
sniff can be removed as the PSR12 standard contains the more comprehensiveSquiz.ControlStructures.ControlSignature
sniff.Zend.Files.ClosingTag
sniff can be removed as the PSR12 standard contains the semi-equivalentPSR2.Files.ClosingTag
sniff.Ruleset: order remaining extra rules alphabetically
Ruleset: add a few extra sniffs + a property for one of the PSR12 sniffs
PSR12.ControlStructures.BooleanOperatorPlacement
sniffs checks for consistent placement of boolean operators in control structure conditions.The extra property enforces that these are always placed at the start of a line.
Generic.Arrays.ArrayIndent
sniff will at least safeguard some semblance of normalized arrays.Generic.CodeAnalysis.EmptyPHPStatement
prevents empty PHP statements, like when there is a duplicate semi-colon at the end of a statement.Generic.ControlStructures.DisallowYodaConditions
ensures that conditions never use Yoda.Generic.CodeAnalysis.ForLoopShouldBeWhileLoop
,Generic.CodeAnalysis.JumbledIncrementer
,Generic.CodeAnalysis.UnconditionalIfStatement
,Generic.CodeAnalysis.UnnecessaryFinalModifier
,Generic.PHP.ForbiddenFunctions
and theSquiz.WhiteSpace.SemicolonSpacing
sniffs, which were already in use in the PHP Parallel Lint repo, but not in the other repos, have also been added.Note: the
Generic.PHP.DeprecatedFunctions
sniff, as used in the PHP Parallel Lint repo, has not been added as the PHPCompatibility standard included a far more comprehensive and stable sniff for the same.Composer/Ruleset: include the PHPCompatibility standard
The PHPCompatibility standard can detect a large range of PHP cross-version incompatibilities and flag these, to prevent code being committed to the projects which is incompatible with the minimum supported PHP version of those projects.
For optimal results, the projects using this standard should set a
testVersion
to inform PHPCompatibility which PHP versions the code should be compatible with.For more information, see the README of the project.
Ref: https://github.com/PHPCompatibility/PHPCompatibility/
Add a README
... with the most basic information about the coding standard.
Composer: minor tweaks
description
, so thecomposer.json
will validate.version
key as recommended by Composer.