diff --git a/.github/actions/linter_tests/action.yaml b/.github/actions/linter_tests/action.yaml index d68843357..16e09101f 100644 --- a/.github/actions/linter_tests/action.yaml +++ b/.github/actions/linter_tests/action.yaml @@ -60,11 +60,11 @@ runs: sudo rm /var/lib/apt/lists/lock || true # Install non-hermetic linters + sudo add-apt-repository ppa:ondrej/php sudo apt-get update sudo apt-get -y install libperl-critic-perl perltidy zlib1g-dev software-properties-common DEBIAN_FRONTEND=noninteractive TZ=Etc/UTC sudo apt-get -y install tzdata - sudo add-apt-repository ppa:ondrej/php - sudo apt install -y php8.0-fpm php8.0-xml php8.0-mbstring php8.0-curl + sudo apt install -y php8.2-fpm php8.2-xml php8.2-mbstring php8.2-curl ;; macOS) brew install cpm diff --git a/.github/actions/tool_tests/action.yaml b/.github/actions/tool_tests/action.yaml index 87c296869..9d36c17e3 100644 --- a/.github/actions/tool_tests/action.yaml +++ b/.github/actions/tool_tests/action.yaml @@ -33,11 +33,23 @@ runs: with: node-version: 18 - - name: Specify defaults + - name: Install packages and specify defaults run: | echo "CLI_PATH=${{ inputs.cli-path }}" >> "$GITHUB_ENV" case "$RUNNER_OS" in + Linux) + # Cleanup any existing apt locks + sudo killall apt-get || true + sudo rm /var/lib/apt/lists/lock || true + + sudo add-apt-repository ppa:ondrej/php + sudo apt-get update + sudo apt install -y php8.2-fpm php8.2-xml php8.2-mbstring php8.2-curl + ;; + macOS) + brew install php gnupg + ;; Windows) echo "PLATFORM_APPEND_ARGS=--maxWorkers=5" >> "$GITHUB_ENV" if [[ "${{ inputs.cli-path }}" == "" ]]; then diff --git a/README.md b/README.md index 671649c0d..87869111f 100644 --- a/README.md +++ b/README.md @@ -70,7 +70,7 @@ trunk check enable {linter} | Nix | [nixpkgs-fmt] | | package.json | [sort-package-json] | | Perl | [perlcritic], [perltidy] | -| PHP | [phpstan] | +| PHP | [php-cs-fixer], [phpstan] | | PNG | [oxipng] | | PowerShell | [psscriptanalyzer] | | Prisma | [prisma] | @@ -147,6 +147,7 @@ trunk check enable {linter} [oxipng]: https://github.com/shssoichiro/oxipng#readme [perlcritic]: https://metacpan.org/pod/Perl::Critic [perltidy]: https://metacpan.org/dist/Perl-Tidy/view/bin/perltidy +[php-cs-fixer]: https://github.com/PHP-CS-Fixer/PHP-CS-Fixer#readme [phpstan]: https://phpstan.org/ [pmd]: https://pmd.github.io/ [pragma-once]: linters/pragma-once/README.md diff --git a/linters/php-cs-fixer/php-cs-fixer.test.ts b/linters/php-cs-fixer/php-cs-fixer.test.ts new file mode 100644 index 000000000..5b52856fb --- /dev/null +++ b/linters/php-cs-fixer/php-cs-fixer.test.ts @@ -0,0 +1,7 @@ +import { linterFmtTest } from "tests"; +import { skipOS } from "tests/utils"; + +linterFmtTest({ + linterName: "php-cs-fixer", + skipTestIf: skipOS(["win32"]), +}); diff --git a/linters/php-cs-fixer/plugin.yaml b/linters/php-cs-fixer/plugin.yaml new file mode 100644 index 000000000..c809cd798 --- /dev/null +++ b/linters/php-cs-fixer/plugin.yaml @@ -0,0 +1,36 @@ +version: 0.1 +tools: + definitions: + - name: php-cs-fixer + runtime: php + package: friendsofphp/php-cs-fixer + known_good_version: 3.54.0 + shims: [php-cs-fixer] + environment: + - name: PATH + list: ["${tool}/vendor/bin"] + health_checks: + - command: php-cs-fixer --version + parse_regex: PHP CS Fixer ${semver} +lint: + definitions: + - name: php-cs-fixer + description: Keeps PHP code up to standards + tools: [php-cs-fixer] + known_good_version: 3.54.0 + files: [php] + commands: + # TODO(Tyler): Do we want to define a lint command here? + - name: format + output: rewrite + success_codes: [0] + formatter: true + batch: true + in_place: true + run: php-cs-fixer fix --using-cache=no --show-progress=none ${target} + direct_configs: + # uses ruleset @PSR12 when a config is not present. + - .php-cs-fixer.dist.php + affects_cache: + - .php-cs-fixer.php + suggest_if: config_present diff --git a/linters/php-cs-fixer/test_data/basic.in.php b/linters/php-cs-fixer/test_data/basic.in.php new file mode 100644 index 000000000..103f07dc4 --- /dev/null +++ b/linters/php-cs-fixer/test_data/basic.in.php @@ -0,0 +1,15 @@ +format('j. n. Y'); + } +} diff --git a/linters/php-cs-fixer/test_data/php_cs_fixer_v3.54.0_basic.fmt.shot b/linters/php-cs-fixer/test_data/php_cs_fixer_v3.54.0_basic.fmt.shot new file mode 100644 index 000000000..8807a2082 --- /dev/null +++ b/linters/php-cs-fixer/test_data/php_cs_fixer_v3.54.0_basic.fmt.shot @@ -0,0 +1,22 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`Testing formatter php-cs-fixer test basic 1`] = ` +"format('j. n. Y'); + } +} +" +`; diff --git a/tools/diff-so-fancy/diff_so_fancy.test.ts b/tools/diff-so-fancy/diff_so_fancy.test.ts index eafc51d19..34f2d8caa 100644 --- a/tools/diff-so-fancy/diff_so_fancy.test.ts +++ b/tools/diff-so-fancy/diff_so_fancy.test.ts @@ -1,5 +1,6 @@ import { toolInstallTest } from "tests"; +// TODO(Tyler): tool def is missing healthcheck toolInstallTest({ toolName: "diff-so-fancy", toolVersion: "1.4.3", diff --git a/tools/difft/difft.test.ts b/tools/difft/difft.test.ts index 40e310e56..fdbd2dec8 100644 --- a/tools/difft/difft.test.ts +++ b/tools/difft/difft.test.ts @@ -1,5 +1,6 @@ import { toolInstallTest } from "tests"; +// TODO(Tyler): tool def is missing healthcheck toolInstallTest({ toolName: "difft", toolVersion: "0.56.1", diff --git a/tools/gk/gk.test.ts b/tools/gk/gk.test.ts index 15d0f0a1f..67b9a1896 100644 --- a/tools/gk/gk.test.ts +++ b/tools/gk/gk.test.ts @@ -1,5 +1,6 @@ import { toolInstallTest } from "tests"; +// TODO(Tyler): tool def is missing healthcheck toolInstallTest({ toolName: "gk", toolVersion: "1.2.2", diff --git a/tools/goreleaser/goreleaser.test.ts b/tools/goreleaser/goreleaser.test.ts index 9f798e884..c9781a483 100644 --- a/tools/goreleaser/goreleaser.test.ts +++ b/tools/goreleaser/goreleaser.test.ts @@ -4,6 +4,7 @@ import { osTimeoutMultiplier } from "tests/utils"; // This install is quite slow on some Linux machines. jest.setTimeout(600000 * osTimeoutMultiplier); +// TODO(Tyler): tool def is missing healthcheck toolInstallTest({ toolName: "goreleaser", toolVersion: "1.25.1", diff --git a/tools/paratest/paratest.test.ts b/tools/paratest/paratest.test.ts new file mode 100644 index 000000000..accc678bb --- /dev/null +++ b/tools/paratest/paratest.test.ts @@ -0,0 +1,8 @@ +import { toolInstallTest } from "tests"; +import { skipOS } from "tests/utils"; + +toolInstallTest({ + toolName: "paratest", + toolVersion: "7.4.3", + skipTestIf: skipOS(["win32"]), +}); diff --git a/tools/paratest/plugin.yaml b/tools/paratest/plugin.yaml new file mode 100644 index 000000000..5c2eac5b8 --- /dev/null +++ b/tools/paratest/plugin.yaml @@ -0,0 +1,14 @@ +version: 0.1 +tools: + definitions: + - name: paratest + runtime: php + package: brianium/paratest + known_good_version: 7.4.3 + shims: [paratest] + environment: + - name: PATH + list: ["${tool}/vendor/bin"] + health_checks: + - command: paratest --version + parse_regex: ParaTest v${semver} diff --git a/tools/phpunit/phpunit.test.ts b/tools/phpunit/phpunit.test.ts new file mode 100644 index 000000000..b9e94bbd0 --- /dev/null +++ b/tools/phpunit/phpunit.test.ts @@ -0,0 +1,8 @@ +import { toolInstallTest } from "tests"; +import { skipOS } from "tests/utils"; + +toolInstallTest({ + toolName: "phpunit", + toolVersion: "11.1.3", + skipTestIf: skipOS(["win32"]), +}); diff --git a/tools/phpunit/plugin.yaml b/tools/phpunit/plugin.yaml new file mode 100644 index 000000000..542a1a89a --- /dev/null +++ b/tools/phpunit/plugin.yaml @@ -0,0 +1,14 @@ +version: 0.1 +tools: + definitions: + - name: phpunit + runtime: php + package: phpunit/phpunit + known_good_version: 11.1.3 + shims: [phpunit] + environment: + - name: PATH + list: ["${tool}/vendor/bin"] + health_checks: + - command: phpunit --version + parse_regex: PHPUnit ${semver} diff --git a/tools/tsc/tsc.test.ts b/tools/tsc/tsc.test.ts index f156d5040..9f1c81716 100644 --- a/tools/tsc/tsc.test.ts +++ b/tools/tsc/tsc.test.ts @@ -1,6 +1,7 @@ import { toolInstallTest } from "tests"; import { skipOS } from "tests/utils"; +// TODO(Tyler): tool def is missing healthcheck toolInstallTest({ toolName: "tsc", toolVersion: "5.2.2", diff --git a/tools/yq/yq.test.ts b/tools/yq/yq.test.ts index 33c1d3c48..f2318f455 100644 --- a/tools/yq/yq.test.ts +++ b/tools/yq/yq.test.ts @@ -1,5 +1,6 @@ import { toolInstallTest } from "tests"; +// TODO(Tyler): tool def is missing healthcheck toolInstallTest({ toolName: "yq", toolVersion: "4.40.5",