Skip to content

Commit a67313d

Browse files
committed
Add remaining, fix husky & pint failure.
1 parent caae346 commit a67313d

4 files changed

Lines changed: 135 additions & 1 deletion

File tree

.husky/pre-commit

100644100755
File mode changed.

CI.md

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,19 @@ Continuous Integration runs on every push to `main` and on all pull requests. It
6666

6767
---
6868

69+
## VS Code Integration & Auto-Formatting
70+
71+
This repository is pre-configured with workspace settings to ensure a seamless developer experience.
72+
73+
When opening this project in VS Code, you will be prompted to install the recommended extensions (ESLint, Prettier, Laravel Pint). Once installed, the workspace `.vscode/settings.json` enforces **Format on Save** and **Auto-Fix on Save** globally:
74+
75+
- **React/JS/CSS:** Handled automatically by Prettier & ESLint.
76+
- **PHP:** Handled automatically by Laravel Pint.
77+
78+
You should rarely, if ever, have formatting issues block a commit if these extensions are active.
79+
80+
---
81+
6982
## Available Scripts
7083

7184
### Frontend (React / Vite)
@@ -81,7 +94,8 @@ pnpm format:check # Check if JS/CSS files are formatted
8194

8295
php artisan serve # Start the PHP development server
8396
php artisan test # Run backend test suite
84-
./vendor/bin/pint # Run Laravel Pint to format all PHP files
97+
pnpm format:php # Format all PHP files using Laravel Pint
98+
./vendor/bin/pint # Direct access to Laravel Pint binary
8599

86100
---
87101

@@ -116,6 +130,14 @@ When cloning the repository for the first time, run these commands to set up the
116130
If Husky didn't initialize properly upon cloning, manually wire it up:
117131
pnpm exec husky init
118132

133+
### Husky failing silently (Code 1) on Windows:
134+
135+
If Git Bash crashes instantly when trying to commit, it is likely the Windows CRLF bug.
136+
137+
1. Open `.husky/pre-commit` in VS Code.
138+
2. Look at the bottom right corner of the window. Change **CRLF** to **LF**.
139+
3. Save the file and try your commit again.
140+
119141
### VS Code commit button failing:
120142

121143
If the visual Git UI in VS Code fails silently, it is likely due to missing environment variables for `pnpm`. Use the terminal instead:

