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

Migrate lint setup to duster #697

Open
wants to merge 3 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
17 changes: 17 additions & 0 deletions .github/workflows/duster-lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
name: Duster Lint

on:
push:
branches: [ main ]
pull_request:

jobs:
duster:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- name: "Duster Lint"
uses: tighten/duster-action@v2
with:
args: lint
34 changes: 0 additions & 34 deletions .github/workflows/format.yml

This file was deleted.

50 changes: 0 additions & 50 deletions .php-cs-fixer.php

This file was deleted.

14 changes: 10 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
{
"name": "tightenco/jigsaw",
"description": "Simple static sites with Laravel's Blade.",
"keywords": ["blade", "laravel", "static", "site", "generator"],
"keywords": [
"blade",
"laravel",
"static",
"site",
"generator"
],
"license": "MIT",
"authors": [
{
Expand Down Expand Up @@ -39,9 +45,9 @@
"vlucas/phpdotenv": "^5.3.1"
},
"require-dev": {
"friendsofphp/php-cs-fixer": "^3.17",
"mockery/mockery": "^1.4",
"phpunit/phpunit": "^9.3.3"
"phpunit/phpunit": "^9.3.3",
"tightenco/duster": "^2.5"
},
"autoload": {
"psr-4": {
Expand All @@ -60,7 +66,7 @@
"jigsaw"
],
"scripts": {
"format" : "php-cs-fixer fix --verbose"
"format": "./vendor/bin/duster fix"
},
"config": {
"sort-packages": true,
Expand Down
3 changes: 3 additions & 0 deletions duster.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"exclude": ["tests/snapshots", "src/**/helpers.php"]
}
10 changes: 5 additions & 5 deletions src/Bootstrap/HandleExceptions.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,11 @@ public function bootstrap(Container $app): void
/**
* Report PHP deprecations, or convert PHP errors to ErrorException instances.
*
* @param int $level
* @param string $message
* @param string $file
* @param int $line
* @param array $context
* @param int $level
* @param string $message
* @param string $file
* @param int $line
* @param array $context
*
* @throws ErrorException
*/
Expand Down
2 changes: 1 addition & 1 deletion src/Collection/Collection.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class Collection extends BaseCollection

public static function withSettings(IterableObject $settings, $name)
{
$collection = new static();
$collection = new static;
$collection->settings = $settings;
$collection->name = $name;

Expand Down
8 changes: 4 additions & 4 deletions src/Collection/CollectionItem.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,13 +58,13 @@ public function getContent()
$this->_content;
}

public function __toString()
protected function missingHelperError($functionName)
{
return (string) $this->getContent();
return 'No function named "' . $functionName . '" for the collection "' . $this->_meta->collectionName . '" was found in the file "config.php".';
}

protected function missingHelperError($functionName)
public function __toString()
{
return 'No function named "' . $functionName . '" for the collection "' . $this->_meta->collectionName . '" was found in the file "config.php".';
return (string) $this->getContent();
}
}
2 changes: 1 addition & 1 deletion src/CollectionItemHandlers/BladeCollectionItemHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,6 @@ public function getItemVariables($file)

public function getItemContent($file)
{
return;

}
}
2 changes: 1 addition & 1 deletion src/Console/BuildCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ protected function fire()
$cacheExists = $this->app[TemporaryFilesystem::class]->hasTempDirectory();

if ($this->input->getOption('pretty') === 'true' && $this->app->config->get('pretty') !== false) {
$this->app->instance('outputPathResolver', new PrettyOutputPathResolver());
$this->app->instance('outputPathResolver', new PrettyOutputPathResolver);
}

if ($this->input->getOption('quiet')) {
Expand Down
62 changes: 31 additions & 31 deletions src/Console/ConsoleOutput.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,37 +16,6 @@ public function setup($verbosity)
$this->setupProgressBars();
}

protected function setupSections()
{
$this->sections = collect([
'footer' => $this->section(),
'intro' => $this->section(),
'message' => $this->section(),
'progress' => $this->section(),
'header' => $this->section(),
])->map(function ($section) {
return $this->section();
});

$this->sections['header']->writeln('');
$this->sections['footer']->writeln('');
}

protected function setupProgressBars()
{
$this->progressBars = [
'collections' => $this->getProgressBar('Loading collections...'),
'build' => $this->getProgressBar('Building files from source...'),
];
}

protected function getProgressBar($message = null)
{
return $this->isVerbose() ?
new ProgressBar($this, $message, $this->sections['progress']) :
new NullProgressBar($this, $message, $this->sections['progress']);
}

public function progressBar($name)
{
return $this->progressBars[$name];
Expand Down Expand Up @@ -123,4 +92,35 @@ public function writeConclusion()

return $this;
}

protected function setupSections()
{
$this->sections = collect([
'footer' => $this->section(),
'intro' => $this->section(),
'message' => $this->section(),
'progress' => $this->section(),
'header' => $this->section(),
])->map(function ($section) {
return $this->section();
});

$this->sections['header']->writeln('');
$this->sections['footer']->writeln('');
}

protected function setupProgressBars()
{
$this->progressBars = [
'collections' => $this->getProgressBar('Loading collections...'),
'build' => $this->getProgressBar('Building files from source...'),
];
}

protected function getProgressBar($message = null)
{
return $this->isVerbose() ?
new ProgressBar($this, $message, $this->sections['progress']) :
new NullProgressBar($this, $message, $this->sections['progress']);
}
}
4 changes: 2 additions & 2 deletions src/Container.php
Original file line number Diff line number Diff line change
Expand Up @@ -139,15 +139,15 @@ private function boot(): void
$this->fireAppCallbacks($this->bootedCallbacks);
}

