Skip to content

Commit

Permalink
Merge pull request #296 from PHPCSStandards/develop
Browse files Browse the repository at this point in the history
Release PHPCSExtra 1.2.0
  • Loading branch information
jrfnl committed Dec 2, 2023
2 parents 746c319 + 9f90980 commit 78b2cae
Show file tree
Hide file tree
Showing 30 changed files with 1,563 additions and 101 deletions.
22 changes: 0 additions & 22 deletions .github/SECURITY.md

This file was deleted.

9 changes: 5 additions & 4 deletions .github/workflows/basics.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ jobs:
composer require --no-update squizlabs/php_codesniffer:"dev-master" --no-interaction
# Install dependencies and handle caching in one go.
# @link https://github.com/marketplace/actions/install-composer-dependencies
# @link https://github.com/marketplace/actions/install-php-dependencies-with-composer
- name: Install Composer dependencies
uses: "ramsey/composer-install@v2"
with:
Expand All @@ -62,7 +62,8 @@ jobs:
# Show XML violations inline in the file diff.
# @link https://github.com/marketplace/actions/xmllint-problem-matcher
- uses: korelstar/xmllint-problem-matcher@v1
- name: Enable showing XML issues inline
uses: korelstar/xmllint-problem-matcher@v1

# Validate the Ruleset XML file.
# @link http://xmlsoft.org/xmllint.html
Expand Down Expand Up @@ -112,7 +113,7 @@ jobs:

# Install dependencies and handle caching in one go.
# Dependencies need to be installed to make sure the PHPCS and PHPUnit classes are recognized.
# @link https://github.com/marketplace/actions/install-composer-dependencies
# @link https://github.com/marketplace/actions/install-php-dependencies-with-composer
- name: Install Composer dependencies
uses: "ramsey/composer-install@v2"
with:
Expand All @@ -131,7 +132,7 @@ jobs:
uses: actions/checkout@v4

- name: Set up node and enable caching of dependencies
uses: actions/setup-node@v3
uses: actions/setup-node@v4
with:
node-version: '16'

Expand Down
53 changes: 53 additions & 0 deletions .github/workflows/label-remove-outdated.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
name: Remove outdated labels

on:
# https://docs.github.com/en/actions/using-workflows/events-that-trigger-workflows#pull_request_target
issues:
types:
- closed
pull_request_target:
types:
- closed

jobs:
on-issue-close:
runs-on: ubuntu-latest
if: github.repository_owner == 'PHPCSStandards' && github.event.issue.state == 'closed'

name: Clean up labels on issue close

steps:
- uses: mondeja/remove-labels-gh-action@v1
with:
token: ${{ secrets.GITHUB_TOKEN }}
labels: |
Status: awaiting feedback
Status: wait for upstream
on-pr-merge:
runs-on: ubuntu-latest
if: github.repository_owner == 'PHPCSStandards' && github.event.pull_request.merged == true

name: Clean up labels on PR merge

steps:
- uses: mondeja/remove-labels-gh-action@v1
with:
token: ${{ secrets.GITHUB_TOKEN }}
labels: |
Status: awaiting feedback
Status: wait for upstream
on-pr-close:
runs-on: ubuntu-latest
if: github.repository_owner == 'PHPCSStandards' && github.event_name == 'pull_request_target' && github.event.pull_request.merged == false

name: Clean up labels on PR close

steps:
- uses: mondeja/remove-labels-gh-action@v1
with:
token: ${{ secrets.GITHUB_TOKEN }}
labels: |
Status: awaiting feedback
Status: wait for upstream
2 changes: 1 addition & 1 deletion .github/workflows/quicktest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ jobs:
run: composer require squizlabs/php_codesniffer:"${{ matrix.phpcs_version }}" --no-update --no-scripts --no-interaction

# Install dependencies and handle caching in one go.
# @link https://github.com/marketplace/actions/install-composer-dependencies
# @link https://github.com/marketplace/actions/install-php-dependencies-with-composer
- name: Install Composer dependencies - normal
if: matrix.php != 'latest'
uses: "ramsey/composer-install@v2"
Expand Down
59 changes: 12 additions & 47 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,12 @@ jobs:
# @link https://docs.github.com/en/free-pro-team@latest/actions/reference/workflow-syntax-for-github-actions#jobsjob_idstrategymatrix
#
# The matrix is set up so as not to duplicate the builds which are run for code coverage.
php: ['5.5', '5.6', '7.0', '7.1', '7.2', '7.3', '8.0', '8.1', '8.2', '8.3']
php: ['5.5', '5.6', '7.0', '7.1', '7.2', '7.3', '8.0', '8.1', '8.2', '8.3', '8.4']
phpcs_version: ['lowest', 'dev-master']

name: "Test${{ matrix.phpcs_version == 'dev-master' && ' + Lint' || '' }}: PHP ${{ matrix.php }} - PHPCS ${{ matrix.phpcs_version }}"

