Skip to content

Commit

Permalink
Merge pull request #38 from PHPCSStandards/develop
Browse files Browse the repository at this point in the history
Release 1.0.0-alpha2
  • Loading branch information
jrfnl committed Feb 18, 2020
2 parents 8670f18 + 0a0e2f2 commit 65e057f
Show file tree
Hide file tree
Showing 47 changed files with 2,103 additions and 129 deletions.
3 changes: 3 additions & 0 deletions .coveralls.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
coverage_clover: build/logs/clover.xml
json_path: build/logs/coveralls-upload.json
service_name: travis-ci
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
# https://www.reddit.com/r/PHP/comments/2jzp6k/i_dont_need_your_tests_in_my_production
# https://blog.madewithlove.be/post/gitattributes/
#
/.coveralls.yml export-ignore
/.gitattributes export-ignore
/.gitignore export-ignore
/.travis.yml export-ignore
Expand Down
62 changes: 53 additions & 9 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,11 @@ cache:
- $HOME/.cache/composer/files

php:
- 5.4
- 5.5
- 5.6
- 7.0
- 7.1
- 7.2
- 7.3

env:
jobs:
Expand All @@ -38,6 +36,8 @@ stages:
if: type = push AND branch NOT IN (master, develop)
- name: test
if: branch IN (master, develop)
- name: coverage
if: branch IN (master, develop)

jobs:
fast_finish: true
Expand All @@ -57,7 +57,7 @@ jobs:
- composer validate --no-check-all --strict

# Check the code style of the code base.
- composer checkcs
- composer travis-checkcs

# Validate the xml files.
# @link http://xmlsoft.org/xmllint.html
Expand All @@ -74,6 +74,8 @@ jobs:
#### QUICK TEST STAGE ####
# This is a much quicker test which only runs the unit tests and linting against the low/high
# supported PHP/PHPCS combinations.
# These are basically the same builds as in the Coverage stage, but then without doing
# the code-coverage.
- stage: quicktest
php: 7.4
env: PHPCS_VERSION="dev-master" LINT=1
Expand All @@ -88,23 +90,41 @@ jobs:
#### TEST STAGE ####
# Additional builds to prevent issues with PHPCS versions incompatible with certain PHP versions.
- stage: test
# PHPCS is only compatible with PHP 7.4 as of version 3.5.0.
php: 7.4
env: PHPCS_VERSION="dev-master" LINT=1
# PHPCS is only compatible with PHP 7.4 as of version 3.5.0.
- php: 7.4
env: PHPCS_VERSION="3.5.0"
- php: 7.3
env: PHPCS_VERSION="dev-master" LINT=1

- php: "nightly"
env: PHPCS_VERSION="n/a" LINT=1

#### CODE COVERAGE STAGE ####
# N.B.: Coverage is only checked on the lowest and highest stable PHP versions for all PHPCS versions.
# These builds are left out off the "test" stage so as not to duplicate test runs.
# The script used is the default script below, the same as for the `test` stage.
- stage: coverage
php: 7.4
env: PHPCS_VERSION="dev-master" LINT=1 COVERALLS_VERSION="^2.0"
- php: 7.3
env: PHPCS_VERSION="3.3.1" COVERALLS_VERSION="^2.0"

- php: 5.4
env: PHPCS_VERSION="dev-master" LINT=1 COVERALLS_VERSION="^1.0"
- php: 5.4
env: PHPCS_VERSION="3.3.1" COVERALLS_VERSION="^1.0"

allow_failures:
# Allow failures for unstable builds.
- php: "nightly"


before_install:
# Speed up build time by disabling Xdebug when its not needed.
- phpenv config-rm xdebug.ini || echo 'No xdebug config.'
- |
if [[ "$TRAVIS_BUILD_STAGE_NAME" != "Coverage" ]]; then
phpenv config-rm xdebug.ini || echo 'No xdebug config.'
fi
- export XMLLINT_INDENT=" "

