dantleech / gherkin-lint-php

PHP Gherkin Linter
MIT License
45 stars 6 forks source link

Rules #1

Closed dantleech closed 2 years ago

dantleech commented 2 years ago

This PR introduces the linter and 2 rules:

image

ciaranmcnulty commented 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);
        }
    }
}
dantleech commented 2 years ago

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 ....

ciaranmcnulty commented 2 years ago

That's why dot output is so much easier :)

dantleech commented 2 years ago

Not cool though

dantleech commented 2 years ago

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

dantleech commented 2 years ago

ok, i think I'll refactor to use Generators throughout, I'll merge this now though,

dantleech commented 2 years ago

Refactored a bit here: https://github.com/dantleech/gherkin-lint-php/pull/2