continue-on-error: ${{ matrix.php == '8.3' }}
continue-on-error: ${{ matrix.php == '8.4' }}

steps:
- name: Checkout code
Expand Down Expand Up @@ -66,7 +66,7 @@ jobs:
run: composer require squizlabs/php_codesniffer:"${{ matrix.phpcs_version }}" --no-update --no-scripts --no-interaction

# Install dependencies and handle caching in one go.
# @link https://github.com/marketplace/actions/install-composer-dependencies
# @link https://github.com/marketplace/actions/install-php-dependencies-with-composer
- name: Install Composer dependencies - normal
if: ${{ startsWith( matrix.php, '8' ) == false }}
uses: "ramsey/composer-install@v2"
Expand Down Expand Up @@ -148,7 +148,7 @@ jobs:
run: composer require squizlabs/php_codesniffer:"${{ matrix.phpcs_version }}" --no-update --no-scripts --no-interaction

# Install dependencies and handle caching in one go.
# @link https://github.com/marketplace/actions/install-composer-dependencies
# @link https://github.com/marketplace/actions/install-php-dependencies-with-composer
- name: Install Composer dependencies
uses: "ramsey/composer-install@v2"
with:
Expand All @@ -168,37 +168,14 @@ jobs:
- name: Run the unit tests with code coverage
run: composer coverage

# PHP Coveralls v2 (which supports GH Actions) has a PHP 5.5 minimum, so switch the PHP version.
- name: Switch to PHP latest
if: ${{ success() && matrix.php == '5.4' }}
uses: shivammathur/setup-php@v2
with:
php-version: 'latest'
coverage: none

# Global install is used to prevent a conflict with the local composer.lock.
- name: Install Coveralls
- name: Upload coverage results to Coveralls
if: ${{ success() }}
run: composer global require php-coveralls/php-coveralls:"^2.6.0" --no-interaction

- name: Upload coverage results to Coveralls (normal)
if: ${{ success() && github.actor != 'dependabot[bot]' }}
env:
COVERALLS_REPO_TOKEN: ${{ secrets.COVERALLS_TOKEN }}
COVERALLS_PARALLEL: true
COVERALLS_FLAG_NAME: php-${{ matrix.php }}-phpcs-${{ matrix.phpcs_version }}
run: php-coveralls -v -x build/logs/clover.xml

# Dependabot does not have access to secrets, other than the GH token.
# Ref: https://docs.github.com/en/code-security/dependabot/working-with-dependabot/automating-dependabot-with-github-actions
# Ref: https://github.com/lemurheavy/coveralls-public/issues/1721
- name: Upload coverage results to Coveralls (Dependabot)
if: ${{ success() && github.actor == 'dependabot[bot]' }}
env:
COVERALLS_REPO_TOKEN: ${{ secrets.GITHUB_TOKEN }}
COVERALLS_PARALLEL: true
COVERALLS_FLAG_NAME: php-${{ matrix.php }}-phpcs-${{ matrix.phpcs_version }}
run: php-coveralls -v -x build/logs/clover.xml
uses: coverallsapp/github-action@v2
with:
format: clover
file: build/logs/clover.xml
flag-name: php-${{ matrix.php }}-phpcs-${{ matrix.phpcs_version }}
parallel: true

coveralls-finish:
needs: coverage
Expand All @@ -207,19 +184,7 @@ jobs:
runs-on: ubuntu-latest

steps:
- name: Coveralls Finished (normal)
if: ${{ github.actor != 'dependabot[bot]' }}
uses: coverallsapp/github-action@v2
with:
github-token: ${{ secrets.COVERALLS_TOKEN }}
parallel-finished: true

# Dependabot does not have access to secrets, other than the GH token.
# Ref: https://docs.github.com/en/code-security/dependabot/working-with-dependabot/automating-dependabot-with-github-actions
# Ref: https://github.com/lemurheavy/coveralls-public/issues/1721
- name: Coveralls Finished (Dependabot)
if: ${{ github.actor == 'dependabot[bot]' }}
- name: Coveralls Finished
uses: coverallsapp/github-action@v2
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
parallel-finished: true
1 change: 1 addition & 0 deletions .yamllint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ yaml-files:
- '*.yaml'
- '*.yml'
- '.yamllint'
- 'phpstan.neon*'

