From 41b58d1c175138ca0d751aa4e13e65864c0ab86f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dalibor=20Karlovi=C4=87?= Date: Mon, 4 Mar 2024 10:48:50 +0100 Subject: [PATCH] chore: update Psalm, fix issues --- composer.json | 2 +- src/Model/RuleDocumentationBuilder.php | 3 ++- src/Rule/FileNameRule.php | 10 ---------- src/Rule/IndentationRule.php | 2 +- src/Rule/NoBackgroundWithSingleScenarioRule.php | 2 +- src/Rule/NoConsecutiveEmptyLinesRule.php | 2 +- src/Rule/NoDisallowedPatternsConfig.php | 2 +- src/Rule/NoDisallowedPatternsRule.php | 2 +- 8 files changed, 8 insertions(+), 17 deletions(-) diff --git a/composer.json b/composer.json index 34aad43..5f37c6d 100644 --- a/composer.json +++ b/composer.json @@ -37,7 +37,7 @@ "symfony/var-dumper": "^6.0", "symfony/process": "^6.0", "phpunit/phpunit": "^10.5", - "vimeo/psalm": "^5.0@beta", + "vimeo/psalm": "^5.22", "friendsofphp/php-cs-fixer": "^3.8" }, "scripts": { diff --git a/src/Model/RuleDocumentationBuilder.php b/src/Model/RuleDocumentationBuilder.php index 75220b9..85f625e 100644 --- a/src/Model/RuleDocumentationBuilder.php +++ b/src/Model/RuleDocumentationBuilder.php @@ -33,6 +33,7 @@ public function generate(): string /** * @param list $out + * @param-out list $out */ private function ruleDocumentation(RuleDescription $description, array &$out): void { @@ -50,7 +51,7 @@ private function ruleDocumentation(RuleDescription $description, array &$out): v [ $description->name => $example->config, ], - JSON_PRETTY_PRINT + JSON_PRETTY_PRINT | JSON_THROW_ON_ERROR ); $out[] = '```json'; $out[] = $configString; diff --git a/src/Rule/FileNameRule.php b/src/Rule/FileNameRule.php index 1f66587..9899ac3 100644 --- a/src/Rule/FileNameRule.php +++ b/src/Rule/FileNameRule.php @@ -11,7 +11,6 @@ use DTL\GherkinLint\Model\RuleDescription; use DTL\GherkinLint\Model\RuleExample; use Generator; -use RuntimeException; use Symfony\Component\Filesystem\Path; use Symfony\Component\String\UnicodeString; @@ -33,10 +32,6 @@ public function analyse(ParsedFeature $feature, RuleConfig $config): Generator FileNameConfig::CAMEL_CASE => $path->camel()->__toString(), FileNameConfig::SNAKE_CASE => $path->snake()->__toString(), FileNameConfig::KEBAB_CASE => $path->snake()->replace('_', '-')->__toString(), - default => throw new RuntimeException(sprintf( - 'Invalid filename style "%s"', - $config->style - )), }; if ($converted === $path->__toString()) { @@ -108,9 +103,4 @@ public function describe(): RuleDescription ] ); } - - private function match(string $pattern, string $filename): bool - { - return (bool)preg_match($pattern, $filename); - } } diff --git a/src/Rule/IndentationRule.php b/src/Rule/IndentationRule.php index 507b742..49aa5bf 100644 --- a/src/Rule/IndentationRule.php +++ b/src/Rule/IndentationRule.php @@ -100,7 +100,7 @@ private function check(Location $location, string $name, IndentationConfig $conf $column = $location->column; - if (!$column) { + if ($column === null) { return; } diff --git a/src/Rule/NoBackgroundWithSingleScenarioRule.php b/src/Rule/NoBackgroundWithSingleScenarioRule.php index 16238b5..d01f400 100644 --- a/src/Rule/NoBackgroundWithSingleScenarioRule.php +++ b/src/Rule/NoBackgroundWithSingleScenarioRule.php @@ -37,7 +37,7 @@ public function analyse(ParsedFeature $feature, RuleConfig $config): Generator yield new FeatureDiagnostic( Range::fromLocationAndName($background->location, $background->name), FeatureDiagnosticSeverity::WARNING, - sprintf('Background is only permitted if there is more than one scenario') + 'Background is only permitted if there is more than one scenario' ); } } diff --git a/src/Rule/NoConsecutiveEmptyLinesRule.php b/src/Rule/NoConsecutiveEmptyLinesRule.php index 995e314..c54da00 100644 --- a/src/Rule/NoConsecutiveEmptyLinesRule.php +++ b/src/Rule/NoConsecutiveEmptyLinesRule.php @@ -57,7 +57,7 @@ public function analyse(ParsedFeature $feature, RuleConfig $config): Generator $prev = $lineNo; } - if ($start && $lineNo && $prev) { + if ($start && $prev) { yield new FeatureDiagnostic( Range::fromInts($start, 1, $prev, 1), FeatureDiagnosticSeverity::WARNING, diff --git a/src/Rule/NoDisallowedPatternsConfig.php b/src/Rule/NoDisallowedPatternsConfig.php index e5cd607..f64877a 100644 --- a/src/Rule/NoDisallowedPatternsConfig.php +++ b/src/Rule/NoDisallowedPatternsConfig.php @@ -7,7 +7,7 @@ class NoDisallowedPatternsConfig implements RuleConfig { public function __construct( - /** @var string[] */ + /** @var list */ public readonly array $patterns = [] ) { } diff --git a/src/Rule/NoDisallowedPatternsRule.php b/src/Rule/NoDisallowedPatternsRule.php index b6bd31c..3fff88f 100644 --- a/src/Rule/NoDisallowedPatternsRule.php +++ b/src/Rule/NoDisallowedPatternsRule.php @@ -18,7 +18,7 @@ public function analyse(ParsedFeature $feature, RuleConfig $config): Generator { assert($config instanceof NoDisallowedPatternsConfig); foreach ($config->patterns as $pattern) { - if (!preg_match_all($pattern, $feature->source(), $matches, PREG_OFFSET_CAPTURE)) { + if (preg_match_all($pattern, $feature->source(), $matches, PREG_OFFSET_CAPTURE) === false) { continue; }