Skip to content

Commit

Permalink
Merge pull request #9 from Kocal/imp/check-write-unsafe
Browse files Browse the repository at this point in the history
imp(check): deprecate --apply and --apply-unsafe in favor of --write and --unsafe
  • Loading branch information
Kocal authored Aug 5, 2024
2 parents 0415bfe + 37c8650 commit fdc033e
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 49 deletions.
11 changes: 7 additions & 4 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -116,13 +116,16 @@ jobs:
- name: Install Composer dependencies
run: symfony composer install --prefer-dist --no-interaction --no-progress

- name: Create a new Symfony project and install kocal/biome-js-bundle
- name: Create a new Symfony project
run: |
git config --global user.email "hugo@alliau.me"
git config --global user.name "Hugo Alliaume"
symfony new my_app --webapp
cd my_app
- name: Install kocal/biome-js-bundle
run: |
symfony composer config minimum-stability dev
symfony composer config --json extra.symfony.allow-contrib 'true'
symfony composer config repositories.biome-js-bundle '{"type":"path", "url":"../","options":{"symlink":true}}'
symfony composer require 'kocal/biome-js-bundle:*' --dev --no-interaction
cat << EOF > biome.json
Expand All @@ -137,17 +140,17 @@ jobs:
}
}
EOF
working-directory: my_app

- name: Run Biome CI, which should fails
run: symfony console biomejs:ci .
continue-on-error: true
working-directory: my_app

- name: Run Biome Check, and apply fixes
run: symfony console biomejs:check . --apply
run: symfony console biomejs:check . --write
working-directory: my_app

- name: Run Biome CI, which should now pass
run: symfony console biomejs:ci .
working-directory: my_app

41 changes: 6 additions & 35 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
@@ -1,35 +1,10 @@
parameters:
ignoreErrors:
-
message: "#^Parameter \\$apply of method Kocal\\\\BiomeJsBundle\\\\BiomeJs\\:\\:check\\(\\) expects bool, mixed given\\.$#"
count: 1
path: src/Command/BiomeJsCheckCommand.php

-
message: "#^Parameter \\$applyUnsafe of method Kocal\\\\BiomeJsBundle\\\\BiomeJs\\:\\:check\\(\\) expects bool, mixed given\\.$#"
count: 1
path: src/Command/BiomeJsCheckCommand.php

-
message: "#^Parameter \\$changed of method Kocal\\\\BiomeJsBundle\\\\BiomeJs\\:\\:check\\(\\) expects bool, mixed given\\.$#"
count: 1
path: src/Command/BiomeJsCheckCommand.php

-
message: "#^Parameter \\$formatterEnabled of method Kocal\\\\BiomeJsBundle\\\\BiomeJs\\:\\:check\\(\\) expects bool, mixed given\\.$#"
count: 1
path: src/Command/BiomeJsCheckCommand.php

-
message: "#^Parameter \\$linterEnabled of method Kocal\\\\BiomeJsBundle\\\\BiomeJs\\:\\:check\\(\\) expects bool, mixed given\\.$#"
count: 1
path: src/Command/BiomeJsCheckCommand.php

-
message: "#^Parameter \\$organizeImportsEnabled of method Kocal\\\\BiomeJsBundle\\\\BiomeJs\\:\\:check\\(\\) expects bool, mixed given\\.$#"
count: 1
path: src/Command/BiomeJsCheckCommand.php

-
message: "#^Parameter \\$path of method Kocal\\\\BiomeJsBundle\\\\BiomeJs\\:\\:check\\(\\) expects array\\<string\\>, mixed given\\.$#"
count: 1
Expand All @@ -46,22 +21,17 @@ parameters:
path: src/Command/BiomeJsCheckCommand.php

-
message: "#^Parameter \\$changed of method Kocal\\\\BiomeJsBundle\\\\BiomeJs\\:\\:ci\\(\\) expects bool, mixed given\\.$#"
message: "#^Parameter \\$unsafe of method Kocal\\\\BiomeJsBundle\\\\BiomeJs\\:\\:check\\(\\) expects bool, mixed given\\.$#"
count: 1
path: src/Command/BiomeJsCiCommand.php

-
message: "#^Parameter \\$formatterEnabled of method Kocal\\\\BiomeJsBundle\\\\BiomeJs\\:\\:ci\\(\\) expects bool, mixed given\\.$#"
count: 1
path: src/Command/BiomeJsCiCommand.php
path: src/Command/BiomeJsCheckCommand.php

-
message: "#^Parameter \\$linterEnabled of method Kocal\\\\BiomeJsBundle\\\\BiomeJs\\:\\:ci\\(\\) expects bool, mixed given\\.$#"
message: "#^Parameter \\$write of method Kocal\\\\BiomeJsBundle\\\\BiomeJs\\:\\:check\\(\\) expects bool, mixed given\\.$#"
count: 1
path: src/Command/BiomeJsCiCommand.php
path: src/Command/BiomeJsCheckCommand.php