Expand All @@ -122,6 +142,10 @@ install:
if [[ $PHPCS_VERSION != "n/a" ]]; then
composer require --no-update --no-scripts squizlabs/php_codesniffer:${PHPCS_VERSION}
fi
- |
if [[ "$TRAVIS_BUILD_STAGE_NAME" == "Coverage" ]]; then
composer require --no-update --no-suggest --no-scripts php-coveralls/php-coveralls:${COVERALLS_VERSION}
fi
- |
if [[ "$TRAVIS_BUILD_STAGE_NAME" == "Sniff" || $PHPCS_VERSION == "n/a" ]]; then
# The sniff stage doesn't run the unit tests, so no need for PHPUnit.
Expand All @@ -134,9 +158,29 @@ install:
- composer install --prefer-dist --no-suggest


before_script:
- if [[ "$TRAVIS_BUILD_STAGE_NAME" == "Coverage" ]]; then mkdir -p build/logs; fi
- phpenv rehash


script:
# Lint PHP files against parse errors.
- if [[ "$LINT" == "1" ]]; then composer lint; fi

# Run the tests.
- if [[ $PHPCS_VERSION != "n/a" ]]; then composer test; fi
# Run the unit tests.
- |
if [[ $PHPCS_VERSION != "n/a" && "$TRAVIS_BUILD_STAGE_NAME" != "Coverage" ]]; then
composer test
elif [[ $PHPCS_VERSION != "n/a" && "$TRAVIS_BUILD_STAGE_NAME" == "Coverage" ]]; then
composer coverage
fi
after_success:
- |
if [[ "$TRAVIS_BUILD_STAGE_NAME" == "Coverage" && $COVERALLS_VERSION == "^1.0" ]]; then
php vendor/bin/coveralls -v -x build/logs/clover.xml
fi
- |
if [[ "$TRAVIS_BUILD_STAGE_NAME" == "Coverage" && $COVERALLS_VERSION == "^2.0" ]]; then
php vendor/bin/php-coveralls -v -x build/logs/clover.xml
fi
108 changes: 108 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
# Change Log for the PHPCSExtra standard for PHP Codesniffer

All notable changes to this project will be documented in this file.

