diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 7b8f56c..6c7948d 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -23,7 +23,7 @@ jobs: steps: - name: Checkout code - uses: actions/checkout@v2 + uses: actions/checkout@v4 - name: Setup PHP uses: shivammathur/setup-php@v2 @@ -34,16 +34,20 @@ jobs: ini-values: phar.readonly=Off, error_reporting=-1, display_errors=On, zend.assertions=1 # Autoload files generated with Composer 2.3 are not compatible with PHP < 7.0. tools: composer:2.2 + env: + fail-fast: true - name: Install Composer dependencies - uses: ramsey/composer-install@v2 + uses: ramsey/composer-install@v3 with: composer-options: "--no-dev" + # Bust the cache at least once a month - output format: YYYY-MM. + custom-cache-suffix: $(date -u "+%Y-%m") # Note: do NOT turn on the requirement checker in the box config as it is no longer # compatible with PHP < 7.2. - name: Install Box - run: wget https://github.com/humbug/box/releases/latest/download/box.phar -O box.phar && chmod 0755 box.phar && pwd + run: wget https://github.com/box-project/box/releases/latest/download/box.phar -O box.phar && chmod 0755 box.phar && pwd - name: Validate configuration run: php box.phar validate -i box.json @@ -51,10 +55,10 @@ jobs: - name: Building binary... run: php box.phar compile -v --config=box.json - - name: Show info about the build phar with humbug/box + - name: Show info about the build phar with box-project/box run: php box.phar info -l parallel-lint.phar - - uses: actions/upload-artifact@v2 + - uses: actions/upload-artifact@v4 with: name: parallel-lint-phar path: ./parallel-lint.phar @@ -62,7 +66,7 @@ jobs: verify: name: Validate binary on PHP ${{ matrix.php }} runs-on: ubuntu-latest - continue-on-error: ${{ matrix.php == '8.2' }} + continue-on-error: ${{ matrix.php == '8.3' }} needs: - bundle @@ -81,12 +85,13 @@ jobs: - '8.0' - '8.1' - '8.2' + - '8.3' steps: - name: Checkout code - uses: actions/checkout@v2 + uses: actions/checkout@v4 - - uses: actions/download-artifact@v2 + - uses: actions/download-artifact@v4 with: name: parallel-lint-phar @@ -108,24 +113,17 @@ jobs: - verify steps: - - uses: actions/download-artifact@v2 + - uses: actions/download-artifact@v4 with: name: parallel-lint-phar - name: Draft Release - uses: actions/create-release@v1 - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + uses: softprops/action-gh-release@v2 with: tag_name: ${{ github.ref }} release_name: Release ${{ github.ref }} draft: true prerelease: false - - - name: Upload Phar as Release Asset - id: upload-release-asset - uses: softprops/action-gh-release@v1 - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - with: + make_latest: true files: parallel-lint.phar + fail_on_unmatched_files: true diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index b81c8ac..d6de46c 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -23,21 +23,25 @@ jobs: - name: Setup PHP uses: shivammathur/setup-php@v2 with: - php-version: '7.4' + php-version: 'latest' coverage: none tools: cs2pr - name: Checkout code - uses: actions/checkout@v2 + uses: actions/checkout@v4 - name: Install Composer dependencies - uses: ramsey/composer-install@v2 + uses: ramsey/composer-install@v3 + with: + # Bust the cache at least once a month - output format: YYYY-MM. + custom-cache-suffix: $(date -u "+%Y-%m") - name: Run code sniffer - continue-on-error: true + id: phpcs run: vendor/bin/phpcs --report-full --report-checkstyle=./phpcs-report.xml - name: Show PHPCS results in PR + if: ${{ always() && steps.phpcs.outcome == 'failure' }} run: cs2pr ./phpcs-report.xml bundle: @@ -46,7 +50,7 @@ jobs: steps: - name: Checkout code - uses: actions/checkout@v2 + uses: actions/checkout@v4 - name: Setup PHP uses: shivammathur/setup-php@v2 @@ -57,16 +61,20 @@ jobs: ini-values: phar.readonly=Off, error_reporting=-1, display_errors=On, zend.assertions=1 # Autoload files generated with Composer 2.3 are not compatible with PHP < 7.0. tools: composer:2.2 + env: + fail-fast: true - name: Install Composer dependencies - uses: ramsey/composer-install@v2 + uses: ramsey/composer-install@v3 with: composer-options: "--no-dev" + # Bust the cache at least once a month - output format: YYYY-MM. + custom-cache-suffix: $(date -u "+%Y-%m") # Note: do NOT turn on the requirement checker in the box config as it is no longer # compatible with PHP < 7.2. - name: Install Box - run: wget https://github.com/humbug/box/releases/latest/download/box.phar -O box.phar && chmod 0755 box.phar && pwd + run: wget https://github.com/box-project/box/releases/latest/download/box.phar -O box.phar && chmod 0755 box.phar && pwd - name: Validate configuration run: php box.phar validate -i box.json @@ -74,10 +82,10 @@ jobs: - name: Building binary... run: php box.phar compile -v --config=box.json - - name: Show info about the build phar with humbug/box + - name: Show info about the build phar with box-project/box run: php box.phar info -l parallel-lint.phar - - uses: actions/upload-artifact@v2 + - uses: actions/upload-artifact@v4 with: name: parallel-lint-phar path: ./parallel-lint.phar @@ -85,7 +93,7 @@ jobs: test: name: Run tests on PHP ${{ matrix.php }} runs-on: ubuntu-latest - continue-on-error: ${{ matrix.php == '8.2' }} + continue-on-error: ${{ matrix.php == '8.4' }} needs: - bundle @@ -104,10 +112,12 @@ jobs: - '8.0' - '8.1' - '8.2' + - '8.3' + - '8.4' steps: - name: Checkout code - uses: actions/checkout@v2 + uses: actions/checkout@v4 - name: Setup PHP uses: shivammathur/setup-php@v2 @@ -122,7 +132,18 @@ jobs: run: composer remove --dev squizlabs/php_codesniffer --no-update --no-interaction - name: Install Composer dependencies - uses: ramsey/composer-install@v2 + if: ${{ matrix.php != '8.3' }} + uses: ramsey/composer-install@v3 + with: + # Bust the cache at least once a month - output format: YYYY-MM. + custom-cache-suffix: $(date -u "+%Y-%m") + + - name: "Install Composer dependencies (PHP 8.3, ignore PHP reqs)" + if: ${{ matrix.php == '8.3' }} + uses: ramsey/composer-install@v3 + with: + composer-options: --ignore-platform-req=php + custom-cache-suffix: $(date -u "+%Y-%m") - name: 'Integration test 1 - linting own code, no colors' continue-on-error: true @@ -139,7 +160,7 @@ jobs: if: ${{ matrix.php >= 5.6 }} run: composer test - - uses: actions/download-artifact@v2 + - uses: actions/download-artifact@v4 with: name: parallel-lint-phar diff --git a/README.md b/README.md index ca3deb5..61bbf34 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,7 @@ [![Build Status](https://github.com/php-parallel-lint/PHP-Parallel-Lint/actions/workflows/test.yml/badge.svg)](https://github.com/php-parallel-lint/PHP-Parallel-Lint/actions/workflows/test.yml) [![License](https://poser.pugx.org/php-parallel-lint/php-parallel-lint/license.svg)](https://packagist.org/packages/php-parallel-lint/php-parallel-lint) -This application checks syntax of PHP files in parallel. +This application checks the syntax of PHP files in parallel. It can output in plain text, colored text, json and checksyntax formats. Additionally `blame` can be used to show commits that introduced the breakage. @@ -72,7 +72,7 @@ It is strongly recommended for existing users of the (unmaintained) - `-a`, `--asp` Set asp_tags to On (default: Off). - `-e ` Check only files with selected extensions separated by comma. (default: php,php3,php4,php5,phtml,phpt) - `-j ` Run jobs in parallel (default: 10). -- `--exclude` Exclude a file or directory. If you want exclude multiple items, use multiple exclude parameters. +- `--exclude` Exclude a file or directory. If you want to exclude multiple items, use multiple exclude parameters. - `--colors` Enable colors in console output. (disables auto detection of color support) - `--no-colors` Disable colors in console output. - `--no-progress` Disable progress in console output. @@ -116,7 +116,7 @@ Note: The `// lint >= 7.4` comment has to be only the first line of the file and ## How to upgrade -Are you using `jakub-onderka/php-parallel-lint` package? You can switch to `php-parallel-lint/php-parallel-lint` using: +Are you using the `jakub-onderka/php-parallel-lint` package? You can switch to `php-parallel-lint/php-parallel-lint` using: composer remove --dev jakub-onderka/php-parallel-lint composer require --dev php-parallel-lint/php-parallel-lint diff --git a/bin/skip-linting.php b/bin/skip-linting.php index 2c69554..9cb552b 100644 --- a/bin/skip-linting.php +++ b/bin/skip-linting.php @@ -8,6 +8,12 @@ $f = @fopen($file, 'r'); if ($f) { $firstLine = fgets($f); + + // ignore shebang line + if (strpos($firstLine, '#!') === 0) { + $firstLine = fgets($f); + } + @fclose($f); if (preg_match('~run()); diff --git a/src/Error.php b/src/Error.php index 0c9f65f..61cace9 100644 --- a/src/Error.php +++ b/src/Error.php @@ -107,6 +107,8 @@ function jsonSerialize() class SyntaxError extends Error { + const IN_ON_REGEX = '~ in %s on line [0-9]+$~'; + /** @var Blame */ private $blame; @@ -131,8 +133,22 @@ public function getLine() */ public function getNormalizedMessage($translateTokens = false) { - $message = preg_replace('~^(Parse|Fatal) error: (syntax error, )?~', '', $this->message); - $message = preg_replace('~ in ' . preg_quote(basename($this->filePath)) . ' on line [0-9]+$~', '', $message); + $message = preg_replace('~^(Parse|Fatal) error: (syntax error, )?~', '', $this->message); + $baseName = basename($this->filePath); + $regex = sprintf(self::IN_ON_REGEX, preg_quote($baseName, '~')); + $message = preg_replace($regex, '', $message, -1, $count); + + if ($count === 0 && strpos($baseName, '\\') !== false) { + $baseName = ltrim(strrchr($this->filePath, '\\'), '\\'); + $regex = sprintf(self::IN_ON_REGEX, preg_quote($baseName, '~')); + $message = preg_replace($regex, '', $message, -1, $count); + } + + if ($count === 0) { + $regex = sprintf(self::IN_ON_REGEX, preg_quote($this->filePath, '~')); + $message = preg_replace($regex, '', $message); + } + $message = ucfirst($message); if ($translateTokens) { @@ -194,7 +210,7 @@ protected function translateTokens($message) 'T_ECHO' => 'echo' ); - return preg_replace_callback('~T_([A-Z_]*)~', function ($matches) use ($translateTokens) { + return preg_replace_callback('~(?output ?: $this->getDefaultOutput($settings); $phpExecutable = PhpExecutable::getPhpExecutable($settings->phpExecutable); diff --git a/src/Output.php b/src/Output.php index 7b72915..dc2c94a 100644 --- a/src/Output.php +++ b/src/Output.php @@ -348,9 +348,9 @@ protected function writeMark($type) protected function writePercent() { - $percent = floor($this->checkedFiles / $this->totalFileCount * 100); + $percent = $this->stringWidth(floor($this->checkedFiles / $this->totalFileCount * 100), 3); $current = $this->stringWidth($this->checkedFiles, strlen($this->totalFileCount)); - $this->writeLine(" $current/$this->totalFileCount ($percent %)"); + $this->writeLine(" $current/$this->totalFileCount ($percent%)"); } /** diff --git a/tests/Output.phpt b/tests/Output.phpt index 407c569..afea8e1 100644 --- a/tests/Output.phpt +++ b/tests/Output.phpt @@ -31,6 +31,8 @@ class OutputTest extends Tester\TestCase $result = (array) json_decode($writer->getLogs()); + Assert::equal(count($errors), count($result)); + for ($i = 0; $i < count($result) && $i < count($errors); $i++) { $message = $errors[$i]->getMessage(); $filePath = $errors[$i]->getFilePath(); diff --git a/tests/ParallelLint.lint.phpt b/tests/ParallelLint.lint.phpt index 847a9e7..19d7c63 100644 --- a/tests/ParallelLint.lint.phpt +++ b/tests/ParallelLint.lint.phpt @@ -83,6 +83,16 @@ class ParallelLintLintTest extends Tester\TestCase Assert::equal(0, count($result->getErrors())); } + public function testSkipShebang() + { + $parallelLint = new ParallelLint($this->getPhpExecutable()); + $result = $parallelLint->lint(array(__DIR__ . '/examples/example-07/example.php')); + + Assert::equal(0, $result->getCheckedFilesCount()); + Assert::equal(0, $result->getFilesWithSyntaxErrorCount()); + Assert::equal(1, $result->getSkippedFilesCount()); + } + public function testInvalidFile() { $parallelLint = new ParallelLint($this->getPhpExecutable()); diff --git a/tests/examples/example-07/example.php b/tests/examples/example-07/example.php new file mode 100644 index 0000000..a1f4e99 --- /dev/null +++ b/tests/examples/example-07/example.php @@ -0,0 +1,5 @@ +#!/usr/bin/php +