-
message: "#^Parameter \\$organizeImportsEnabled of method Kocal\\\\BiomeJsBundle\\\\BiomeJs\\:\\:ci\\(\\) expects bool, mixed given\\.$#"
message: "#^Parameter \\$changed of method Kocal\\\\BiomeJsBundle\\\\BiomeJs\\:\\:ci\\(\\) expects bool, mixed given\\.$#"
count: 1
path: src/Command/BiomeJsCiCommand.php

Expand All @@ -79,6 +49,7 @@ parameters:
message: "#^Cannot call method end\\(\\) on Symfony\\\\Component\\\\Config\\\\Definition\\\\Builder\\\\NodeParentInterface\\|null\\.$#"
count: 1
path: src/DependencyInjection/BiomeJsExtension.php

-
message: "#^Call to an undefined method Symfony\\\\Component\\\\Config\\\\Definition\\\\Builder\\\\NodeParentInterface\\:\\:end\\(\\)\\.$#"
count: 1
Expand Down
15 changes: 9 additions & 6 deletions src/BiomeJs.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
use Symfony\Component\Console\Style\SymfonyStyle;
use Symfony\Component\Process\Process;

/**
* @internal
*/
final class BiomeJs
{
private ?SymfonyStyle $output;
Expand All @@ -25,8 +28,8 @@ public function setOutput(?SymfonyStyle $output): void
* @param array<string> $path
*/
public function check(
bool $apply,
bool $applyUnsafe,
bool $write,
bool $unsafe,
bool $formatterEnabled,
bool $linterEnabled,
bool $organizeImportsEnabled,
Expand All @@ -36,11 +39,11 @@ public function check(
array $path,
): Process {
$arguments = [];
if ($apply) {
$arguments[] = '--apply';
if ($write) {
$arguments[] = '--write';
}
if ($applyUnsafe) {
$arguments[] = '--apply-unsafe';
if ($unsafe) {
$arguments[] = '--unsafe';
}
$arguments[] = '--formatter-enabled=' . ($formatterEnabled ? 'true' : 'false');
$arguments[] = '--linter-enabled=' . ($linterEnabled ? 'true' : 'false');
Expand Down
3 changes: 3 additions & 0 deletions src/BiomeJsBinary.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
use Symfony\Component\Process\Process;
use Symfony\Contracts\HttpClient\HttpClientInterface;

/**
* @internal
*/
final class BiomeJsBinary implements BiomeJsBinaryInterface
{
private ?SymfonyStyle $output = null;
Expand Down
26 changes: 22 additions & 4 deletions src/Command/BiomeJsCheckCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,12 @@ public function __construct(
protected function configure(): void
{
$this
->addOption('apply', null, InputOption::VALUE_NONE, 'Apply safe fixes, formatting and import sorting')
->addOption('apply-unsafe', null, InputOption::VALUE_NONE, 'Apply safe fixes and unsafe fixes, formatting and import sorting')
->addOption('write', null, InputOption::VALUE_NONE, 'Writes safe fixes, formatting and import sorting')
->addOption('unsafe', null, InputOption::VALUE_NONE, ' Allow to do unsafe fixes, should be used with --write')
// TODO: Deprecated, remove in favor of --write
->addOption('apply', null, InputOption::VALUE_NONE, 'Apply safe fixes, formatting and import sorting (deprecated, use --write)')
// TODO: Deprecated, remove in favor of --unsafe
->addOption('apply-unsafe', null, InputOption::VALUE_NONE, 'Apply safe fixes and unsafe fixes, formatting and import sorting (deprecated, use --write --unsafe)')
->addOption('formatter-enabled', null, InputOption::VALUE_OPTIONAL, 'Allow to enable or disable the formatter check', true)
->addOption('linter-enabled', null, InputOption::VALUE_OPTIONAL, 'Allow to enable or disable the linter check', true)
->addOption('organize-imports-enabled', null, InputOption::VALUE_OPTIONAL, 'Allow to enable or disable the organize imports.', true)
Expand All @@ -50,9 +54,23 @@ protected function execute(InputInterface $input, OutputInterface $output): int
{
$this->biomeJs->setOutput($this->io);

$write = $input->getOption('write');
$unsafe = $input->getOption('unsafe');

if ($input->getOption('apply')) {
$this->io->warning('The "--apply" option is deprecated and will be removed in the next major version, use "--write" instead.');
$write = true;
}

if ($input->getOption('apply-unsafe')) {
$this->io->warning('The "--apply-unsafe" option is deprecated and will be removed in the next major version, use "--write --unsafe" instead.');
$write = true;
$unsafe = true;
}

$process = $this->biomeJs->check(
apply: $input->getOption('apply'),
applyUnsafe: $input->getOption('apply-unsafe'),
write: $write,
unsafe: $unsafe,
formatterEnabled: filter_var($input->getOption('formatter-enabled'), FILTER_VALIDATE_BOOL),
linterEnabled: filter_var($input->getOption('linter-enabled'), FILTER_VALIDATE_BOOL),
organizeImportsEnabled: filter_var($input->getOption('organize-imports-enabled'), FILTER_VALIDATE_BOOL),
Expand Down

0 comments on commit fdc033e

Please sign in to comment.