LINTING.md

Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
# Linting and Formatting Setup (SIST)
2+
3+
This project is configured with ESLint, Prettier, and Laravel Pint, following industry-standard best practices for modern full-stack Laravel + React (Inertia.js) development.
4+
5+
Because SIST combines a PHP backend with a React frontend in the same repository, our linting strategy is strictly separated by file type to ensure tools do not conflict.
6+
7+
## Configuration Files
8+
9+
- **.prettierrc** - Prettier configuration for JavaScript, React (JSX), and CSS formatting.
10+
- **.prettierignore** - Protects compiled assets and Laravel backend files from Prettier.
11+
- **eslint.config.js** - Modern ESLint "Flat Config" handling React 18, JSX, and global variables.
12+
- **pint.json** _(Optional)_ - Laravel Pint configuration (uses Laravel defaults if missing).
13+
14+
## Available Scripts
15+
16+
### React / Frontend
17+
18+
- **pnpm lint** - Check for linting errors in resources/js/
19+
- **pnpm lint:fix** - Fix auto-fixable linting errors
20+
- **pnpm format** - Format all JS/CSS files with Prettier
21+
- **pnpm format:check** - Check if JS/CSS files are formatted correctly
22+
23+
### Laravel / Backend
24+
25+
- **pnpm format:php** - Format all PHP files using Laravel Pint
26+
- **./vendor/bin/pint --test** - Check if PHP files are formatted correctly (used in CI)
27+
28+
## Key Features
29+
30+
### Prettier Settings (Frontend)
31+
32+
- **Semi-colons**: Enabled (true)
33+
- **Single quotes**: Enabled (true) for JS/JSX
34+
- **Print width**: 100 characters (optimal for modern wide screens)
35+
- **Tab width**: 4 spaces (aligns with standard Laravel formatting)
36+
- **Trailing commas**: ES5 compatible
37+
38+
### ESLint Rules (Frontend)
39+
40+
**React/JSX:**
41+
42+
- Uses the official eslint-plugin-react Flat Config.
43+
- **No React import needed**: react/react-in-jsx-scope is disabled for React 17+.
44+
- **Prop Types**: react/prop-types is disabled (we rely on clear component structures).
45+
- **Apostrophes**: react/no-unescaped-entities is disabled to allow natural text writing.
46+
47+
**Code Quality & Laravel Compatibility:**
48+
49+
- **Ziggy Routes**: `route` is defined as a readonly global variable, preventing ESLint from throwing errors when using Laravel's route() helper in React.
50+
- **Strict Ignores**: Completely ignores vendor/, storage/, public/, and bootstrap/cache/ to prevent scanning backend files.
51+
- Warns on console.log (allows console.warn, console.info, and console.error).
52+
53+
### Laravel Pint (Backend)
54+
55+
- Built on top of PHP-CS-Fixer.
56+
- Enforces the official Laravel coding style across all Models, Controllers, and Configurations.
57+
- Automatically removes unused imports and fixes array syntax.
58+
59+
## VS Code Integration (Recommended)
60+
61+
This repository is pre-configured for VS Code. When you open the project, it will recommend the necessary extensions. For the best development experience, ensure these are installed:
62+
63+
1. **ESLint** (dbaeumer.vscode-eslint)
64+
2. **Prettier** (esbenp.prettier-vscode)
65+
3. **Laravel Pint** (open-southeners.laravel-pint)
66+
67+
The workspace .vscode/settings.json is already configured to format on save:
68+
69+
{
70+
"editor.formatOnSave": true,
71+
"editor.defaultFormatter": "esbenp.prettier-vscode",
72+
"editor.codeActionsOnSave": {
73+
"source.fixAll.eslint": "explicit"
74+
},
75+
"[php]": {
76+
"editor.defaultFormatter": "open-southeners.laravel-pint"
77+
}
78+
}
79+
80+
## Pre-commit Hook (Already Configured)
81+
82+
This project uses Husky and lint-staged to guarantee code quality before every commit. You do not need to install this manually; it runs automatically after pnpm install.
83+
84+
**How it works (from package.json):**
85+
"lint-staged": {
86+
"resources/**/\*.{js,jsx,ts,tsx}": [
87+
"eslint --fix",
88+
"prettier --write"
89+
],
90+
"resources/**/_.{css,scss}": [
91+
"prettier --write"
92+
],
93+
"\*\*/_.php": [
94+
"./vendor/bin/pint"
95+
]
96+
}
97+
98+
## Best Practices
99+
100+
1. **Trust the automation**: Let your editor format on save. It saves time and prevents CI failures.
101+
2. **Review auto-fixes**: While lint:fix is helpful, always double-check staged changes before pushing.
102+
3. **Commit via Terminal if UI fails**: On Windows, the VS Code commit button can sometimes fail to trigger Husky due to path issues. If this happens, use `git commit -m "message"` in the terminal.
103+
104+
## Laravel / Inertia Specifics
105+
106+
When building React components for SIST:
107+
108+
- **Routing**: Use the global route('route.name') helper. ESLint is configured to recognize it.
109+
- **Props**: Data passed from Laravel Controllers arrives as standard React props.
110+
- **No API Calls Needed**: Because we use Inertia.js, you generally do not need axios or fetch to get page data; Laravel injects it directly into your page components.

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@
3939
"lint:fix": "eslint resources/js --fix",
4040
"format": "prettier --write \"resources/**/*.{js,jsx,ts,tsx,css}\"",
4141
"format:check": "prettier --check \"resources/**/*.{js,jsx,ts,tsx,css}\"",
42+
"format:php": "./vendor/bin/pint",
43+
"format:php:test": "./vendor/bin/pint --test",
4244
"prepare": "husky"
4345
},
4446
"dependencies": {

0 commit comments

Comments
 (0)