mirror of
https://github.com/Respect/Validation.git
synced 2026-03-15 06:45:44 +01:00
This commit introduces REUSE compliance by annotating all files with SPDX information and placing the reused licences in the LICENSES folder. We additionally removed the docheader tool which is made obsolete by this change. The main LICENSE and copyright text of the project is now not under my personal name anymore, and it belongs to "The Respect Project Contributors" instead. This change restores author names to several files, giving the appropriate attribution for contributions.
83 lines
2.1 KiB
PHP
83 lines
2.1 KiB
PHP
<?php
|
|
|
|
/*
|
|
* SPDX-License-Identifier: MIT
|
|
* SPDX-FileCopyrightText: (c) Respect Project Contributors
|
|
* SPDX-FileContributor: Henrique Moody <henriquemoody@gmail.com>
|
|
*/
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace Respect\Dev\Commands;
|
|
|
|
use Respect\Dev\Markdown\Differ;
|
|
use Respect\Dev\Markdown\File;
|
|
use Respect\Dev\Markdown\Linter;
|
|
use Symfony\Component\Console\Attribute\AsCommand;
|
|
use Symfony\Component\Console\Command\Command;
|
|
use Symfony\Component\Console\Input\InputInterface;
|
|
use Symfony\Component\Console\Output\OutputInterface;
|
|
use Symfony\Component\Finder\Finder;
|
|
|
|
use function count;
|
|
use function dirname;
|
|
use function sprintf;
|
|
|
|
#[AsCommand(
|
|
name: 'docs:lint',
|
|
description: 'Apply documentation linters and optionally auto-fix issues',
|
|
)]
|
|
final class DocsLintCommand extends Command
|
|
{
|
|
public function __construct(
|
|
private readonly Differ $differ,
|
|
private readonly Linter $linter,
|
|
) {
|
|
parent::__construct();
|
|
}
|
|
|
|
protected function configure(): void
|
|
{
|
|
$this->addOption(
|
|
'fix',
|
|
null,
|
|
null,
|
|
'Automatically fix files with issues.',
|
|
);
|
|
}
|
|
|
|
protected function execute(InputInterface $input, OutputInterface $output): int
|
|
{
|
|
$finder = new Finder();
|
|
$finder->in(dirname(__DIR__, 2) . '/docs')->files()->name('*.md');
|
|
|
|
$lintedFiles = [];
|
|
foreach ($finder as $file) {
|
|
$original = File::from($file);
|
|
$linted = $this->linter->lint($original);
|
|
if ($linted === $original) {
|
|
continue;
|
|
}
|
|
|
|
$lintedFiles[] = $linted;
|
|
|
|
$output->writeln($this->differ->diff($original, $linted));
|
|
}
|
|
|
|
if ($lintedFiles === []) {
|
|
$output->writeln('<info>No changes needed.</info>');
|
|
} else {
|
|
$output->writeln(sprintf('<comment>Changes needed in %d files.</comment>', count($lintedFiles)));
|
|
}
|
|
|
|
if ($lintedFiles !== [] && !$input->getOption('fix')) {
|
|
return Command::FAILURE;
|
|
}
|
|
|
|
foreach ($lintedFiles as $linted) {
|
|
$linted->save();
|
|
}
|
|
|
|
return Command::SUCCESS;
|
|
}
|
|
}
|