This projects adheres to [Keep a CHANGELOG](http://keepachangelog.com/) and uses [Semantic Versioning](http://semver.org/).

**Legend**:
:wrench: = Includes auto-fixer.
:bar_chart: = Includes metrics.
:books: = Includes CLI documentation.


## [Unreleased]

_Nothing yet._


## 1.0.0-alpha2 - 2020-02-18

### Added

#### Universal
* :wrench: :bar_chart: :books: New `Universal.ControlStructures.DisallowAlternativeSyntax` sniff to disallow using the alternative syntax for control structures. [#23](https://github.com/PHPCSStandards/PHPCSExtra/pull/23)
- This sniff contains a `allowWithInlineHTML` property to allow alternative syntax when inline HTML is used within the control structure. In all other cases, the use of the alternative syntax will still be disallowed.
- The sniff has modular error codes to allow for making exceptions based on specific control structures and/or specific control structures in combination with inline HTML.
* :bar_chart: `Universal.UseStatements.DisallowUseClass/Function/Const`: new, additional metrics about the import source will be shown in the `info` report. [#25](https://github.com/PHPCSStandards/PHPCSExtra/pull/25)

#### Other
* Readme: installation instructions and sniff list. [#26](https://github.com/PHPCSStandards/PHPCSExtra/pull/26)

### Changed

#### Universal
* `Universal.Arrays.DuplicateArrayKey`: wording of the error message. [#18](https://github.com/PHPCSStandards/PHPCSExtra/pull/18)
* `Universal.UseStatements.DisallowUseClass/Function/Const`: the error codes have been made more modular. [#25](https://github.com/PHPCSStandards/PHPCSExtra/pull/25)
Each of these sniffs now has four additional error codes:
<ul>
<li><code>FoundSameNamespace</code>, <code>FoundSameNamespaceWithAlias</code> for <code>use</code> statements importing from the same namespace;</li>
<li><code>FoundGlobalNamespace</code>, <code>FoundGlobalNamespaceWithAlias</code> for <code>use</code> statements importing from the global namespace, like import statements for PHP native classes, functions and constants.</li>
</ul>
In all other circumstances, the existing error codes <code>FoundWithAlias</code> and <code>FoundWithoutAlias</code> will continue to be used.

#### Other
* Improved formatting of the CLI documentation which can be viewed using `--generator=text`. [#17](https://github.com/PHPCSStandards/PHPCSExtra/pull/17)
* Various housekeeping.

### Fixed

#### Universal
* `Universal.Arrays.DuplicateArrayKey`: improved handling of parse errors. [#34](https://github.com/PHPCSStandards/PHPCSExtra/pull/34)
* `Universal.ControlStructures.IfElseDeclaration`: the fixer will now respect tab indentation. [#19](https://github.com/PHPCSStandards/PHPCSExtra/pull/19)
* `Universal.UseStatements.DisallowUseClass/Function/Const`: the determination of whether a import is aliased in now done in a case-insensitive manner. [#25](https://github.com/PHPCSStandards/PHPCSExtra/pull/25)
* `Universal.UseStatements.DisallowUseClass/Function/Const`: an import from the global namespace would previously always be seen as non-aliased, even when it was aliased. [#25](https://github.com/PHPCSStandards/PHPCSExtra/pull/25)
* `Universal.UseStatements.DisallowUseClass/Function/Const`: improved tolerance for `use` import statements with leading backslashes. [#25](https://github.com/PHPCSStandards/PHPCSExtra/pull/25)


## 1.0.0-alpha1 - 2020-01-23

Initial alpha release containing:
* A `NormalizedArrays` standard which will contain a full set of sniffs to check the formatting of array declarations.
* A `Universal` standard which will contain a collection of universal sniffs.
DO NOT INCLUDE THIS AS A STANDARD.
`Universal`, like the upstream PHPCS `Generic` standard, contains sniffs which contradict each other.
Include individual sniffs from this standard in a custom project/company ruleset to use them.

This initial alpha release contains the following sniffs:

### NormalizedArrays
* :wrench: :bar_chart: :books: `NormalizedArrays.Arrays.ArrayBraceSpacing`: enforce consistent spacing for the open/close braces of array declarations.
The sniff allows for having different settings for:
- Space between the array keyword and the open parenthesis for long arrays via the `keywordSpacing` property.
Accepted values: (int) number of spaces or `false` to turn this check off. Defaults to `0` spaces.
- Spaces on the inside of the braces for empty arrays via the `spacesWhenEmpty` property.
Accepted values: (string) `newline`, (int) number of spaces or `false` to turn this check off. Defaults to `0` spaces.
- Spaces on the inside of the braces for single-line arrays via the `spacesSingleLine` property;
Accepted values: (int) number of spaces or `false` to turn this check off. Defaults to `0` spaces.
- Spaces on the inside of the braces for multi-line arrays via the `spacesMultiLine` property.
Accepted values: (string) `newline`, (int) number of spaces or `false` to turn this check off. Defaults to `newline`.
Note: if any of the above properties are set to `newline`, it is recommended to also include an array indentation sniff. This sniff will not handle the indentation.
* :wrench: :bar_chart: :books: `NormalizedArrays.Arrays.CommaAfterLast`: enforce/forbid a comma after the last item in an array declaration.
By default, this sniff will:
<ul>
<li>forbid a comma after the last array item for single-line arrays.</li>
<li>enforce a comma after the last array item for multi-line arrays.</li>
</ul>
This can be changed for each type or array individually by setting the <code>singleLine</code> or <code>multiLine</code> properties in a custom ruleset.
The valid values are: <code>enforce</code>, <code>forbid</code> or <code>skip</code> to not check the comma after the last array item for a particular type of array.

### Universal
* :books: `Universal.Arrays.DuplicateArrayKey`: detects duplicate array keys in array declarations.
* :books: `Universal.Arrays.MixedArrayKeyTypes`: best practice sniff: don't use a mix of integer and numeric keys for array items.
* :books: `Universal.Arrays.MixedKeyedUnkeyedArray`: best practice sniff: don't use a mix of keyed and unkeyed array items.
* :wrench: :bar_chart: :books: `Universal.ControlStructures.IfElseDeclaration`: verify that else(if) statements with braces are on a new line.
* :wrench: :bar_chart: :books: `Universal.Lists.DisallowLongListSyntax`: disallow the use of long `list`s.
* :wrench: :bar_chart: :books: `Universal.Lists.DisallowShortListSyntax`: disallow the use of short lists.
* :bar_chart: :books: `Universal.Namespaces.DisallowCurlyBraceSyntax`: disallow the use of the alternative namespace declaration syntax using curly braces.
* :bar_chart: :books: `Universal.Namespaces.EnforceCurlyBraceSyntax`: enforce the use of the alternative namespace syntax using curly braces.
* :books: `Universal.Namespaces.OneDeclarationPerFile`: disallow the use of multiple namespaces within a file.
* :bar_chart: :books: `Universal.UseStatements.DisallowUseClass`: forbid using import use statements for classes/traits/interfaces.
Individual sub-types can be allowed by excluding specific error codes.
* :bar_chart: :books: `Universal.UseStatements.DisallowUseConst`: forbid using import use statements for constants.
Individual sub-types can be allowed by excluding specific error codes.
* :bar_chart: :books: `Universal.UseStatements.DisallowUseFunction`: forbid using import use statements for functions.
Individual sub-types can be allowed by excluding specific error codes.


[Unreleased]: https://github.com/PHPCSStandards/PHPCSExtra/compare/1.0.0-alpha2...HEAD
[1.0.0-alpha2]: https://github.com/PHPCSStandards/PHPCSExtra/compare/1.0.0-alpha1...1.0.0-alpha2
5 changes: 1 addition & 4 deletions NormalizedArrays/Docs/Arrays/ArrayBraceSpacingStandard.xml
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,7 @@ $args = array(1,
2);
$args = [1,
2<em>
</em>];
2];
]]>
</code>
</code_comparison>
Expand Down
13 changes: 13 additions & 0 deletions NormalizedArrays/Tests/Arrays/ArrayBraceSpacingUnitTest.inc
Original file line number Diff line number Diff line change
Expand Up @@ -207,5 +207,18 @@ $array = array($a,
$b
);

// Test behaviour with all checks turned off.
// phpcs:set NormalizedArrays.Arrays.ArrayBraceSpacing keywordSpacing false
// phpcs:set NormalizedArrays.Arrays.ArrayBraceSpacing spacesWhenEmpty false
// phpcs:set NormalizedArrays.Arrays.ArrayBraceSpacing spacesSingleLine false
// phpcs:set NormalizedArrays.Arrays.ArrayBraceSpacing spacesMultiLine false
$foo = array ( );
$foo = array ( $a );
$array = array($a,
$b);

// Reset to default.
// phpcs:set NormalizedArrays.Arrays.ArrayBraceSpacing keywordSpacing 0
// phpcs:set NormalizedArrays.Arrays.ArrayBraceSpacing spacesWhenEmpty 0
// phpcs:set NormalizedArrays.Arrays.ArrayBraceSpacing spacesSingleLine 0
// phpcs:set NormalizedArrays.Arrays.ArrayBraceSpacing spacesMultiLine newline
13 changes: 13 additions & 0 deletions NormalizedArrays/Tests/Arrays/ArrayBraceSpacingUnitTest.inc.fixed
Original file line number Diff line number Diff line change
Expand Up @@ -195,5 +195,18 @@ $array = array($a,
$b
);

// Test behaviour with all checks turned off.
// phpcs:set NormalizedArrays.Arrays.ArrayBraceSpacing keywordSpacing false
// phpcs:set NormalizedArrays.Arrays.ArrayBraceSpacing spacesWhenEmpty false
// phpcs:set NormalizedArrays.Arrays.ArrayBraceSpacing spacesSingleLine false
// phpcs:set NormalizedArrays.Arrays.ArrayBraceSpacing spacesMultiLine false
$foo = array ( );
$foo = array ( $a );
$array = array($a,
$b);

// Reset to default.
// phpcs:set NormalizedArrays.Arrays.ArrayBraceSpacing keywordSpacing 0
// phpcs:set NormalizedArrays.Arrays.ArrayBraceSpacing spacesWhenEmpty 0
// phpcs:set NormalizedArrays.Arrays.ArrayBraceSpacing spacesSingleLine 0
// phpcs:set NormalizedArrays.Arrays.ArrayBraceSpacing spacesMultiLine newline
Loading

0 comments on commit 65e057f

Please sign in to comment.