# AI Rule: Code Quality Standards Enforces ESLint, Prettier, and coding best practices for consistent, maintainable code. **Execution rule:** Do not use `node -e` for any file or config edits. Use `replace_in_file` or `write_to_file` only (see **webapp-no-node-e.md**). ## Targets - `force-app/main/default/webapplications/*/**/*` - `**/*.{js,ts,jsx,tsx,json,md}` ## MANDATORY Checks **Before completing code** (run from the web app directory `force-app/main/default/webapplications//`): ```bash npm run lint # MUST result in: 0 errors (0 warnings preferred) npm run build # MUST succeed (includes TypeScript check) ``` If your project adds Prettier, use a consistent config (e.g. `.prettierrc` with `semi`, `singleQuote`, `printWidth`, etc.) and run format checks before completing. ## Lint / Fix ```bash npm run lint # Run ESLint (always available in the template web app) # Use your editor's format-on-save or add npm scripts for Prettier if desired ``` ## Import Order (MANDATORY) ```typescript // 1. React ecosystem import { useState, useEffect } from 'react'; // 2. External libraries (alphabetical) import clsx from 'clsx'; // 3. UI components (alphabetical) import { Button } from '@/components/ui/button'; import { Card } from '@/components/ui/card'; // 4. Internal utilities (alphabetical) import { useAuth } from '../hooks/useAuth'; import { formatDate } from '../utils/dateUtils'; // 5. Relative imports import { ComponentA } from './ComponentA'; // 6. Type imports (separate, at end) import type { User, ApiResponse } from '../types'; ``` ## Naming Conventions ```typescript // PascalCase: Components, classes const UserProfile = () => {}; const ApiClient = class {}; // camelCase: Variables, functions, properties const userName = 'john'; const fetchUserData = async () => {}; // SCREAMING_SNAKE_CASE: Constants const API_BASE_URL = 'https://api.example.com'; // kebab-case: Files // user-profile.tsx, api-client.ts ``` ## React Component Structure ```typescript interface ComponentProps { // Props interface first } const Component: React.FC = ({ prop1, prop2 }) => { // 1. Hooks // 2. Computed values // 3. Event handlers // 4. JSX return return
; }; export default Component; ``` ## JSX Standards ```typescript // Self-closing tags