# Rule documentation: https://yamllint.readthedocs.io/en/stable/rules.html
rules:
Expand Down
34 changes: 34 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,36 @@ This projects adheres to [Keep a CHANGELOG](http://keepachangelog.com/) and uses

_Nothing yet._

## [1.2.0] - 2023-12-02

### Added

#### Universal

* :wrench: :books: New `Universal.CodeAnalysis.NoDoubleNegative` sniff to detect double negatives (!!) and advise to use a boolean cast instead. Thanks [@diedexx] for reviewing. [#277]
* :wrench: :books: New `Universal.Operators.ConcatPosition` sniff to enforce that the concatenation operator for multi-line concatenations is in a preferred position, either always at the start of the next line or always at the end of the previous line. [#294]
* :wrench: :bar_chart: :books: New `Universal.PHP.LowercasePHPTag` sniff to enforce that the "PHP" in a PHP open tag is lowercase. Thanks [@fredden] for reviewing. [#276]

### Changed

#### NormalizedArrays

* `NormalizedArrays.Arrays.CommaAfterLast`: the sniff now has two extra error codes to distinguish between multi-line arrays with the last array item on the _same line_ as the array closer vs the last array item being on a line _before_ the array closer. Thanks [@stronk7] for suggesting and patching this. [#283], [#284]
These new error codes allow for selectively excluding that specific situation from triggering the sniff.
The new error codes are `FoundMultiLineCloserSameLine` (for `multiLine="forbid"`) and `MissingMultiLineCloserSameLine` (for `multiLine="enforce"`).
The pre-existing `FoundMultiLine` and `FoundSingleLine` error codes continue to be used for multi-line arrays with the last array item on a different line than the array closer.

#### Other

* Various housekeeping.

[#276]: https://github.com/PHPCSStandards/PHPCSExtra/pull/276
[#277]: https://github.com/PHPCSStandards/PHPCSExtra/pull/277
[#283]: https://github.com/PHPCSStandards/PHPCSExtra/issues/283
[#284]: https://github.com/PHPCSStandards/PHPCSExtra/pull/284
[#294]: https://github.com/PHPCSStandards/PHPCSExtra/pull/294


## [1.1.2] - 2023-09-21

### Changed
Expand Down Expand Up @@ -523,6 +553,7 @@ This initial alpha release contains the following sniffs:
[php_version-config]: https://github.com/squizlabs/PHP_CodeSniffer/wiki/Configuration-Options#setting-the-php-version

[Unreleased]: https://github.com/PHPCSStandards/PHPCSExtra/compare/stable...HEAD
[1.2.0]: https://github.com/PHPCSStandards/PHPCSExtra/compare/1.1.2...1.2.0
[1.1.2]: https://github.com/PHPCSStandards/PHPCSExtra/compare/1.1.1...1.1.2
[1.1.1]: https://github.com/PHPCSStandards/PHPCSExtra/compare/1.1.0...1.1.1
[1.1.0]: https://github.com/PHPCSStandards/PHPCSExtra/compare/1.0.4...1.1.0
Expand All @@ -537,5 +568,8 @@ This initial alpha release contains the following sniffs:

[@anomiex]: https://github.com/anomiex
[@derickr]: https://github.com/derickr
[@diedexx]: https://github.com/diedexx
[@fredden]: https://github.com/fredden
[@GaryJones]: https://github.com/GaryJones
[@stronk7]: https://github.com/stronk7
[@szepeviktor]: https://github.com/szepeviktor
7 changes: 7 additions & 0 deletions NormalizedArrays/Sniffs/Arrays/CommaAfterLastSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,13 @@ public function process(File $phpcsFile, $stackPtr)
return;
}

// If the closer is on the same line as the last element, change the error code for multi-line arrays.
if ($errorCode === 'MultiLine'
&& $tokens[$lastNonEmpty]['line'] === $tokens[$closer]['line']
) {
$errorCode .= 'CloserSameLine';
}

$isComma = ($tokens[$lastNonEmpty]['code'] === \T_COMMA);

$phpcsFile->recordMetric(
Expand Down
50 changes: 50 additions & 0 deletions NormalizedArrays/Tests/Arrays/CommaAfterLastUnitTest.1.inc
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,56 @@ EOD
, /*comment*/
) );

/**
* Tests enforcing a comma after the last array item when the closer is in the same line. See #283.
*/
// phpcs:set NormalizedArrays.Arrays.CommaAfterLast multiLine enforce

$missing = array(
1, 2,
3, 4);

$missing = [
'1', '2',
'3', '4'];

$missing_but_good = [
'1', '2',
'3', '4']; // phpcs:ignore NormalizedArrays.Arrays.CommaAfterLast.MissingMultiLineCloserSameLine

$good = array(
1, 2,
3, 4,);

$good = [
'1', '2',
'3', '4',];

/**
* Tests forbidding a comma after the last array item when the closer is in the same line. See #283.
*/
// phpcs:set NormalizedArrays.Arrays.CommaAfterLast multiLine forbid

$found = array(
1, 2,
3, 4,);

$found = [
'1', '2',
'3', '4',];

$found_but_good = [
'1', '2',
'3', '4',]; // phpcs:ignore NormalizedArrays.Arrays.CommaAfterLast.FoundMultiLineCloserSameLine

$good = array(
1, 2,
3, 4);

$good = [
'1', '2',
'3', '4'];

// Reset the properties to the defaults.
// phpcs:set NormalizedArrays.Arrays.CommaAfterLast singleLine forbid
// phpcs:set NormalizedArrays.Arrays.CommaAfterLast multiLine enforce
Expand Down

0 comments on commit 78b2cae

Please sign in to comment.