generated from ddev/ddev-addon-template
-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add a new phpcs command to run phpcs analysis (#28)
* Create PhpCsCommand.php * Update install.yaml * Update drupal * Update PhpCsCommand.php * Add more linting commands * Fixes to lint commands and add documentation --------- Co-authored-by: Sally Young <[email protected]>
- Loading branch information
Showing
11 changed files
with
301 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
<?php | ||
#ddev-generated | ||
|
||
namespace DrupalCoreDev\Command; | ||
|
||
use Symfony\Component\Console\Command\Command; | ||
use Symfony\Component\Console\Input\InputInterface; | ||
use Symfony\Component\Console\Input\InputOption; | ||
use Symfony\Component\Console\Output\OutputInterface; | ||
use Symfony\Component\Process\Process; | ||
|
||
class LintCommand extends Command { | ||
/** | ||
* {@inheritdoc} | ||
*/ | ||
protected function configure(): void { | ||
$this->setName('lint') | ||
->setDescription('Run lint tests.') | ||
->addOption('stop-on-failure', null, InputOption::VALUE_NONE, 'Stop all test execution once a failure is found.'); | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
protected function execute(InputInterface $input, OutputInterface $output): int { | ||
$return = 0; | ||
$stop_on_failure = $input->getOption('stop-on-failure'); | ||
|
||
$commands = [ | ||
new LintPhpCsCommand(), | ||
new LintPhpStanCommand(), | ||
new LintCssCommand(), | ||
new LintJsCommand(), | ||
new LintCspellCommand(), | ||
]; | ||
|
||
foreach ($commands as $command) { | ||
$return_command = $command->execute($input, $output); | ||
if (!$return_command) { | ||
continue; | ||
} | ||
$return = $return_command; | ||
|
||
if ($stop_on_failure) { | ||
return $return; | ||
} | ||
} | ||
|
||
return $return; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
<?php | ||
#ddev-generated | ||
|
||
namespace DrupalCoreDev\Command; | ||
|
||
use Symfony\Component\Console\Command\Command; | ||
use Symfony\Component\Console\Input\InputInterface; | ||
use Symfony\Component\Console\Input\InputOption; | ||
use Symfony\Component\Console\Output\OutputInterface; | ||
use Symfony\Component\Process\Process; | ||
|
||
class LintCspellCommand extends Command { | ||
/** | ||
* {@inheritdoc} | ||
*/ | ||
protected function configure(): void { | ||
$this->setName('lint:cspell') | ||
->setDescription('Run CSpell analysis.') | ||
->addOption('modified-only', null, InputOption::VALUE_NONE, 'Only run cspell on modified files.'); | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
protected function execute(InputInterface $input, OutputInterface $output): int { | ||
$modified_only = $input->getOption('modified-only'); | ||
$command = "cd core && yarn run spellcheck:core --no-must-find-files"; | ||
if ($modified_only) { | ||
$command = "cd core && git diff --name-only | sed \"s_^_../_\" | yarn run spellcheck:core --no-must-find-files --file-list stdin"; | ||
} | ||
$phpcs = Process::fromShellCommandline($command); | ||
$output->writeln($command); | ||
$phpcs->setTimeout(0); | ||
$phpcs->run(function ($type, $data) use ($output) { | ||
$output->write($data); | ||
}); | ||
if ($phpcs->getExitCode()) { | ||
return 1; | ||
} | ||
return 0; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
<?php | ||
#ddev-generated | ||
|
||
namespace DrupalCoreDev\Command; | ||
|
||
use Symfony\Component\Console\Command\Command; | ||
use Symfony\Component\Console\Input\InputInterface; | ||
use Symfony\Component\Console\Output\OutputInterface; | ||
use Symfony\Component\Console\Style\SymfonyStyle; | ||
use Symfony\Component\Process\Process; | ||
|
||
class LintCssCommand extends Command { | ||
/** | ||
* {@inheritdoc} | ||
*/ | ||
protected function configure(): void { | ||
$this->setName('lint:css') | ||
->setDescription('Run CSS coding standard analysis against core.'); | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
protected function execute(InputInterface $input, OutputInterface $output): int { | ||
$io = new SymfonyStyle($input, $output); | ||
$yarn = getcwd() . '/core/.yarn'; | ||
$node_modules = getcwd() . '/core/node_modules'; | ||
|
||
// Check if dependencies folder exists before to start. | ||
if(!file_exists($yarn) || !file_exists($node_modules)) { | ||
$io->error('Missing Yarn dependencies. Ensure that you run yarn install before executing this command.'); | ||
return 1; | ||
} | ||
|
||
$command = "cd core && yarn run lint:css --color --custom-formatter=node_modules/stylelint-formatter-gitlab"; | ||
$phpcs = Process::fromShellCommandline($command); | ||
$output->writeln($command); | ||
$phpcs->setTimeout(0); | ||
$phpcs->run(function ($type, $data) use ($output) { | ||
$output->write($data); | ||
}); | ||
if ($phpcs->getExitCode()) { | ||
return 1; | ||
} | ||
return 0; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
<?php | ||
#ddev-generated | ||
|
||
namespace DrupalCoreDev\Command; | ||
|
||
use Symfony\Component\Console\Command\Command; | ||
use Symfony\Component\Console\Input\InputInterface; | ||
use Symfony\Component\Console\Output\OutputInterface; | ||
use Symfony\Component\Console\Style\SymfonyStyle; | ||
use Symfony\Component\Process\Process; | ||
|
||
class LintJsCommand extends Command { | ||
/** | ||
* {@inheritdoc} | ||
*/ | ||
protected function configure(): void { | ||
$this->setName('lint:js') | ||
->setDescription('Run JS coding standard analysis against core.'); | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
protected function execute(InputInterface $input, OutputInterface $output): int { | ||
$io = new SymfonyStyle($input, $output); | ||
$yarn = getcwd() . '/core/.yarn'; | ||
$node_modules = getcwd() . '/core/node_modules'; | ||
|
||
// Check if dependencies folder exists before to start. | ||
if(!file_exists($yarn) || !file_exists($node_modules)) { | ||
$io->error('Missing Yarn dependencies. Ensure that you run yarn install before executing this command.'); | ||
return 1; | ||
} | ||
|
||
$command = "cd core && yarn run lint:core-js-passing"; | ||
$phpcs = Process::fromShellCommandline($command); | ||
$output->writeln($command); | ||
$phpcs->setTimeout(0); | ||
$phpcs->run(function ($type, $data) use ($output) { | ||
$output->write($data); | ||
}); | ||
if ($phpcs->getExitCode()) { | ||
return 1; | ||
} | ||
return 0; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
<?php | ||
#ddev-generated | ||
|
||
namespace DrupalCoreDev\Command; | ||
|
||
use Symfony\Component\Console\Command\Command; | ||
use Symfony\Component\Console\Input\InputInterface; | ||
use Symfony\Component\Console\Output\OutputInterface; | ||
use Symfony\Component\Process\Process; | ||
|
||
class LintPhpCsCommand extends Command { | ||
/** | ||
* {@inheritdoc} | ||
*/ | ||
protected function configure(): void { | ||
$this->setName('lint:phpcs') | ||
->setDescription('Run PHPCS coding standard analysis against core.'); | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
protected function execute(InputInterface $input, OutputInterface $output): int { | ||
$command = "composer phpcs -- --report-full --report-summary"; | ||
$phpcs = Process::fromShellCommandline($command); | ||
$output->writeln($command); | ||
$phpcs->setTimeout(0); | ||
$phpcs->run(function ($type, $data) use ($output) { | ||
$output->write($data); | ||
}); | ||
if ($phpcs->getExitCode()) { | ||
return 1; | ||
} | ||
return 0; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
<?php | ||
#ddev-generated | ||
|
||
namespace DrupalCoreDev\Command; | ||
|
||
use Symfony\Component\Console\Command\Command; | ||
use Symfony\Component\Console\Input\InputInterface; | ||
use Symfony\Component\Console\Output\OutputInterface; | ||
use Symfony\Component\Process\Process; | ||
|
||
class LintPhpStanCommand extends Command { | ||
/** | ||
* {@inheritdoc} | ||
*/ | ||
protected function configure(): void { | ||
$this->setName('lint:phpstan') | ||
->setDescription('Run PHPStan code quality analysis against core.'); | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
protected function execute(InputInterface $input, OutputInterface $output): int { | ||
$command = "php vendor/bin/phpstan analyze --configuration=./core/phpstan.neon.dist --error-format=table"; | ||
$phpcs = Process::fromShellCommandline($command); | ||
$output->writeln($command); | ||
$phpcs->setTimeout(0); | ||
$phpcs->run(function ($type, $data) use ($output) { | ||
$output->write($data); | ||
}); | ||
if ($phpcs->getExitCode()) { | ||
return 1; | ||
} | ||
return 0; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters