-
-
Notifications
You must be signed in to change notification settings - Fork 7
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
Add the base rulesets #7
Merged
Merged
Conversation
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 will allow PHPCS to recognize PHPCSUtils as if it were an external PHPCS standard and handle the autoloading of all PHPCSUtils files automatically when using PHPCS 3+. External standards using PHPCSUtils don't even need to add `<rule ref="PHPCSUtils"/>` to their own ruleset. All that is needed is for the PHPCSUtils standard to be in the PHPCS `installed_paths` which - for Composer based installs - will automatically be taken care of by the DealerDirect Composer PHPCS plugin which is a required dependency for this package.
... for external standards which have their own test suite. In PHPCS > 3.0.2+, when using the PHPCS native test suite, the files from PHPCSUtils will automatically load correctly. However, when using a custom test suite, this will generally not be the case. Requiring the `phpcsutils-autoload.php` file in the test runner bootstrap file will fix this. Alternatively, if only Composer-based installs are supported, loading the `vendor/autoload.php` file generated by Composer should also fix this. Notes: * The file is named `phpcsutils-autoload.php` instead of `autoload.php` to prevent potential confusion with other autoload files. Also see: squizlabs/PHP_CodeSniffer 2751 * The autoloader definition is wrapped within a constant check to prevent conflicts/the autoloader from being registered multiple times, when several external PHPCS standards each use PHPCSUtils.
This commit is two-fold: 1. It enhances the `phpcsutils-autoload.php` file to contain class aliases to translate the relevant PHPCS 3.x class names to PHPCS 2.x class names which, in effect, allows for the PHPCSUtils utilities to be used in both PHPCS 2.x as well as PHPCS 3.x. 2. It adds a `PHPCS23Utils` ruleset with one `PHPCS23Utils.Load.LoadUtils` sniff. The only thing this standard does is trigger the PHPCSUtils autoload file in PHPCS 2.x. This standard will not include any utilities or real sniffs. It is just in place to enable support for PHPCS 2.x in an as-simple-as-possible manner.
This: * Adds a custom PHPCS ruleset which uses the `PHPCSDev` ruleset to check the code style of code in this repo, with a few, very select, exclusions. * Adds convenience scripts to the `composer.json` file to check the code of the repo. * And allows for individual developers to overload the `phpcs.xml.dist` file by ignoring the typical overload files. **Important notes**: 1. The `compose require` is done directly in the Composer script rather than in the `require-dev` section as the PHPCS requirements for the `PHPCSDevTools` package can conflict with the PHPCS requirements of this package. The CS check for this package should always be run on a recent PHPCS version to get the benefit of new sniffs, while the Utils themselves are - and should be - compatible with a wider range of PHPCS versions. 2. Using the above "trick" runs into issues when trying to remove the package on Travis due to some phantom _uncommitted changes in the `vendor/phpcstandards/phpcsdevtools` directory_. So, a separate script is used for Travis which doesn't `composer remove` of `PHPCSDevTools`. 3. For the time being - until v 1.0.0 has been tagged for the `PHPCSDevTools` package -, the `require` will use the `dev-develop` branch of `PHPCSDevTools`. Also, the `composer validate` check doesn't need to be run on every build. Running it on just one build is sufficient, so moving it to the `sniff` stage.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR adds the base rulesets for PHPCSUtils.
It also puts QA in place to:
Commit details:
PHPCSUtils: add the ruleset file
This will allow PHPCS to recognize PHPCSUtils as if it were an external PHPCS standard and handle the autoloading of all PHPCSUtils files automatically when using PHPCS 3+.
External standards using PHPCSUtils don't even need to add
<rule ref="PHPCSUtils"/>
to their own ruleset.All that is needed is for the PHPCSUtils standard to be in the PHPCS
installed_paths
which - for Composer based installs - will automatically be taken care of by the DealerDirect Composer PHPCS plugin which is arequire
d dependency for this package.PHPCSUtils: add an (optional) autoloader
... for external standards which have their own test suite.
In PHPCS > 3.0.2+, when using the PHPCS native test suite, the files from PHPCSUtils will automatically load correctly.
However, when using a custom test suite, this will generally not be the case.
Requiring the
phpcsutils-autoload.php
file in the test runner bootstrap file will fix this.Alternatively, if only Composer-based installs are supported, loading the
vendor/autoload.php
file generated by Composer should also fix this.Notes:
phpcsutils-autoload.php
instead ofautoload.php
to prevent potential confusion with other autoload files.Also see: Autoload relative paths first to avoid confusion with files from the global include path squizlabs/PHP_CodeSniffer#2751
PHPCS23Utils: add support for PHPCS 2.x
This commit is two-fold:
It enhances the
phpcsutils-autoload.php
file to contain class aliases to translate the relevant PHPCS 3.x class names to PHPCS 2.x class names which, in effect, allows for the PHPCSUtils utilities to be used in both PHPCS 2.x as well as PHPCS 3.x.It adds a
PHPCS23Utils
ruleset with onePHPCS23Utils.Load.LoadUtils
sniff.The only thing this standard does is trigger the PHPCSUtils autoload file in PHPCS 2.x.
This standard will not include any utilities or real sniffs. It is just in place to enable support for PHPCS 2.x in an as-simple-as-possible manner.
🔧 QA: lint the ruleset XML files
🔧 QA: lint PHP files in this repo
🔧 QA: add code style check for the code in this repo
This:
PHPCSDev
ruleset to check the code style of code in this repo, with a few, very select, exclusions.composer.json
file to check the code of the repo.phpcs.xml.dist
file by ignoring the typical overload files.Important notes:
compose require
is done directly in the Composer script rather than in therequire-dev
section as the PHPCS requirements for thePHPCSDevTools
package can conflict with the PHPCS requirements of this package.The CS check for this package should always be run on a recent PHPCS version to get the benefit of new sniffs, while the Utils themselves are - and should be - compatible with a wider range of PHPCS versions.
Using the above "trick" runs into issues when trying to remove the package on Travis due to some phantom uncommitted changes in the
vendor/phpcstandards/phpcsdevtools
directory. So, a separate script is used for Travis which doesn'tcomposer remove
ofPHPCSDevTools
.For the time being - until v 1.0.0 has been tagged for the
PHPCSDevTools
package -, therequire
will use thedev-develop
branch ofPHPCSDevTools
.Also, the
composer validate
check doesn't need to be run on every build. Running it on just one build is sufficient, so moving it to thesniff
stage.