-
-
Notifications
You must be signed in to change notification settings - Fork 53
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: misspelling should still be recognised as a misspelling when no suggestions are returned #121
base: main
Are you sure you want to change the base?
Conversation
…tions are returned Signed-off-by: Ben James <[email protected]>
40291f7
to
7629314
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@benjam-es I reviewed the changes. Generally, I think this is a good contribution. I just added some feedback where I see some problems with your approach.
Please take a look the the feedback and suggestions. I really like that you added good tests for your changes!
@@ -198,6 +198,8 @@ private function renderLineIssue(Issue $issue): void | |||
$issue, | |||
); | |||
|
|||
$suggestionsHelperText = ($suggestions > '') ? 'Did you mean:' : 'No suggestions found.'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would prefer checking directly for "not equals" or am I missing something?
$suggestionsHelperText = ($suggestions > '') ? 'Did you mean:' : 'No suggestions found.'; | |
$suggestionsHelperText = ($suggestions !=== '') ? 'Did you mean:' : 'No suggestions found.'; |
@@ -272,6 +274,8 @@ private function renderLineLessIssue(Issue $issue): void | |||
$issue, | |||
); | |||
|
|||
$suggestionsHelperText = ($suggestions > '') ? 'Did you mean:' : 'No suggestions found.'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See previous comment ^^
$suggestionsHelperText = ($suggestions > '') ? 'Did you mean:' : 'No suggestions found.'; | |
$suggestionsHelperText = ($suggestions !=== '') ? 'Did you mean:' : 'No suggestions found.'; |
@@ -64,7 +64,7 @@ public function check(string $text): array | |||
*/ | |||
private function getMisspellings(string $text): array | |||
{ | |||
$misspellings = iterator_to_array($this->run($text)); | |||
$misspellings = $this->run($text); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we really drop this conversion at this position?
Then it would be serialized as an iterator and returned as an iterator from the cache.
This would cause the is_array()
call to always be false
:
peck/src/Services/Spellcheckers/Aspell.php
Lines 48 to 53 in 818c85c
/** @var array<int, Misspelling>|null $misspellings */ | |
$misspellings = $this->cache->has($text) ? $this->cache->get($text) : $this->getMisspellings($text); | |
if (! is_array($misspellings)) { | |
$misspellings = $this->getMisspellings($text); | |
} |
$lines = $this->getAspellLinesFromOutput($output); | ||
|
||
return $this->getMisspellingsFromOutputLines($lines); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We don't need the variable and can pass this directly:
$lines = $this->getAspellLinesFromOutput($output); | |
return $this->getMisspellingsFromOutputLines($lines); | |
return $this->getMisspellingsFromOutputLines( | |
$this->getAspellLinesFromOutput($output) | |
); |
if (preg_match('/#\\s(\\w*)\\sd*/', $line, $matches)) { | ||
$word = $matches[1]; | ||
$suggestions = []; | ||
} else { | ||
[$wordMetadataAsString, $suggestionsAsString] = explode(':', trim($line)); | ||
$word = explode(' ', $wordMetadataAsString)[1]; | ||
$suggestions = explode(', ', trim($suggestionsAsString)); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you wanted to, we could turn this if-else block into two match()
statements.
This way we do not rely on the variables from inside the if block in the return statement and clearly separate the aggregation of the $word
and the $suggestions
.
if (preg_match('/#\\s(\\w*)\\sd*/', $line, $matches)) { | |
$word = $matches[1]; | |
$suggestions = []; | |
} else { | |
[$wordMetadataAsString, $suggestionsAsString] = explode(':', trim($line)); | |
$word = explode(' ', $wordMetadataAsString)[1]; | |
$suggestions = explode(', ', trim($suggestionsAsString)); | |
} | |
$word = match (true) { | |
preg_match('/#\\s(\\w*)\\sd*/', $line, $matches) => $matches[1], | |
default => explode(' ', explode(':', trim($line))[0])[1], | |
}; | |
$suggestions = match (true) { | |
preg_match('/#\\s(\\w*)\\sd*/', $line, $matches) => [], | |
default => explode(', ', trim(explode(':', trim($line))[1])), | |
}; |
I marked this as a draft for now until we discussed and implemented some of the feedback I gave you. |
…
What:
Description:
Fixes #100
When a misspelling occurs, but no suggestions are found, the spellchecker returns as a pass. This is incorrect as the misspelling should still be reported.
results in:
With this PR:
Related:
Issue #100
Also just found #101