Skip to content

Commit

Permalink
Refactors/simplify out of box experience
Browse files Browse the repository at this point in the history
  • Loading branch information
JohnathonKoster committed Feb 11, 2024
1 parent 46e59cf commit fc14708
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 5 deletions.
3 changes: 2 additions & 1 deletion src/Console/Commands/ValidateBladeCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use Stillat\BladeParser\Document\Document;
use Stillat\BladeParser\Errors\BladeError;
use Stillat\BladeParser\Errors\ErrorFamily;
use Stillat\BladeParser\Providers\ValidatorServiceProvider;
use Stillat\BladeParser\Validation\Workspaces\PhpStanWrapper;
use Stillat\BladeParser\Workspaces\Workspace;

Expand All @@ -31,7 +32,7 @@ public function handle(Workspace $workspace)
$totalStart = microtime(true);
$bladeStart = microtime(true);
$workspace->withCoreValidators()
->ignoreDirectives(config('blade.validation.ignore_directives', []))
->ignoreDirectives(ValidatorServiceProvider::getIgnoreDirectives())
->addDirectory(resource_path('views'));

$runMessage = "Running {$workspace->validator()->getValidatorCount()} validators against {$workspace->getFileCount()} files.";
Expand Down
7 changes: 6 additions & 1 deletion src/Providers/ValidatorServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,18 @@

class ValidatorServiceProvider extends ServiceProvider
{
public static function getIgnoreDirectives()
{
return array_merge(config('blade.validation.ignore_directives', []), ['livewire']);
}

public function register()
{
$this->mergeConfigFrom(
__DIR__.'/../../config/validation.php', 'blade.validation'
);

$globalIgnoreDirectives = config('blade.validation.ignore_directives', []);
$globalIgnoreDirectives = self::getIgnoreDirectives();
$globalCustomDirectives = config('blade.validation.custom_directives', []);

$availableConfig = config('blade.validation.options');
Expand Down
5 changes: 3 additions & 2 deletions src/Validation/PhpSyntaxValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
use Stillat\BladeParser\Nodes\AbstractNode;
use Stillat\BladeParser\Nodes\DirectiveNode;
use Stillat\BladeParser\Nodes\LiteralNode;
use Stillat\BladeParser\Providers\ValidatorServiceProvider;

class PhpSyntaxValidator
{
Expand All @@ -29,7 +30,7 @@ public function __construct()
{
$this->compilerOptions = new DocumentCompilerOptions();
$this->compilerOptions->throwExceptionOnUnknownComponentClass = false;
$this->compilerOptions->ignoreDirectives = config('blade.validation.ignore_directives', []);
$this->compilerOptions->ignoreDirectives = ValidatorServiceProvider::getIgnoreDirectives();
$this->compilerOptions->appendCallbacks[] = function (AppendState $state) {
for ($i = $state->beforeLineNumber; $i <= $state->afterLineNumber; $i++) {
$this->sourceMap[$i] = $state->node->position->startLine;
Expand Down Expand Up @@ -113,7 +114,7 @@ public function checkDocument(Document $document, ?int $originalLine = null): Ph
public function checkString(string $content, ?int $originalLine = null): PhpSyntaxValidationResult
{
return $this->checkDocument(
Document::fromText($content, documentOptions: new DocumentOptions(ignoreDirectives: config('blade.validation.ignore_directives', []))), $originalLine
Document::fromText($content, documentOptions: new DocumentOptions(ignoreDirectives: ValidatorServiceProvider::getIgnoreDirectives())), $originalLine
);
}

Expand Down
2 changes: 1 addition & 1 deletion src/Workspaces/Concerns/CompilesWorkspace.php
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ public function getCompilerOptions(): DocumentCompilerOptions

$options = new DocumentCompilerOptions();
$options->throwExceptionOnUnknownComponentClass = false;
$options->ignoreDirectives = config('blade.validation.ignore_directives', []);
$options->ignoreDirectives = $this->ignoreDirectives;

return $options;
}
Expand Down

0 comments on commit fc14708

Please sign in to comment.