From 747562d3da9feb76a685819346acc516b3915aca Mon Sep 17 00:00:00 2001 From: Franco Fichtner Date: Tue, 22 Feb 2022 08:28:06 +0100 Subject: [PATCH] make: update parallel-lint to 1.3.2 --- contrib/parallel-lint/CHANGELOG.md | 66 +++++++++++++++++-- contrib/parallel-lint/README.md | 68 +++++++++++--------- contrib/parallel-lint/src/Application.php | 18 ++++-- contrib/parallel-lint/src/ErrorFormatter.php | 29 ++++++--- contrib/parallel-lint/src/Output.php | 16 +++-- contrib/parallel-lint/src/Settings.php | 16 ++--- 6 files changed, 152 insertions(+), 61 deletions(-) diff --git a/contrib/parallel-lint/CHANGELOG.md b/contrib/parallel-lint/CHANGELOG.md index 3df611dcbc..66f38982e2 100644 --- a/contrib/parallel-lint/CHANGELOG.md +++ b/contrib/parallel-lint/CHANGELOG.md @@ -6,7 +6,62 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). ## [Unreleased] -[Unreleased]: https://github.com/php-parallel-lint/PHP-Parallel-Lint/compare/v1.3.0...HEAD +[Unreleased]: https://github.com/php-parallel-lint/PHP-Parallel-Lint/compare/v1.3.2...HEAD + +## [1.3.2] - 2022-02-19 + +### Added + +- Support for PHP Console Highlighter 1.0.0, which comes with PHP Console Color 1.0.1, [#92] from [@jrfnl]. + +### Fixed + +- Bug fix: make Phar file run independently of project under scan [#63] from [@jrfnl], fixes [#61]. +- Bug fix: checkstyle report could contain invalid XML due to insufficient output escaping [#73] from [@gmazzap], fixes [#72]. +- Fix Phar building [#70] from [@jrfnl]. This fixes PHP 8.1 compatibility for the Phar file. +- Documentation fix: the `--show-deprecated` option was missing in both the README as well as the CLI `help` [#84] from [@jrfnl], fixes [#81] reported by [@stronk7]. + +### Changed + +- README: updated information about PHAR availability [#77] from [@jrfnl]. +- README: updated CLI example [#80] from [@jrfnl]. +- README: added documentation on how to exclude files from a scan based on the PHP version used [#80] from [@jrfnl]. +- Composer autoload improvement [#88] from [@jrfnl] with thanks to [@mfn]. + +### Internal + +- Welcome [@jrfnl] as a new maintainer [#32]. +- GH Actions: set error reporting to E_ALL [#65], [#76] from [@jrfnl]. +- GH Actions: fix failing tests on PHP 5.3-5.5 [#71] from [@jrfnl] and [@villfa]. +- GH Actions: auto-cancel concurrent builds [#76] from [@jrfnl]. +- GH Actions: testing against PHP 8.2 [#74] from [@grogy]. +- GH Actions: release testing against PHP 5.3 [#79] from [@jrfnl]. +- GH Actions: update used actions [#82] from [@jrfnl]. +- Release checklist can now be found in the `.github` folder [#78] from [@jrfnl]. + +[1.3.2]: https://github.com/php-parallel-lint/PHP-Parallel-Lint/compare/v1.3.1...v1.3.2 + +[#32]: https://github.com/php-parallel-lint/PHP-Parallel-Lint/issues/32 +[#61]: https://github.com/php-parallel-lint/PHP-Parallel-Lint/issues/61 +[#63]: https://github.com/php-parallel-lint/PHP-Parallel-Lint/pull/63 +[#65]: https://github.com/php-parallel-lint/PHP-Parallel-Lint/pull/65 +[#70]: https://github.com/php-parallel-lint/PHP-Parallel-Lint/pull/70 +[#71]: https://github.com/php-parallel-lint/PHP-Parallel-Lint/pull/71 +[#72]: https://github.com/php-parallel-lint/PHP-Parallel-Lint/issues/72 +[#73]: https://github.com/php-parallel-lint/PHP-Parallel-Lint/pull/73 +[#74]: https://github.com/php-parallel-lint/PHP-Parallel-Lint/pull/74 +[#76]: https://github.com/php-parallel-lint/PHP-Parallel-Lint/pull/76 +[#77]: https://github.com/php-parallel-lint/PHP-Parallel-Lint/pull/77 +[#78]: https://github.com/php-parallel-lint/PHP-Parallel-Lint/pull/78 +[#79]: https://github.com/php-parallel-lint/PHP-Parallel-Lint/pull/79 +[#80]: https://github.com/php-parallel-lint/PHP-Parallel-Lint/pull/80 +[#81]: https://github.com/php-parallel-lint/PHP-Parallel-Lint/issues/81 +[#82]: https://github.com/php-parallel-lint/PHP-Parallel-Lint/pull/82 +[#84]: https://github.com/php-parallel-lint/PHP-Parallel-Lint/pull/84 +[#88]: https://github.com/php-parallel-lint/PHP-Parallel-Lint/pull/88 +[#89]: https://github.com/php-parallel-lint/PHP-Parallel-Lint/pull/89 +[#92]: https://github.com/php-parallel-lint/PHP-Parallel-Lint/pull/92 + ## [1.3.1] - 2021-08-13 @@ -22,7 +77,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). - Reformat changelog to use reflinks in changelog entries [#58] from [@glensc]. -[1.3.1]: https://github.com/php-parallel-lint/PHP-Parallel-Lint/compare/v1.3.0...1.3.1 +[1.3.1]: https://github.com/php-parallel-lint/PHP-Parallel-Lint/compare/v1.3.0...v1.3.1 [#50]: https://github.com/php-parallel-lint/PHP-Parallel-Lint/pull/50 [#58]: https://github.com/php-parallel-lint/PHP-Parallel-Lint/pull/58 @@ -53,7 +108,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). - Provide one true way to run the test suite [#37] from [@mfn]. - Travis: add build against PHP 8.0 and fix failing test [#41] from [@jrfnl]. - GitHub Actions for testing, and automatic phar creation [#46] from [@roelofr]. -- Add .github folder to .gitattributes export-ignore [#54] from [@glensc]. +- Add .github folder to .gitattributes export-ignore [#54] from [@reedy]. - Suggest to curl composer install via HTTPS [#53] from [@reedy]. - GH Actions: allow for manually triggering a workflow [#55] from [@jrfnl]. - GH Actions: fix phar creation [#55] from [@jrfnl]. @@ -100,12 +155,15 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). [@OndraM]: https://github.com/OndraM [@arxeiss]: https://github.com/arxeiss [@glensc]: https://github.com/glensc +[@gmazzap]: https://github.com/gmazzap [@jankonas]: https://github.com/jankonas [@jrfnl]: https://github.com/jrfnl [@mfn]: https://github.com/mfn [@ondrejmirtes]: https://github.com/ondrejmirtes [@reedy]: https://github.com/reedy [@roelofr]: https://github.com/roelofr +[@stronk7]: https://github.com/stronk7 [@szepeviktor]: https://github.com/szepeviktor [@lukas9393]: https://github.com/lukas9393 - +[@villfa]: https://github.com/villfa +[@grogy]: https://github.com/grogy diff --git a/contrib/parallel-lint/README.md b/contrib/parallel-lint/README.md index eb546e93b3..cb6b242ca2 100644 --- a/contrib/parallel-lint/README.md +++ b/contrib/parallel-lint/README.md @@ -10,7 +10,7 @@ Additionally `blame` can be used to show commits that introduced the breakage. Running parallel jobs in PHP is inspired by Nette framework tests. -The application is officially supported for use with PHP 5.3 to 8.0. +The application is officially supported for use with PHP 5.3 to 8.1. ## Table of contents @@ -19,7 +19,7 @@ The application is officially supported for use with PHP 5.3 to 8.0. 3. [History](#history) 4. [Command line options](#command-line-options) 5. [Recommended excludes for Symfony framework](#recommended-excludes-for-symfony-framework) -6. [Create Phar package](#create-phar-package) +6. [Excluding files from a scan based on the PHP version used](#excluding-files-from-a-scan-based-on-the-php-version-used) 7. [How to upgrade](#how-to-upgrade) ## Installation @@ -37,6 +37,9 @@ For colored output, install the suggested package `php-parallel-lint/php-console composer require --dev php-parallel-lint/php-console-highlighter +Since v1.3.0, a PHAR file is also made available for each release. +This PHAR file is published as an asset for each release and can be found on the [Releases](https://github.com/php-parallel-lint/PHP-Parallel-Lint/releases) page. + ## Example output ![Example use of tool with error](/tests/examples/example-images/use-error.png?raw=true "Example use of tool with error") @@ -64,45 +67,52 @@ It is strongly recommended for existing users of the (unmaintained) ## Command line options -- `-p ` Specify PHP-CGI executable to run (default: 'php'). -- `-s, --short` Set short_open_tag to On (default: Off). -- `-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) -- `--exclude` Exclude a file or directory. If you want exclude multiple items, use multiple exclude parameters. -- `-j ` Run jobs in parallel (default: 10). -- `--colors` Force enable colors in console output. -- `--no-colors` Disable colors in console output. -- `--no-progress` Disable progress in console output. -- `--checkstyle` Output results as Checkstyle XML. -- `--json` Output results as JSON string (requires PHP 5.4). -- `--gitlab` Output results for the GitLab Code Quality widget (requires PHP 5.4), see more in [Code Quality](https://docs.gitlab.com/ee/user/project/merge_requests/code_quality.html) documentation. -- `--blame` Try to show git blame for row with error. -- `--git ` Path to Git executable to show blame message (default: 'git'). -- `--stdin` Load files and folder to test from standard input. -- `--ignore-fails` Ignore failed tests. -- `--syntax-error-callback` File with syntax error callback for ability to modify error, see more in [example](doc/syntax-error-callback.md) -- `-h, --help` Print this help. -- `-V, --version` Display this application version. +- `-p ` Specify PHP-CGI executable to run (default: 'php'). +- `-s`, `--short` Set short_open_tag to On (default: Off). +- `-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. +- `--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. +- `--checkstyle` Output results as Checkstyle XML. +- `--json` Output results as JSON string (requires PHP 5.4). +- `--gitlab` Output results for the GitLab Code Quality Widget (requires PHP 5.4), see more in [Code Quality](https://docs.gitlab.com/ee/user/project/merge_requests/code_quality.html) documentation.. +- `--blame` Try to show git blame for row with error. +- `--git ` Path to Git executable to show blame message (default: 'git'). +- `--stdin` Load files and folder to test from standard input. +- `--ignore-fails` Ignore failed tests. +- `--show-deprecated` Show deprecations (default: Off). +- `--syntax-error-callback` File with syntax error callback for ability to modify error, see more in [example](doc/syntax-error-callback.md). +- `-h`, `--help` Print this help. +- `-V`, `--version` Display the application version ## Recommended excludes for Symfony framework To run from the command line: - vendor/bin/parallel-lint --exclude app --exclude vendor . - -## Create Phar package - -PHP Parallel Lint supports [Box app](https://box-project.github.io/box2/) for creating Phar package. First, install box app: + vendor/bin/parallel-lint --exclude .git --exclude app --exclude vendor . - curl -LSs https://box-project.github.io/box2/installer.php | php +## Excluding files from a scan based on the PHP version used +Sometimes a particular file in a project may not comply with the project-wide minimum PHP version, like a file which is conditionally included in the project and contains PHP syntax which needs a higher PHP version to run. -then run the build command in parallel lint folder, which creates `parallel-lint.phar` file. +This can make it complicated to run Parallel Lint in a CI context, as the `exclude`s used in the command would have to be adjusted based on the PHP version on which the scan is being run. +PHP Parallel Lint offers a straight-forward way around this, as files can define their own minimum PHP version like so: +```php += 7.4 + +// Code which contains PHP 7.4 syntax. +``` + +With this comment in place, the file will be automatically skipped when PHP Parallel Lint is run on a PHP version lower than PHP 7.4. + +Note: The `// lint >= 7.4` comment has to be only the first line of the file and must directly follow the PHP open tag. - box build ## How to upgrade diff --git a/contrib/parallel-lint/src/Application.php b/contrib/parallel-lint/src/Application.php index 4b4017e1f5..b94e3c95cc 100644 --- a/contrib/parallel-lint/src/Application.php +++ b/contrib/parallel-lint/src/Application.php @@ -4,7 +4,7 @@ namespace JakubOnderka\PhpParallelLint; class Application { - const VERSION = '1.3.1'; + const VERSION = '1.3.2'; // Return codes const SUCCESS = 0, @@ -77,25 +77,29 @@ class Application Options: -p Specify PHP-CGI executable to run (default: 'php'). -s, --short Set short_open_tag to On (default: Off). - -a, -asp Set asp_tags to On (default: Off). + -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. - -j Run jobs in parallel (default: 10). - --colors Enable colors in console output. (disables auto detection of color support) + --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. - --json Output results as JSON string. - --gitlab Output results for the GitLab Code Quality Widget. --checkstyle Output results as Checkstyle XML. + --json Output results as JSON string + (requires PHP 5.4). + --gitlab Output results for the GitLab Code Quality Widget + (requires PHP 5.4). --blame Try to show git blame for row with error. --git Path to Git executable to show blame message (default: 'git'). --stdin Load files and folder to test from standard input. --ignore-fails Ignore failed tests. + --show-deprecated Show deprecations (default: Off). --syntax-error-callback File with syntax error callback for ability to modify error -h, --help Print this help. - -V, --version Display this application version + -V, --version Display the application version HELP; } diff --git a/contrib/parallel-lint/src/ErrorFormatter.php b/contrib/parallel-lint/src/ErrorFormatter.php index 76b4466ccd..874fab7e26 100644 --- a/contrib/parallel-lint/src/ErrorFormatter.php +++ b/contrib/parallel-lint/src/ErrorFormatter.php @@ -1,8 +1,10 @@ getCodeSnippet($filePath, $lineNumber, $linesBefore, $linesAfter); + // Highlighter and ConsoleColor 1.0+. + $colors = new ConsoleColor(); + $colors->setForceStyle($this->forceColors); + $highlighter = new Highlighter($colors); + } else if ( + class_exists('\JakubOnderka\PhpConsoleHighlighter\Highlighter') + && class_exists('\JakubOnderka\PhpConsoleColor\ConsoleColor') + ) { + // Highlighter and ConsoleColor < 1.0. + $colors = new OldConsoleColor(); + $colors->setForceStyle($this->forceColors); + $highlighter = new OldHighlighter($colors); } - $colors = new ConsoleColor(); - $colors->setForceStyle($this->forceColors); - $highlighter = new Highlighter($colors); + if (isset($colors, $highlighter) === false) { + return $this->getCodeSnippet($filePath, $lineNumber, $linesBefore, $linesAfter); + } $fileContent = file_get_contents($filePath); return $highlighter->getCodeSnippet($fileContent, $lineNumber, $linesBefore, $linesAfter); diff --git a/contrib/parallel-lint/src/Output.php b/contrib/parallel-lint/src/Output.php index 974dde806d..7b729156f8 100644 --- a/contrib/parallel-lint/src/Output.php +++ b/contrib/parallel-lint/src/Output.php @@ -441,7 +441,7 @@ class CheckstyleOutput implements Output sprintf( ' ', $fileError['line'], - $fileError['message'], + htmlspecialchars($fileError['message'], ENT_COMPAT, 'UTF-8'), $fileError['source'] ) . PHP_EOL @@ -456,14 +456,17 @@ class CheckstyleOutput implements Output class TextOutputColored extends TextOutput { - /** @var \JakubOnderka\PhpConsoleColor\ConsoleColor */ + /** @var \PHP_Parallel_Lint\PhpConsoleColor\ConsoleColor|\JakubOnderka\PhpConsoleColor\ConsoleColor */ private $colors; public function __construct(IWriter $writer, $colors = Settings::AUTODETECT) { parent::__construct($writer); - if (class_exists('\JakubOnderka\PhpConsoleColor\ConsoleColor')) { + if (class_exists('\PHP_Parallel_Lint\PhpConsoleColor\ConsoleColor')) { + $this->colors = new \PHP_Parallel_Lint\PhpConsoleColor\ConsoleColor(); + $this->colors->setForceStyle($colors === Settings::FORCED); + } else if (class_exists('\JakubOnderka\PhpConsoleColor\ConsoleColor')) { $this->colors = new \JakubOnderka\PhpConsoleColor\ConsoleColor(); $this->colors->setForceStyle($colors === Settings::FORCED); } @@ -472,11 +475,14 @@ class TextOutputColored extends TextOutput /** * @param string $string * @param string $type - * @throws \JakubOnderka\PhpConsoleColor\InvalidStyleException + * @throws \PHP_Parallel_Lint\PhpConsoleColor\InvalidStyleException|\JakubOnderka\PhpConsoleColor\InvalidStyleException */ public function write($string, $type = self::TYPE_DEFAULT) { - if (!$this->colors instanceof \JakubOnderka\PhpConsoleColor\ConsoleColor) { + if ( + !$this->colors instanceof \PHP_Parallel_Lint\PhpConsoleColor\ConsoleColor + && !$this->colors instanceof \JakubOnderka\PhpConsoleColor\ConsoleColor + ) { parent::write($string, $type); } else { switch ($type) { diff --git a/contrib/parallel-lint/src/Settings.php b/contrib/parallel-lint/src/Settings.php index cea565f55a..73386ed702 100644 --- a/contrib/parallel-lint/src/Settings.php +++ b/contrib/parallel-lint/src/Settings.php @@ -152,10 +152,6 @@ class Settings $settings->aspTags = true; break; - case '--exclude': - $settings->excluded[] = $arguments->getNext(); - break; - case '-e': $settings->extensions = array_map('trim', explode(',', $arguments->getNext())); break; @@ -164,6 +160,10 @@ class Settings $settings->parallelJobs = max((int) $arguments->getNext(), 1); break; + case '--exclude': + $settings->excluded[] = $arguments->getNext(); + break; + case '--colors': $settings->colors = self::FORCED; break; @@ -176,6 +176,10 @@ class Settings $settings->showProgress = false; break; + case '--checkstyle': + $settings->format = self::FORMAT_CHECKSTYLE; + break; + case '--json': $settings->format = self::FORMAT_JSON; break; @@ -184,10 +188,6 @@ class Settings $settings->format = self::FORMAT_GITLAB; break; - case '--checkstyle': - $settings->format = self::FORMAT_CHECKSTYLE; - break; - case '--git': $settings->gitExecutable = $arguments->getNext(); break;