Skip to content

Commit

Permalink
Merge pull request #221 from PHPCSStandards/develop
Browse files Browse the repository at this point in the history
Release PHPCSExtra 1.0.3
  • Loading branch information
jrfnl committed Mar 28, 2023
2 parents a077c4a + cdf5de5 commit 7029c05
Show file tree
Hide file tree
Showing 17 changed files with 198 additions and 37 deletions.
13 changes: 9 additions & 4 deletions .github/workflows/quicktest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ jobs:
strategy:
matrix:
php: ['5.4', 'latest']
phpcs_version: ['3.7.1', 'dev-master']
phpcs_version: ['lowest', 'dev-master']

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

Expand All @@ -55,8 +55,9 @@ jobs:
ini-values: ${{ steps.set_ini.outputs.PHP_INI }}
coverage: none

- name: 'Composer: set PHPCS version for tests'
run: composer require --no-update --no-scripts squizlabs/php_codesniffer:"${{ matrix.phpcs_version }}" --no-interaction
- name: "Composer: set PHPCS version for tests (master)"
if: ${{ matrix.phpcs_version != 'lowest' }}
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
Expand All @@ -72,9 +73,13 @@ jobs:
if: matrix.php == 'latest'
uses: "ramsey/composer-install@v2"
with:
composer-options: --ignore-platform-reqs
composer-options: --ignore-platform-req=php+
custom-cache-suffix: $(date -u "+%Y-%m")

- name: "Composer: set PHPCS version for tests (lowest)"
if: ${{ matrix.phpcs_version == 'lowest' }}
run: composer update squizlabs/php_codesniffer --prefer-lowest --ignore-platform-req=php+ --no-scripts --no-interaction

- name: Lint against parse errors
if: matrix.phpcs_version == 'dev-master'
run: composer lint
Expand Down
33 changes: 21 additions & 12 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ jobs:
#
# 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']
phpcs_version: ['3.7.1', 'dev-master']
phpcs_version: ['lowest', 'dev-master']

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

Expand Down Expand Up @@ -61,8 +61,9 @@ jobs:
ini-values: ${{ steps.set_ini.outputs.PHP_INI }}
coverage: none

- name: 'Composer: set PHPCS version for tests'
run: composer require --no-update squizlabs/php_codesniffer:"${{ matrix.phpcs_version }}" --no-interaction
- name: "Composer: set PHPCS version for tests (master)"
if: ${{ matrix.phpcs_version != 'lowest' }}
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
Expand All @@ -78,9 +79,13 @@ jobs:
if: ${{ startsWith( matrix.php, '8' ) }}
uses: "ramsey/composer-install@v2"
with:
composer-options: --ignore-platform-reqs
composer-options: --ignore-platform-req=php+
custom-cache-suffix: $(date -u "+%Y-%m")

- name: "Composer: set PHPCS version for tests (lowest)"
if: ${{ matrix.phpcs_version == 'lowest' }}
run: composer update squizlabs/php_codesniffer --prefer-lowest --ignore-platform-req=php+ --no-scripts --no-interaction

- name: Lint against parse errors
if: matrix.phpcs_version == 'dev-master'
run: composer lint
Expand Down Expand Up @@ -109,7 +114,7 @@ jobs:
matrix:
# 7.4 should be updated to 8.2 when higher PHPUnit versions can be supported.
php: ['5.4', '7.4']
phpcs_version: ['3.7.1', 'dev-master']
phpcs_version: ['lowest', 'dev-master']

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

Expand All @@ -136,10 +141,9 @@ jobs:
coverage: xdebug
tools: cs2pr

- name: 'Composer: adjust dependencies'
run: |
# Set a specific PHPCS version.
composer require --no-update squizlabs/php_codesniffer:"${{ matrix.phpcs_version }}" --no-scripts --no-interaction
- name: "Composer: set PHPCS version for tests (master)"
if: ${{ matrix.phpcs_version != 'lowest' }}
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
Expand All @@ -149,6 +153,10 @@ jobs:
# Bust the cache at least once a month - output format: YYYY-MM.
custom-cache-suffix: $(date -u "+%Y-%m")

- name: "Composer: set PHPCS version for tests (lowest)"
if: ${{ matrix.phpcs_version == 'lowest' }}
run: composer update squizlabs/php_codesniffer --prefer-lowest --ignore-platform-req=php+ --no-scripts --no-interaction

