|
| 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. |
0 commit comments