Skip to content

Commit e1e6072

Browse files
committed
add linting to test command to pick up on invalid generated files
1 parent 1016a5d commit e1e6072

File tree

4 files changed

+31
-11
lines changed

4 files changed

+31
-11
lines changed

.eslintrc.json

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{
2+
"env": {
3+
"es2022": true,
4+
"node": true
5+
},
6+
"extends": ["eslint:recommended", "plugin:@typescript-eslint/recommended"],
7+
"parser": "@typescript-eslint/parser",
8+
"parserOptions": {
9+
"ecmaVersion": "latest",
10+
"sourceType": "module"
11+
},
12+
"plugins": ["@typescript-eslint", "import"],
13+
"rules": {
14+
"import/no-duplicates": "error"
15+
}
16+
}

package.json

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,17 @@
11
{
22
"type": "module",
33
"scripts": {
4-
"test": "vitest run && npm run test-routes-cached",
5-
"test-routes-cached": "WAYFINDER_CACHE_ROUTES=1 vitest run"
4+
"test": "vitest run && npm run lint && npm run test-routes-cached && npm run lint",
5+
"test-routes-cached": "WAYFINDER_CACHE_ROUTES=1 vitest run",
6+
"lint": "eslint ./workbench/resources/js --ext .ts,.tsx",
7+
"lint:fix": "eslint ./workbench/resources/js --ext .ts,.tsx --fix"
68
},
79
"devDependencies": {
810
"@types/node": "^22.7.5",
11+
"@typescript-eslint/eslint-plugin": "^7.0.0",
12+
"@typescript-eslint/parser": "^7.0.0",
13+
"eslint": "^8.56.0",
14+
"eslint-plugin-import": "^2.29.1",
915
"happy-dom": "^15.11.7",
1016
"vitest": "^2.1.3"
1117
}

src/GenerateCommand.php

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ private function writeContent(): void
126126

127127
// Prepend the imports to the file
128128
if (isset($this->imports[$path])) {
129-
$importLines = collect($this->imports[$path])->map(fn ($imports, $key) => "import { ".implode(', ', array_unique($imports))." } from '{$key}'")->implode(PHP_EOL);
129+
$importLines = collect($this->imports[$path])->map(fn ($imports, $key) => 'import { '.implode(', ', array_unique($imports))." } from '{$key}'")->implode(PHP_EOL);
130130
$this->files->prepend($path, $importLines.PHP_EOL);
131131
}
132132
}
@@ -229,14 +229,12 @@ private function appendCommonImports(Collection $routes, string $path, string $n
229229
}
230230

231231
$importBase = str_repeat('/..', substr_count($namespace, '.') + 1);
232+
$pathKey = ".{$importBase}/wayfinder";
232233

233-
if (!isset($this->imports[$path])) {
234-
$this->imports[$path] = [];
235-
}
236-
237-
$this->imports[$path][".{$importBase}/wayfinder"] = [
238-
...($this->imports[$path][".{$importBase}/wayfinder"] ?? []),
239-
...$imports
234+
$this->imports[$path] ??= [];
235+
$this->imports[$path][$pathKey] = [
236+
...($this->imports[$path][$pathKey] ?? []),
237+
...$imports,
240238
];
241239
}
242240

workbench/routes/web.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
return 'Home';
4242
})->name('home');
4343

44-
Route::post('/optional/{parameter?}', [OptionalController::class, 'optional']);
44+
Route::post('/optional/{parameter?}', [OptionalController::class, 'optional'])->name('optional');
4545
Route::post('/many-optional/{one?}/{two?}/{three?}', [OptionalController::class, 'manyOptional']);
4646

4747
Route::post('/users/{user}', [ModelBindingController::class, 'show']);

0 commit comments

Comments
 (0)