Skip to content
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: to prevent spell checking errors when a user home directory has … #92

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions src/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use Closure;
use Peck\Support\PresetProvider;
use Peck\Support\ProjectPath;
use Peck\Support\SpellcheckFormatter;

final class Config
{
Expand Down Expand Up @@ -151,6 +152,7 @@ public function isWordIgnored(string $word): bool
return in_array(strtolower($word), [
...$this->whitelistedWords,
...PresetProvider::whitelistedWords($this->preset),
...$this->ignoreWordsFromProjectPath(),
]);
}

Expand All @@ -169,4 +171,16 @@ private function persist(): void
],
], JSON_PRETTY_PRINT));
}

/**
* Ignore words from the project path including $HOME directory. Prevents spell check errors for cache constant
*
* @return list<string>
*/
private function ignoreWordsFromProjectPath(): array
{
$directories = explode(DIRECTORY_SEPARATOR, ProjectPath::get());

return array_map(fn ($directory): string => SpellcheckFormatter::format($directory), array_filter($directories));
}
}
3 changes: 2 additions & 1 deletion src/Plugins/Cache.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace Peck\Plugins;

use Peck\Support\ProjectPath;
use RuntimeException;

final readonly class Cache
Expand All @@ -27,7 +28,7 @@ public function __construct(
*/
public static function default(): self
{
$basePath = __DIR__.'/../../';
$basePath = ProjectPath::get();

$cache = new self("{$basePath}/.peck.cache");

Expand Down
Loading