Skip to content

Commit

Permalink
added tests, made php-cs-fixer a formatter
Browse files Browse the repository at this point in the history
  • Loading branch information
TylerJang27 committed May 22, 2024
1 parent d724356 commit 58ecf72
Show file tree
Hide file tree
Showing 16 changed files with 110 additions and 12 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,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] |
Expand Down Expand Up @@ -143,6 +143,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
Expand Down
7 changes: 7 additions & 0 deletions linters/php-cs-fixer/php-cs-fixer.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { linterFmtTest } from "tests";
import { skipOS } from "tests/utils";

linterFmtTest({
linterName: "php-cs-fixer",
skipTestIf: skipOS(["win32"]),
});
36 changes: 36 additions & 0 deletions linters/php-cs-fixer/plugin.yaml
Original file line number Diff line number Diff line change
@@ -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
15 changes: 15 additions & 0 deletions linters/php-cs-fixer/test_data/basic.in.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php declare(strict_types = 1);

class HelloWorld
{
private $b;

private $a;


public function sayHello(DateTimeImutable $date): void
{
$c=(ARRAY)array(1,2);
echo 'Hello, ' . $date->format('j. n. Y');
}
}
22 changes: 22 additions & 0 deletions linters/php-cs-fixer/test_data/php_cs_fixer_v3.54.0_basic.fmt.shot
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`Testing formatter php-cs-fixer test basic 1`] = `
"<?php

declare(strict_types=1);

class HelloWorld
{
private $b;

private $a;


public function sayHello(DateTimeImutable $date): void
{
$c = (array)array(1,2);
echo 'Hello, ' . $date->format('j. n. Y');
}
}
"
`;
1 change: 1 addition & 0 deletions tools/diff-so-fancy/diff_so_fancy.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { toolInstallTest } from "tests";

// TODO(Tyler): tool def is missing healthcheck
toolInstallTest({
toolName: "diff-so-fancy",
toolVersion: "1.4.3",
Expand Down
1 change: 1 addition & 0 deletions tools/difft/difft.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { toolInstallTest } from "tests";

// TODO(Tyler): tool def is missing healthcheck
toolInstallTest({
toolName: "difft",
toolVersion: "0.56.1",
Expand Down
1 change: 1 addition & 0 deletions tools/gk/gk.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { toolInstallTest } from "tests";

// TODO(Tyler): tool def is missing healthcheck
toolInstallTest({
toolName: "gk",
toolVersion: "1.2.2",
Expand Down
1 change: 1 addition & 0 deletions tools/goreleaser/goreleaser.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
8 changes: 8 additions & 0 deletions tools/paratest/paratest.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { toolInstallTest } from "tests";
import { skipOS } from "tests/utils";

toolInstallTest({
toolName: "paratest",
toolVersion: "7.4.3",
skipTestIf: skipOS(["win32"]),
});
3 changes: 3 additions & 0 deletions tools/paratest/plugin.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,6 @@ tools:
environment:
- name: PATH
list: ["${tool}/vendor/bin"]
health_checks:
- command: paratest --version
parse_regex: ParaTest v${semver}
11 changes: 0 additions & 11 deletions tools/php-cs-fixer/plugin.yaml

This file was deleted.

8 changes: 8 additions & 0 deletions tools/phpunit/phpunit.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { toolInstallTest } from "tests";
import { skipOS } from "tests/utils";

toolInstallTest({
toolName: "phpunit",
toolVersion: "11.1.3",
skipTestIf: skipOS(["win32"]),
});
3 changes: 3 additions & 0 deletions tools/phpunit/plugin.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,6 @@ tools:
environment:
- name: PATH
list: ["${tool}/vendor/bin"]
health_checks:
- command: phpunit --version
parse_regex: PHPUnit ${semver}
1 change: 1 addition & 0 deletions tools/tsc/tsc.test.ts
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
1 change: 1 addition & 0 deletions tools/yq/yq.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { toolInstallTest } from "tests";

// TODO(Tyler): tool def is missing healthcheck
toolInstallTest({
toolName: "yq",
toolVersion: "4.40.5",
Expand Down

0 comments on commit 58ecf72

Please sign in to comment.