From 241ff703fe0eb463455e4faca9b81d42cc65465b Mon Sep 17 00:00:00 2001 From: butschster Date: Fri, 3 Sep 2021 19:33:49 +0300 Subject: [PATCH 1/2] Added ability to ignore patch to check CS --- src/Commands/CheckCommand.php | 10 ++++++++++ src/Commands/FixCommand.php | 2 +- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/src/Commands/CheckCommand.php b/src/Commands/CheckCommand.php index 18a4cb2..3574d57 100644 --- a/src/Commands/CheckCommand.php +++ b/src/Commands/CheckCommand.php @@ -32,6 +32,10 @@ protected function execute(InputInterface $input, OutputInterface $output): int '--standard=' . $input->getOption('ruleset'), ], $this->helper->wrapPaths($input->getArgument('paths'))); + if ($input->hasOption('ignore')) { + $_SERVER['argv'][] = '--ignore=' . $input->getOption('ignore'); + } + $runner = new Runner(); $exitCode = $runner->runPHPCS(); @@ -52,6 +56,12 @@ protected function configure() InputArgument::IS_ARRAY | InputArgument::REQUIRED, 'Enumerate directories or files to check' ) + ->addOption( + 'ignore', + 'i', + InputArgument::OPTIONAL, + 'A comma separated list of patterns to ignore files and directories' + ) ->addOption( 'ruleset', 'r', diff --git a/src/Commands/FixCommand.php b/src/Commands/FixCommand.php index 4517d4e..583c1fc 100644 --- a/src/Commands/FixCommand.php +++ b/src/Commands/FixCommand.php @@ -73,7 +73,7 @@ protected function configure() ->addArgument( 'paths', InputArgument::IS_ARRAY | InputArgument::REQUIRED, - 'Enumerate directories or files to check' + 'Enumerate directories or files to fix' ) ->addOption( 'config', From ffedce6e1467c39ae6eb8197586f533257b63a8a Mon Sep 17 00:00:00 2001 From: butschster Date: Wed, 8 Sep 2021 22:24:43 +0300 Subject: [PATCH 2/2] Added test for ignored files --- tests/CodeStyle/CodeStyleCheckTest.php | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/tests/CodeStyle/CodeStyleCheckTest.php b/tests/CodeStyle/CodeStyleCheckTest.php index 2774c32..c0cd637 100644 --- a/tests/CodeStyle/CodeStyleCheckTest.php +++ b/tests/CodeStyle/CodeStyleCheckTest.php @@ -27,7 +27,6 @@ public function testWrongFormattedClass(): void public function testWellFormattedClass(): void { - $out = $this->execCommand([ 'bin/spiral-cs', 'check', @@ -37,4 +36,17 @@ public function testWellFormattedClass(): void $this->assertArrayHasKey(0, $out); $this->assertEquals($out[0], 'No codestyle issues'); } + + public function testIgnoredFilesShouldBeSkipped() + { + $out = $this->execCommand([ + 'bin/spiral-cs', + 'check', + '--ignore=NotFormattedClass.php', + 'tests/fixtures/temp/' + ]); + + $this->assertArrayHasKey(0, $out); + $this->assertEquals($out[0], 'No codestyle issues'); + } }