Skip to content

Commit

Permalink
Merge pull request #371 from tighten/drift/ignore-escaped-blade
Browse files Browse the repository at this point in the history
Ignore escaped blade on `SpacesAroundBladeRenderContent` linters and formatters
  • Loading branch information
driftingly authored Nov 29, 2024
2 parents adee126 + dc55f84 commit bb64e99
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/Linters/SpacesAroundBladeRenderContent.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ class SpacesAroundBladeRenderContent extends BaseLinter
public const DESCRIPTION = 'Spaces around blade rendered content:'
. '`{{1 + 1}}` -> `{{ 1 + 1 }}`';

public const SEARCH_NORMAL = '/\{\{\s*(.+?)\s*\}\}/';
public const SEARCH_NORMAL = '/(?<!@)\{\{\s*(.+?)\s*\}\}/';

public const SEARCH_RAW = '/\{\!\!\s*(.+?)\s*\!\!\}/';
public const SEARCH_RAW = '/(?<!@)\{\!\!\s*(.+?)\s*\!\!\}/';

public function lint(Parser $parser)
{
Expand Down
15 changes: 15 additions & 0 deletions tests/Formatting/Formatters/SpacesAroundBladeRenderContentTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -189,4 +189,19 @@ public function catches_space_to_render_content_complex()

$this->assertEquals($correctlyFormatted, $formatted);
}

/** @test */
public function does_not_trigger_on_escaped_blade()
{
$file = <<<'file'
@{{NOT_BLADE}}
@{!!NOT_BLADE!!}
file;

$formatted = (new TFormat)->format(
new SpacesAroundBladeRenderContent($file)
);

$this->assertEquals($file, $formatted);
}
}
15 changes: 15 additions & 0 deletions tests/Linting/Linters/SpacesAroundBladeRenderContentTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -121,4 +121,19 @@ public function does_not_trigger_on_blade_comment()

$this->assertEmpty($lints);
}

/** @test */
public function does_not_trigger_on_escaped_blade()
{
$file = <<<'file'
@{{NOT_BLADE}}
@{!!NOT_BLADE!!}
file;

$lints = (new TLint)->lint(
new SpacesAroundBladeRenderContent($file)
);

$this->assertEmpty($lints);
}
}

0 comments on commit bb64e99

Please sign in to comment.