/** @param callable[] $callbacks */
/** @param callable[] $callbacks */
private function fireAppCallbacks(array &$callbacks): void
{
$index = 0;

while ($index < count($callbacks)) {
$callbacks[$index]($this);

++$index;
$index++;
}
}

Expand Down
16 changes: 8 additions & 8 deletions src/Events/EventBus.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,21 +28,21 @@ public function __construct()
$this->afterBuild = collect();
}

public function __call($event, $arguments)
{
if (isset($this->{$event})) {
$this->{$event} = $this->{$event}->merge(Arr::wrap($arguments[0]));
}
}

public function fire($event, Jigsaw $jigsaw)
{
$this->{$event}->each(function ($task) use ($jigsaw) {
if (is_callable($task)) {
$task($jigsaw);
} else {
(new $task())->handle($jigsaw);
(new $task)->handle($jigsaw);
}
});
}

public function __call($event, $arguments)
{
if (isset($this->{$event})) {
$this->{$event} = $this->{$event}->merge(Arr::wrap($arguments[0]));
}
}
}
4 changes: 2 additions & 2 deletions src/Exceptions/Handler.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public function render($request, Throwable $e): void
}

/**
* @param \Symfony\Component\Console\Output\OutputInterface $output
* @param \Symfony\Component\Console\Output\OutputInterface $output
*/
public function renderForConsole($output, Throwable $e): void
{
Expand Down Expand Up @@ -88,7 +88,7 @@ public function renderForConsole($output, Throwable $e): void
$handler->handle();
}

public function map(Closure|string $from, Closure|string|null $to = null): static
public function map(Closure|string $from, Closure|string $to = null): static
{
if (is_string($to)) {
$to = fn ($exception) => new $to('', 0, $exception);
Expand Down
2 changes: 1 addition & 1 deletion src/File/TemporaryFilesystem.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class TemporaryFilesystem
public function __construct($tempPath, $filesystem = null)
{
$this->tempPath = $tempPath;
$this->filesystem = $filesystem ?: new Filesystem();
$this->filesystem = $filesystem ?: new Filesystem;
}

public function buildTempPath($filename, $extension)
Expand Down
34 changes: 17 additions & 17 deletions src/Handlers/CollectionItemHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,23 +24,6 @@ public function shouldHandle($file)
&& ! Str::startsWith($file->getFilename(), ['.', '_']);
}

private function isInCollectionDirectory($file)
{
$base = $file->topLevelDirectory();

return Str::startsWith($base, '_') && $this->hasCollectionNamed($this->getCollectionName($file));
}

private function hasCollectionNamed($candidate)
{
return Arr::get($this->config, 'collections.' . $candidate) !== null;
}

private function getCollectionName($file)
{
return substr($file->topLevelDirectory(), 1);
}

public function handle($file, $pageData)
{
$handler = $this->handlers->first(function ($handler) use ($file) {
Expand Down Expand Up @@ -70,4 +53,21 @@ public function handle($file, $pageData)
) : null;
})->filter()->values();
}

private function isInCollectionDirectory($file)
{
$base = $file->topLevelDirectory();

return Str::startsWith($base, '_') && $this->hasCollectionNamed($this->getCollectionName($file));
}

private function hasCollectionNamed($candidate)
{
return Arr::get($this->config, 'collections.' . $candidate) !== null;
}

private function getCollectionName($file)
{
return substr($file->topLevelDirectory(), 1);
}
}
Loading
Loading