Skip to content

Commit

Permalink
feat: add support for --configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
owenvoke committed Sep 24, 2024
1 parent 5d684f7 commit 7f45ccc
Show file tree
Hide file tree
Showing 2 changed files with 92 additions and 72 deletions.
138 changes: 70 additions & 68 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,70 +1,72 @@
{
"name": "worksome/graphlint",
"description": "A static analysis tool for GraphQl",
"type": "project",
"require": {
"php": "^8.2",
"webonyx/graphql-php": "^15.0.1",
"symfony/console": "^6.1",
"illuminate/support": "^10.0",
"symfony/dependency-injection": "^6.0",
"symfony/http-kernel": "^6.0",
"symfony/config": "^6.0",
"symplify/autowire-array-parameter": "^11.0",
"symplify/package-builder": "^11.0",
"thecodingmachine/safe": "^2.4",
"jawira/case-converter": "^3.5"
},
"require-dev": {
"pestphp/pest": "^2.34",
"symfony/var-dumper": "^6.4",
"symplify/easy-testing": "^11.0",
"worksome/coding-style": "^2.10.2"
},
"license": "MIT",
"autoload": {
"psr-4": {
"Worksome\\Graphlint\\": "src/"
}
},
"autoload-dev": {
"psr-4": {
"Worksome\\Graphlint\\Tests\\": "tests/"
}
},
"bin": [
"bin/graphlint"
],
"authors": [
{
"name": "Oliver Nybroe",
"email": "[email protected]"
}
],
"config": {
"allow-plugins": {
"pestphp/pest-plugin": true,
"dealerdirect/phpcodesniffer-composer-installer": true,
"worksome/coding-style": true
}
},
"scripts": {
"ecs": "vendor/bin/ecs",
"ecs:fix": "vendor/bin/ecs --fix",
"phpstan": "vendor/bin/phpstan analyse",
"rector": "vendor/bin/rector process --dry-run --ansi",
"rector:fix": "vendor/bin/rector process --ansi",
"pest": "vendor/bin/pest --parallel",
"test": [
"@ecs",
"@phpstan",
"@rector",
"@pest"
]
},
"suggest": {
"ext-dom": "Required for Checkstyle output format."
},
"minimum-stability": "dev",
"prefer-stable": true
"name": "worksome/graphlint",
"description": "A static analysis tool for GraphQl",
"type": "project",
"require": {
"php": "^8.2",
"illuminate/support": "^10.0",
"jawira/case-converter": "^3.5",
"symfony/config": "^6.0",
"symfony/console": "^6.1",
"symfony/dependency-injection": "^6.0",
"symfony/filesystem": "^6.4",
"symfony/http-kernel": "^6.0",
"symplify/autowire-array-parameter": "^11.0",
"symplify/package-builder": "^11.0",
"thecodingmachine/safe": "^2.4",
"webonyx/graphql-php": "^15.0.1"
},
"require-dev": {
"pestphp/pest": "^2.34",
"symfony/var-dumper": "^6.4",
"symplify/easy-testing": "^11.0",
"worksome/coding-style": "^2.10.2"
},
"license": "MIT",
"autoload": {
"psr-4": {
"Worksome\\Graphlint\\": "src/"
}
},
"autoload-dev": {
"psr-4": {
"Worksome\\Graphlint\\Tests\\": "tests/"
}
},
"bin": [
"bin/graphlint"
],
"authors": [
{
"name": "Oliver Nybroe",
"email": "[email protected]"
}
],
"config": {
"sort-packages": true,
"allow-plugins": {
"pestphp/pest-plugin": true,
"dealerdirect/phpcodesniffer-composer-installer": true,
"worksome/coding-style": true
}
},
"scripts": {
"ecs": "vendor/bin/ecs",
"ecs:fix": "vendor/bin/ecs --fix",
"phpstan": "vendor/bin/phpstan analyse",
"rector": "vendor/bin/rector process --dry-run --ansi",
"rector:fix": "vendor/bin/rector process --ansi",
"pest": "vendor/bin/pest --parallel",
"test": [
"@ecs",
"@phpstan",
"@rector",
"@pest"
]
},
"suggest": {
"ext-dom": "Required for Checkstyle output format."
},
"minimum-stability": "dev",
"prefer-stable": true
}
26 changes: 22 additions & 4 deletions src/Commands/AnalyseCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,14 @@
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Style\SymfonyStyle;
use Symfony\Component\Filesystem\Path;
use Symplify\PackageBuilder\Console\Output\ConsoleDiffer;
use Worksome\Graphlint\EmptyDocumentNode;
use Worksome\Graphlint\Graphlint;
use Worksome\Graphlint\Kernel;
use Worksome\Graphlint\Listeners\CheckstyleListener;
use Worksome\Graphlint\Listeners\ConsolePrinterListener;
use Worksome\Graphlint\ShouldNotHappenException;

use function Safe\file_get_contents;

Expand Down Expand Up @@ -49,17 +51,24 @@ protected function configure(): void
$this->addOption(
self::INPUT,
null,
InputOption::VALUE_OPTIONAL,
InputOption::VALUE_REQUIRED,
'The format for the schema inputs.',
InputFormat::FILE->value,
);
$this->addOption(
self::FORMAT,
null,
InputOption::VALUE_OPTIONAL,
InputOption::VALUE_REQUIRED,
'The output format.',
OutputFormat::Text->value,
);
$this->addOption(
'configuration',
'c',
InputOption::VALUE_REQUIRED,
'The configuration file.',
'graphlint.php',
);
}

/** @throws SyntaxError|FilesystemException|JsonException */
Expand All @@ -70,10 +79,19 @@ protected function execute(InputInterface $input, OutputInterface $output): int
$output
);

$configurationFile = getcwd() . DIRECTORY_SEPARATOR . 'graphlint.php';
$currentWorkingDirectory = getcwd();
if ($currentWorkingDirectory === false) {
throw new ShouldNotHappenException();
}

/** @var string $configurationFile */
$configurationFile = $input->getOption('configuration');

/** @var non-empty-string $configurationFile */
$configurationFile = Path::makeAbsolute($configurationFile, $currentWorkingDirectory);

if (! is_file($configurationFile) || ! is_readable($configurationFile)) {
$style->error("Unable to find a \"graphlint.php\" configuration file in your current directory.");
$style->error("Unable to find a \"{$configurationFile}\" configuration file.");

return self::FAILURE;
}
Expand Down

0 comments on commit 7f45ccc

Please sign in to comment.