- name: Lint against parse errors
if: matrix.phpcs_version == 'dev-master'
run: composer lint -- --checkstyle | cs2pr
Expand All @@ -164,17 +172,18 @@ jobs:
php-version: 7.4
coverage: none

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

- name: Upload coverage results to Coveralls
if: ${{ success() }}
env:
COVERALLS_REPO_TOKEN: ${{ secrets.GITHUB_TOKEN }}
COVERALLS_PARALLEL: true
COVERALLS_FLAG_NAME: php-${{ matrix.php }}-phpcs-${{ matrix.phpcs_version }}
run: vendor/bin/php-coveralls -v -x build/logs/clover.xml
run: php-coveralls -v -x build/logs/clover.xml

coveralls-finish:
needs: coverage
Expand All @@ -184,7 +193,7 @@ jobs:

steps:
- name: Coveralls Finished
uses: coverallsapp/github-action@master
uses: coverallsapp/github-action@v2
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
parallel-finished: true
25 changes: 25 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,30 @@ This projects adheres to [Keep a CHANGELOG](http://keepachangelog.com/) and uses

_Nothing yet._

## [1.0.3] - 2023-03-28

### Changed

#### Universal

* `Universal.WhiteSpace.DisallowInlineTabs`: significant performance improvement. [#216], [#217]

#### Other

* Various housekeeping.

### Fixed

#### Modernize

* `Modernize.FunctionCalls.Dirname`: prevent false positives for attribute classes called `dirname`. [#211], [#213]

[#211]: https://github.com/PHPCSStandards/PHPCSExtra/pull/211
[#213]: https://github.com/PHPCSStandards/PHPCSExtra/pull/213
[#216]: https://github.com/PHPCSStandards/PHPCSExtra/pull/216
[#217]: https://github.com/PHPCSStandards/PHPCSExtra/pull/217


## [1.0.2] - 2023-01-10

### Changed
Expand Down Expand Up @@ -398,6 +422,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.0.3]: https://github.com/PHPCSStandards/PHPCSExtra/compare/1.0.2...1.0.3
[1.0.2]: https://github.com/PHPCSStandards/PHPCSExtra/compare/1.0.1...1.0.2
[1.0.1]: https://github.com/PHPCSStandards/PHPCSExtra/compare/1.0.0...1.0.1
[1.0.0]: https://github.com/PHPCSStandards/PHPCSExtra/compare/1.0.0-rc1...1.0.0
Expand Down
6 changes: 6 additions & 0 deletions Modernize/Sniffs/FunctionCalls/DirnameSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
use PHP_CodeSniffer\Sniffs\Sniff;
use PHP_CodeSniffer\Util\Tokens;
use PHPCSUtils\Tokens\Collections;
use PHPCSUtils\Utils\Context;
use PHPCSUtils\Utils\PassedParameters;

/**
Expand Down Expand Up @@ -70,6 +71,11 @@ public function process(File $phpcsFile, $stackPtr)
return;
}

if (Context::inAttribute($phpcsFile, $stackPtr) === true) {
// Class instantiation in attribute, not function call.
return;
}

// Check if it is really a function call to the global function.
$prevNonEmpty = $phpcsFile->findPrevious(Tokens::$emptyTokens, ($stackPtr - 1), null, true);

Expand Down
6 changes: 6 additions & 0 deletions Modernize/Tests/FunctionCalls/DirnameUnitTest.inc
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,12 @@ $path = dirname(
)
);

class AttributesShouldBeIgnored
{
#[DirName(__FILE__)]
public function foo(): void
{}
}

// Parse error.
// This must be the last test in the file.
Expand Down
6 changes: 6 additions & 0 deletions Modernize/Tests/FunctionCalls/DirnameUnitTest.inc.fixed
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,12 @@ $path = dirname(
path: __DIR__
, levels: 6);

class AttributesShouldBeIgnored
{
#[DirName(__FILE__)]
public function foo(): void
{}
}

// Parse error.
// This must be the last test in the file.
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -470,7 +470,7 @@ If unsure whether the changes you are proposing would be welcome, open an issue

License
-------
This code is released under the GNU Lesser General Public License (LGPLv3). For more information, visit <http://www.gnu.org/copyleft/lesser.html>
This code is released under the [GNU Lesser General Public License (LGPLv3)](LICENSE).


[phpcsextra-packagist]: https://packagist.org/packages/phpcsstandards/phpcsextra
Expand Down
19 changes: 15 additions & 4 deletions Universal/Sniffs/WhiteSpace/DisallowInlineTabsSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,12 @@ public function process(File $phpcsFile, $stackPtr)
$this->tabWidth = Helper::getTabWidth($phpcsFile);
}

if (defined('PHP_CODESNIFFER_IN_TESTS')) {
$this->tabWidth = Helper::getCommandLineData($phpcsFile, 'tabWidth');
}

$tokens = $phpcsFile->getTokens();
$dummy = new DummyTokenizer('', $phpcsFile->config);

for ($i = 0; $i < $phpcsFile->numTokens; $i++) {
// Skip all non-whitespace tokens and skip whitespace at the start of a new line.
Expand All @@ -109,10 +114,18 @@ public function process(File $phpcsFile, $stackPtr)
// If tabs haven't been converted to spaces by the tokenizer, do so now.
$token = $tokens[$i];
if (isset($token['orig_content']) === false) {
$dummy = new DummyTokenizer('', $phpcsFile->config);
$dummy->replaceTabsInToken($token, ' ', ' ', $this->tabWidth);
if ($token['content'] === '' || \strpos($token['content'], "\t") === false) {
// If there are no tabs, we can continue, no matter what.
continue;
}

$dummy->replaceTabsInToken($token);
}

/*
* Tokens only have the 'orig_content' key if they contain tabs,
* so from here on out, we **know** there will be tabs in the content.
*/
$origContent = $token['orig_content'];

$multiLineComment = false;
Expand All @@ -131,8 +144,6 @@ public function process(File $phpcsFile, $stackPtr)
if ($commentOnly === '' || \strpos($commentOnly, "\t") === false) {
continue;
}
} elseif ($origContent === '' || \strpos($origContent, "\t") === false) {
continue;
}

$fix = $phpcsFile->addFixableError(
Expand Down
12 changes: 12 additions & 0 deletions Universal/Tests/Classes/DisallowAnonClassParenthesesUnitTest.1.inc
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,18 @@ $anon = new class // Comment

$b = new class ( /*comment*/ ) {};

/*
* Safeguard handling of anon classes with attributes.
*/
$anon = new
#[AllowDynamicProperties]
#[MyAttribute, AnotherAttribute]
class() {}; // Bad.

$anon = new
#[MyAttribute, AnotherAttribute]
class {}; // OK.

// Live coding.
// Intentional parse error. This has to be the last test in the file.
$anon = new class()
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,18 @@ $anon = new class // Comment

$b = new class /*comment*/ {};

/*
* Safeguard handling of anon classes with attributes.
*/
$anon = new
#[AllowDynamicProperties]
#[MyAttribute, AnotherAttribute]
class {}; // Bad.

$anon = new
#[MyAttribute, AnotherAttribute]
class {}; // OK.

// Live coding.
// Intentional parse error. This has to be the last test in the file.
$anon = new class()
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ public function getErrorList($testFile = '')
23 => 1,
24 => 1,
27 => 1,
35 => 1,
];

default:
Expand Down
12 changes: 12 additions & 0 deletions Universal/Tests/Classes/RequireAnonClassParenthesesUnitTest.inc
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,18 @@ $anon = new class // Comment
$util->doSomething( new class {} );
$b = new class extends SomeClass implements SomeInterface {};

/*
* Safeguard handling of anon classes with attributes.
*/
$anon = new
#[MyAttribute, AnotherAttribute]
class() {}; // OK.

$anon = new
#[AllowDynamicProperties]
#[MyAttribute, AnotherAttribute]
class {}; // Bad.

// Live coding.
// Intentional parse error. This has to be the last test in the file.
$anon = new class
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,18 @@ $anon = new class // Comment
$util->doSomething( new class() {} );
$b = new class() extends SomeClass implements SomeInterface {};

/*
* Safeguard handling of anon classes with attributes.
*/
$anon = new
#[MyAttribute, AnotherAttribute]
class() {}; // OK.

$anon = new
#[AllowDynamicProperties]
#[MyAttribute, AnotherAttribute]
class() {}; // Bad.

// Live coding.
// Intentional parse error. This has to be the last test in the file.
$anon = new class
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ public function getErrorList()
return [
22 => 1,
23 => 1,
35 => 1,
];
}

Expand Down

0 comments on commit 7029c05

Please sign in to comment.