Closed dantleech closed 2 years ago
I like laziness so I would probably:
Then the code in LintCommand would look like:
$files = $this->finder->find($path);
$diagnostics = $this->linter->lint($files);
The Linter would be more like:
public function lint($files)
{
$sources = $this->sources($files);
$envelopes = $this->parser->parse($sources);
$documents = $this->gherkinDocuments($envelopes);
yield from $this->analyse($documents);
}
private function sources($files)
{
foreach ($files as $file) {
yield new Source(uri: $file->pathName(), data: file_get_contents($fileInfo->path));
}
}
private function gherkinDocuments($envelopes)
{
foreach ($envelopes as $envelope) {
if (!is_null($envelope->gherkinDocument)) {
yield $envelope->gherkinDocument;
}
}
}
private function analyse($documents)
{
foreach ($documents as $document) {
foreach ($this->rules as $rule) {
yield from $rule->analyse($document);
}
}
}
Make FeatureFinder::find return Generator
i was going to do this, however if we want a progress bar then we need to count the files anyway... so makes no difference (assuming a progress bar is useful).
otherwise your Linter looks better ....
That's why dot output is so much easier :)
Not cool though
antother thing is that Diagnostics need to be retrieved on a per-file basis to be able to organise them in report, which is why the Linter accepts a single file
ok, i think I'll refactor to use Generators throughout, I'll merge this now though,
Refactored a bit here: https://github.com/dantleech/gherkin-lint-php/pull/2
This PR introduces the linter and 2 rules:
no-empty-file
: Disallow empty filesno-duplicate-tags
: Disallow duplicate tags