Skip to content

Commit

Permalink
Features/php cs fixer (#3598)
Browse files Browse the repository at this point in the history
* introduces new linter for PHP-CS-Fixer (see feature report #3550)

* changes after running build.py

* fix cspell dict for missing words related to #3550

* wrong filename used for testing new linter PHP_PHPCSFIXER (see #3550)

* automation about php-cs-fixer

* quick fix for PHP-CS-Fixer util unit tests

* ugly quick fix for new PHP-CS-Fixer linter

* docs and automation files

* clean-up code

* [MegaLinter] Apply linters fixes

* Workaround for test case names

* [MegaLinter] Apply linters fixes

* Fix

---------

Co-authored-by: llaville <llaville@users.noreply.github.com>
Co-authored-by: nvuillam <nicolas.vuillamy@gmail.com>
Co-authored-by: nvuillam <nvuillam@users.noreply.github.com>
  • Loading branch information
4 people authored Jun 2, 2024
1 parent 178d6a8 commit 219bdab
Show file tree
Hide file tree
Showing 20 changed files with 419 additions and 11 deletions.
38 changes: 38 additions & 0 deletions .automation/generated/linter-helps.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions .automation/generated/linter-links-previews.json
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,11 @@
"image": null,
"title": "PHP: Hypertext Preprocessor"
},
"php-cs-fixer": {
"description": "PHP Coding Standards Fixer",
"image": null,
"title": "PHP Coding Standards Fixer"
},
"phpcs": {
"description": "PHP_CodeSniffer tokenizes PHP files and detects violations of a defined set of coding standards. - squizlabs/PHP_CodeSniffer",
"image": "https://avatars2.githubusercontent.com/u/997547?s=400&v=4",
Expand Down
1 change: 1 addition & 0 deletions .automation/generated/linter-versions.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@
"npm-package-json-lint": "7.1.0",
"perlcritic": "1.152",
"php": "7.4.26",
"php-cs-fixer": "3.58.1",
"phpcs": "3.10.1",
"phplint": "9.3.1",
"phpstan": "1.11.3",
Expand Down
16 changes: 16 additions & 0 deletions .automation/test/php/reports/ERROR-PHP_PHPCSFIXER.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
Results of php-cs-fixer linter (version 3.58.1)
See documentation on https://megalinter.io/latest/descriptors/php_php_cs_fixer/
-----------------------------------------------

❌ [ERROR] for workspace /tmp/lint
Linter raw log:
PHP CS Fixer 3.58.1 7th Gear by Fabien Potencier, Dariusz Ruminski and contributors.
PHP runtime: 8.3.7
Running analysis on 1 core sequentially.
You can enable parallel runner and speed up the analysis! Please see https://cs.symfony.com/doc/usage.html for more information.
Loaded config default from "/action/lib/.automation/.php-cs-fixer.dist.php".
Using cache file ".php-cs-fixer.cache".

Files that were not fixed due to errors reported during linting before fixing:
1) ./php_bad_1.php
2) ./php_bad_2.php
3 changes: 3 additions & 0 deletions .cspell.json
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@
"fastq",
"ffenses",
"filelist",
"friendsofphp",
"fs.realpath",
"gfch",
"gotit",
Expand Down Expand Up @@ -104,6 +105,7 @@
"minizlib",
"mkdirp",
"msgon",
"netbeans",
"nextick",
"numprocesses",
"noni",
Expand Down Expand Up @@ -355,6 +357,7 @@
"PERLCRITIC",
"PHAR",
"PHPCS",
"PHPCSFIXER",
"PHPSTAN",
"PIPESTATUS",
"PIPVENV",
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/deploy-BETA-linters.yml
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ jobs:
"php_phpstan",
"php_psalm",
"php_phplint",
"php_phpcsfixer",
"powershell_powershell",
"powershell_powershell_formatter",
"protobuf_protolint",
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/deploy-DEV-linters.yml
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ jobs:
"php_phpstan",
"php_psalm",
"php_phplint",
"php_phpcsfixer",
"powershell_powershell",
"powershell_powershell_formatter",
"protobuf_protolint",
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/deploy-RELEASE-linters.yml
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ jobs:
"php_phpstan",
"php_psalm",
"php_phplint",
"php_phpcsfixer",
"powershell_powershell",
"powershell_powershell_formatter",
"protobuf_protolint",
Expand Down
4 changes: 4 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -641,6 +641,10 @@ RUN --mount=type=secret,id=GITHUB_TOKEN GITHUB_AUTH_TOKEN="$(cat /run/secrets/GI
RUN --mount=type=secret,id=GITHUB_TOKEN GITHUB_AUTH_TOKEN="$(cat /run/secrets/GITHUB_TOKEN)" && export GITHUB_AUTH_TOKEN && phive --no-progress install overtrue/phplint --force-accept-unsigned -g


# php-cs-fixer installation
RUN --mount=type=secret,id=GITHUB_TOKEN GITHUB_AUTH_TOKEN="$(cat /run/secrets/GITHUB_TOKEN)" && export GITHUB_AUTH_TOKEN && composer global require friendsofphp/php-cs-fixer


# powershell installation
RUN pwsh -c 'Install-Module -Name PSScriptAnalyzer -RequiredVersion ${PSSA_VERSION} -Scope AllUsers -Force'

Expand Down
12 changes: 12 additions & 0 deletions TEMPLATES/.php-cs-fixer.dist.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php

$finder = (new PhpCsFixer\Finder())
->in('.')
;

return (new PhpCsFixer\Config())
->setRules([
'@PER-CS' => true,
])
->setFinder($finder)
;
1 change: 1 addition & 0 deletions docs/standalone-linters.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@
| PHP_PHPSTAN | oxsecurity/megalinter-only-php_phpstan:beta | ![Docker Image Size (tag)](https://img.shields.io/docker/image-size/oxsecurity/megalinter-only-php_phpstan/beta) |
| PHP_PSALM | oxsecurity/megalinter-only-php_psalm:beta | ![Docker Image Size (tag)](https://img.shields.io/docker/image-size/oxsecurity/megalinter-only-php_psalm/beta) |
| PHP_PHPLINT | oxsecurity/megalinter-only-php_phplint:beta | ![Docker Image Size (tag)](https://img.shields.io/docker/image-size/oxsecurity/megalinter-only-php_phplint/beta) |
| PHP_PHPCSFIXER | oxsecurity/megalinter-only-php_phpcsfixer:beta | ![Docker Image Size (tag)](https://img.shields.io/docker/image-size/oxsecurity/megalinter-only-php_phpcsfixer/beta) |
| POWERSHELL_POWERSHELL | oxsecurity/megalinter-only-powershell_powershell:beta | ![Docker Image Size (tag)](https://img.shields.io/docker/image-size/oxsecurity/megalinter-only-powershell_powershell/beta) |
| POWERSHELL_POWERSHELL_FORMATTER | oxsecurity/megalinter-only-powershell_powershell_formatter:beta | ![Docker Image Size (tag)](https://img.shields.io/docker/image-size/oxsecurity/megalinter-only-powershell_powershell_formatter/beta) |
| PROTOBUF_PROTOLINT | oxsecurity/megalinter-only-protobuf_protolint:beta | ![Docker Image Size (tag)](https://img.shields.io/docker/image-size/oxsecurity/megalinter-only-protobuf_protolint/beta) |
Expand Down
4 changes: 4 additions & 0 deletions flavors/cupcake/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -467,6 +467,10 @@ RUN --mount=type=secret,id=GITHUB_TOKEN GITHUB_AUTH_TOKEN="$(cat /run/secrets/GI
RUN --mount=type=secret,id=GITHUB_TOKEN GITHUB_AUTH_TOKEN="$(cat /run/secrets/GITHUB_TOKEN)" && export GITHUB_AUTH_TOKEN && phive --no-progress install overtrue/phplint --force-accept-unsigned -g


# php-cs-fixer installation
RUN --mount=type=secret,id=GITHUB_TOKEN GITHUB_AUTH_TOKEN="$(cat /run/secrets/GITHUB_TOKEN)" && export GITHUB_AUTH_TOKEN && composer global require friendsofphp/php-cs-fixer


# mypy installation
ENV MYPY_CACHE_DIR=/tmp

Expand Down
1 change: 1 addition & 0 deletions flavors/cupcake/flavor.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
"PHP_PHPSTAN",
"PHP_PSALM",
"PHP_PHPLINT",
"PHP_PHPCSFIXER",
"PYTHON_PYLINT",
"PYTHON_BLACK",
"PYTHON_FLAKE8",
Expand Down
4 changes: 4 additions & 0 deletions flavors/php/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,10 @@ RUN --mount=type=secret,id=GITHUB_TOKEN GITHUB_AUTH_TOKEN="$(cat /run/secrets/GI
RUN --mount=type=secret,id=GITHUB_TOKEN GITHUB_AUTH_TOKEN="$(cat /run/secrets/GITHUB_TOKEN)" && export GITHUB_AUTH_TOKEN && phive --no-progress install overtrue/phplint --force-accept-unsigned -g


# php-cs-fixer installation
RUN --mount=type=secret,id=GITHUB_TOKEN GITHUB_AUTH_TOKEN="$(cat /run/secrets/GITHUB_TOKEN)" && export GITHUB_AUTH_TOKEN && composer global require friendsofphp/php-cs-fixer


# protolint installation
# Managed with COPY --link --from=protolint /usr/local/bin/protolint /usr/bin/

Expand Down
1 change: 1 addition & 0 deletions flavors/php/flavor.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
"PHP_PHPSTAN",
"PHP_PSALM",
"PHP_PHPLINT",
"PHP_PHPCSFIXER",
"PROTOBUF_PROTOLINT",
"REPOSITORY_CHECKOV",
"REPOSITORY_GIT_DIFF",
Expand Down
Loading

0 comments on commit 219bdab

Please sign in to comment.