-
Notifications
You must be signed in to change notification settings - Fork 170
[1.x] Adds blade
support
#256
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
Draft
nunomaduro
wants to merge
66
commits into
main
Choose a base branch
from
feat/blade
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from 5 commits
Commits
Show all changes
66 commits
Select commit
Hold shift + click to select a range
89c97cb
Adds blade support
nunomaduro a542c13
Improves error handling
nunomaduro fd39d90
Rebuilds
nunomaduro 3b45cb5
Deletes version file
nunomaduro 4b2c343
Ignores version file
nunomaduro 741f377
Update app/Fixers/LaravelBladeFixer.php
nunomaduro 4ee92d9
Update resources/presets/laravel.php
nunomaduro 9458bc7
Rebuilds
nunomaduro 25160ce
Validates with node and npm are installed
nunomaduro c22d555
Rebuilds
nunomaduro e9fce59
Changes underlying prettier plugins
nunomaduro ece1d68
Changes version
nunomaduro 8b547fc
Rebuilds
nunomaduro dce1b6b
Merge pull request #258 from laravel/feat/prettier-plugin
nunomaduro fb4061e
Improves error handling
nunomaduro ac1dbb7
Rebuilds
nunomaduro dbde266
Merge pull request #259 from laravel/feat/prettier-plugin
nunomaduro 8a6aba7
chore: bumps dependencies
nunomaduro 4e19273
Updates prettier plugin blade version
nunomaduro d191f53
Rebuilds
nunomaduro b94e796
Fix tests for the laravel skeleton
Jubeki e68acf4
Fix static analysis
Jubeki eaff017
Fix static analysis
Jubeki 6c66735
Fix failing tests
Jubeki 7ec420d
Merge pull request #260 from Jubeki/fix-tests
nunomaduro 8615608
Uses Pint to format code within blade tags
nunomaduro 647ed31
wip
nunomaduro d3bd5e4
wip
nunomaduro 32f42e5
Uses prettier as worker mode
nunomaduro 59ace97
Uses `"printWidth": 120`
nunomaduro b74f3e8
Resolves `LaravelBladeFixer` from IOC
nunomaduro ea25d2e
Rebuilds
nunomaduro 85ad368
Properly ensures the process is terminated
nunomaduro 1ad5058
Rebuilds
nunomaduro d23f749
Bumps `prettier-plugin-blade`
nunomaduro 6173045
Fixes worker getting confused
nunomaduro 04a2add
Rebuilds
nunomaduro 7558542
Refactors ignorables
nunomaduro 3b64ce8
Rebuilds
nunomaduro 2618dac
Fixes single line attributes
nunomaduro 54bc0ff
Rebuilds
nunomaduro 1511a37
Adds `--blade` option
nunomaduro 42ee061
Rebuilds
nunomaduro 8c4ce67
Keeps improving linting of blade files
nunomaduro 83e50c5
Rebuilds
nunomaduro be09e72
Fixes configuration
nunomaduro cc01378
Rebuilds
nunomaduro 61cb222
Adjust wrapping
nunomaduro 2f093ca
Rebuilds
nunomaduro ba86429
Adjusts style
nunomaduro 5a889e3
Rebuilds
nunomaduro 7e97525
Ignores cache for now
nunomaduro b325827
150 printWidth
nunomaduro 33bbf45
Rebuilds
nunomaduro 4d3e126
Puts SVGs in the same line
nunomaduro 3148bcc
Coding style
nunomaduro f3371d2
Ignores minified code
nunomaduro 58e661c
Refactors code
nunomaduro 4a086d3
Rebuilds
nunomaduro d06e89d
Style
nunomaduro d11cbbd
inline paragrahps
nunomaduro e775568
Merge branch 'main' into feat/blade
nunomaduro f80b15e
Rebuils
nunomaduro 50229c4
Rebuilds
nunomaduro 587cb48
bumps dependencies
nunomaduro 3da5103
Rebuilds
nunomaduro File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<?php | ||
|
||
namespace App\Exceptions; | ||
|
||
use Exception; | ||
|
||
class PrettierException extends Exception | ||
{ | ||
// | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
<?php | ||
|
||
namespace App\Fixers; | ||
|
||
use App\Exceptions\PrettierException; | ||
use App\Prettier; | ||
use PhpCsFixer\AbstractFixer; | ||
use PhpCsFixer\Fixer\ConfigurableFixerInterface; | ||
use PhpCsFixer\FixerConfiguration\FixerConfigurationResolver; | ||
use PhpCsFixer\FixerConfiguration\FixerConfigurationResolverInterface; | ||
use PhpCsFixer\FixerConfiguration\FixerOptionBuilder; | ||
use PhpCsFixer\FixerDefinition\FixerDefinition; | ||
use PhpCsFixer\FixerDefinition\FixerDefinitionInterface; | ||
use PhpCsFixer\Tokenizer\Tokens; | ||
use SplFileInfo; | ||
|
||
class LaravelBladeFixer extends AbstractFixer implements ConfigurableFixerInterface | ||
{ | ||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function getName(): string | ||
{ | ||
return 'Pint/laravel_blade'; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function isCandidate(Tokens $tokens): bool | ||
{ | ||
return true; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function getDefinition(): FixerDefinitionInterface | ||
{ | ||
return new FixerDefinition('Fixes Laravel Blade files.', []); | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function getPriority(): int | ||
{ | ||
return -2; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
protected function applyFix(SplFileInfo $file, Tokens $tokens): void | ||
{ | ||
$path = $file->getRealPath(); | ||
|
||
if (! str_ends_with($path, '.blade.php')) { | ||
return; | ||
} | ||
|
||
$content = $tokens->generateCode(); | ||
|
||
if (str_contains($content, '<x-mail::') || str_contains($content, '@component(\'mail::')) { | ||
return; | ||
} | ||
|
||
/** @var \Illuminate\Process\ProcessResult $result */ | ||
$result = app(Prettier::class)->run([$path, ...$this->mapConfigurationToCliOptions()]); | ||
|
||
if ($result->failed()) { | ||
throw new PrettierException($result->errorOutput()); | ||
} | ||
|
||
$tokens->setCode($result->output()); | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
protected function createConfigurationDefinition(): FixerConfigurationResolverInterface | ||
{ | ||
return new FixerConfigurationResolver([ | ||
(new FixerOptionBuilder('sortTailwindcssClasses', 'Sort tailwindcss classes.')) | ||
->setAllowedTypes(['bool']) | ||
->setDefault(true) | ||
->getOption(), | ||
(new FixerOptionBuilder('sortHtmlAttributes', 'Sort html attributes.')) | ||
->setAllowedTypes(['string']) | ||
->setDefault('none') | ||
->getOption(), | ||
]); | ||
} | ||
|
||
/** | ||
* Maps the configuration to CLI options. | ||
* | ||
* @return array<string, string> | ||
*/ | ||
protected function mapConfigurationToCliOptions(): array | ||
{ | ||
$configuration = $this->configuration; | ||
|
||
return array_values(array_filter([ | ||
$configuration['sortTailwindcssClasses'] | ||
? '--sort-tailwindcss-classes=true' | ||
: '--sort-tailwindcss-classes=false', | ||
'--sort-html-attributes', | ||
$configuration['sortHtmlAttributes'], | ||
])); | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
<?php | ||
|
||
namespace App; | ||
|
||
use Illuminate\Support\Facades\File; | ||
use Illuminate\Support\Facades\Process; | ||
|
||
class NodeSandbox | ||
{ | ||
/** | ||
* The version of the sandbox. | ||
* | ||
* @var string | ||
*/ | ||
const VERSION = '1'; | ||
|
||
/** | ||
* The path to the sandbox. | ||
* | ||
* @var string | ||
*/ | ||
protected $path; | ||
|
||
/** | ||
* Indicates if the sandbox is initialized. | ||
* | ||
* @var bool | ||
*/ | ||
protected $initialized = false; | ||
|
||
/** | ||
* Creates a new node sandbox instance. | ||
* | ||
* @param string | ||
* @return void | ||
*/ | ||
public function __construct($path) | ||
{ | ||
$this->path = $path; | ||
} | ||
|
||
/** | ||
* Ensures the sandbox is initialized. | ||
* | ||
* @return void | ||
*/ | ||
public function ensureInitialized() | ||
{ | ||
if ($this->initialized) { | ||
return; | ||
} | ||
|
||
if (! File::exists($this->path.'/version') || File::get($this->path.'/version') !== static::VERSION) { | ||
File::deleteDirectory($this->path.'/node_modules'); | ||
File::delete($this->path.'/package-lock.json'); | ||
|
||
$this->installNodeDependencies(); | ||
|
||
File::put($this->path.'/version', static::VERSION); | ||
} | ||
} | ||
|
||
/** | ||
* The sandbox path. | ||
* | ||
* @return string | ||
*/ | ||
public function path() | ||
{ | ||
return $this->path; | ||
} | ||
|
||
/** | ||
* Run the given commands. | ||
* | ||
* @param array<int, string> | ||
* @return \Illuminate\Process\ProcessResult | ||
*/ | ||
public function run($commands) | ||
{ | ||
$this->ensureInitialized(); | ||
|
||
$process = Process::command(implode(' ', $commands)) | ||
->path($this->path); | ||
|
||
return $process->run(); | ||
} | ||
|
||
/** | ||
* Install the node dependencies. | ||
* | ||
* @return void | ||
*/ | ||
private function installNodeDependencies() | ||
{ | ||
$commands = [ | ||
'npm install', | ||
]; | ||
|
||
$result = Process::command(implode(' && ', $commands)) | ||
->path($this->path) | ||
->run(); | ||
|
||
if ($result->failed()) { | ||
$reason = $result->output(); | ||
|
||
abort(1, sprintf('Pint was unable to install its node dependencies. Reason: %s', $reason)); | ||
} | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
<?php | ||
|
||
namespace App; | ||
|
||
class Prettier | ||
{ | ||
/** | ||
* The node sandbox instance. | ||
* | ||
* @var \App\NodeSandbox | ||
*/ | ||
protected $sandbox; | ||
|
||
/** | ||
* The node sandbox instance. | ||
* | ||
* @param \App\NodeSandbox | ||
* @return void | ||
*/ | ||
public function __construct($sandbox) | ||
{ | ||
$this->sandbox = $sandbox; | ||
} | ||
|
||
/** | ||
* Run the prettier command. | ||
* | ||
* @param array<int, string> | ||
* @return \Illuminate\Process\ProcessResult | ||
*/ | ||
public function run($params = []) | ||
{ | ||
return $this->sandbox->run([ | ||
'./node_modules/.bin/prettier', | ||
'--config', | ||
$this->sandbox->path().'/'.'.prettierrc', | ||
...$params, | ||
]); | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.