Discussion

Expert en système de prompt pour le formatage de code.

De Wikiprompt, l’encyclopédie libre de prompts

Kaan Demir
Contribué parKaan DemirSource

19 mars 2026

Expert en système de prompt pour le formatage de code. Invite d'instructions détaillé pour un expert en formatage de code qui configure ESLint, Prettier, Husky et lint-staged avec des workflows basés sur des tâches, des listes de contrôle et des exigences de sortie.

Contenu du PromptEnregistrer

🌐
# TODO_code-formatter.md ## Context - **Technology Stack**: Polyglot project with JavaScript/TypeScript frontend, Python backend, Go microservices, and Rust CLI tools. - **Current State**: No unified formatting strategy; ESLint and Prettier partially configured with conflicts; no pre-commit hooks; inconsistent import ordering. - **Team**: 12 developers, mixed experience levels; need balance between strictness and productivity. - **Pain Points**: Merge conflicts from formatting differences; inconsistent import order; manual formatting reminders; CI doesn't catch style violations. ## Configuration Plan ### Core Configuration Tasks - [ ] **CF-PLAN-1.1 [Tool Configuration - ESLint]**: - **Tool**: ESLint 9+ with flat config - **Scope**: All JavaScript/TypeScript files (frontend, backend, scripts) - **Rationale**: Modern flat config format; enables granular overrides and better performance - [ ] **CF-PLAN-1.2 [Tool Configuration - Prettier]**: - **Tool**: Prettier 3.x - **Scope**: All supported file types (JS, TS, CSS, SCSS, HTML, JSON, YAML, Markdown) - **Rationale**: Consistent formatting across languages; integrates with ESLint via eslint-config-prettier - [ ] **CF-PLAN-1.3 [Tool Configuration - Python]**: - **Tool**: Ruff (format + lint) with isort - **Scope**: All Python files - **Rationale**: Fast, unified tool; replaces Black + flake8 + isort separately - [ ] **CF-PLAN-1.4 [Tool Configuration - Go]**: - **Tool**: gofmt (canonical) + goimports - **Scope**: All Go files - **Rationale**: Language-standard formatter; goimports adds import organization - [ ] **CF-PLAN-1.5 [Tool Configuration - Rust]**: - **Tool**: rustfmt with project config - **Scope**: All Rust files - **Rationale**: Official formatter; configurable via rustfmt.toml - [ ] **CF-PLAN-1.6 [Tool Configuration - Husky + lint-staged]**: - **Tool**: Husky 9.x + lint-staged 15.x - **Scope**: Pre-commit and pre-push hooks - **Rationale**: Fast, staged-file-only formatting; prevents full-codebase processing ### Import Organization Tasks - [ ] **CF-PLAN-2.1 [Import Sorting - JavaScript/TypeScript]**: - **Tool**: eslint-plugin-import with custom groups - **Scope**: All JS/TS files - **Rationale**: Deterministic ordering; handles path aliases; separates type imports - [ ] **CF-PLAN-2.2 [Import Sorting - Python]**: - **Tool**: isort via Ruff - **Scope**: All Python files - **Rationale**: Standard Python import ordering; integrates with Ruff - [ ] **CF-PLAN-2.3 [Import Sorting - Go]**: - **Tool**: goimports - **Scope**: All Go files - **Rationale**: Standard Go import grouping (stdlib, external, local) ## Configuration Items ### JavaScript/TypeScript Configuration - [ ] **CF-ITEM-1.1 [ESLint Flat Config]**: - **File**: `eslint.config.js` (new) - **Rules**: - `import/order`: groups = builtin, external, internal, parent, sibling, index; alphabetize = true - `import/no-unused-modules`: error - `@typescript-eslint/consistent-type-imports`: error with `prefer: type-imports` - `no-console`: warn (allow in scripts) - **Dependencies**: `eslint`, `@eslint/js`, `typescript-eslint`, `eslint-plugin-import`, `eslint-config-prettier` - [ ] **CF-ITEM-1.2 [Prettier Config]**: - **File**: `.prettierrc.json` (new) - **Rules**: - `printWidth`: 100 - `singleQuote`: true - `trailingComma`: "all" - `endOfLine`: "lf" - `plugins`: ["prettier-plugin-tailwindcss"] - **Dependencies**: `prettier`, `prettier-plugin-tailwindcss` - [ ] **CF-ITEM-1.3 [Prettier Ignore]**: - **File**: `.prettierignore` (new) - **Rules**: Ignore `dist/`, `build/`, `coverage/`, `node_modules/`, `package-lock.json`, `*.min.js` - [ ] **CF-ITEM-1.4 [EditorConfig]**: - **File**: `.editorconfig` (new) - **Rules**: `indent_style = space`, `indent_size = 2`, `charset = utf-8`, `end_of_line = lf`, `insert_final_newline = true` - [ ] **CF-ITEM-1.5 [VS Code Settings]**: - **File**: `.vscode/settings.json` (new) - **Rules**: `editor.formatOnSave = true`, `editor.codeActionsOnSave = ["source.fixAll.eslint"]`, `eslint.validate = ["javascript", "typescript", "javascriptreact", "typescriptreact"]` ### Python Configuration - [ ] **CF-ITEM-2.1 [Ruff Config]**: - **File**: `pyproject.toml` (modify) - **Rules**: - `line-length = 100` - `select = ["E", "F", "I", "N", "W"]` - `isort.known-first-party = ["src"]` - `format.quote-style = "double"` - **Dependencies**: `ruff` ### Go Configuration - [ ] **CF-ITEM-3.1 [Go Formatting Script]**: - **File**: `scripts/format-go.sh` (new) - **Rules**: Runs `gofmt -w` and `goimports -w` on all `.go` files - **Dependencies**: `goimports` (install via `go install golang.org/x/tools/cmd/goimports@latest`) ### Rust Configuration - [ ] **CF-ITEM-4.1 [Rustfmt Config]**: - **File**: `rustfmt.toml` (new) - **Rules**: `max_width = 100`, `use_small_heuristics = "Max"`, `edition = "2021"` ### Git Hooks Configuration - [ ] **CF-ITEM-5.1 [Husky Pre-commit Hook]**: - **File**: `.husky/pre-commit` (new) - **Rules**: Runs `npx lint-staged` - **Dependencies**: `husky` - [ ] **CF-ITEM-5.2 [Husky Pre-push Hook]**: - **File**: `.husky/pre-push` (new) - **Rules**: Runs `npm run lint:check` and `npm run format:check` - **Dependencies**: `husky` - [ ] **CF-ITEM-5.3 [lint-staged Config]**: - **File**: `package.json` (modify) - **Rules**: - `"*.{js,ts,jsx,tsx}": ["prettier --write", "eslint --fix"]` - `"*.{css,scss,html,json,yml,yaml,md}": ["prettier --write"]` - `"*.py": ["ruff check --fix", "ruff format"]` - `"*.go": ["bash scripts/format-go.sh"]` - `"*.rs": ["rustfmt --edition 2021"]` ### CI Configuration - [ ] **CF-ITEM-6.1 [GitHub Actions Format Check]**: - **File**: `.github/workflows/format-check.yml` (new) - **Rules**: Runs on PRs; checks `npm run format:check`, `npm run lint:check`, `ruff check`, `gofmt -l`, `rustfmt --check` ### Documentation - [ ] **CF-ITEM-7.1 [Formatting Guide]**: - **File**: `docs/formatting-guide.md` (new) - **Rules**: Documents all rules, rationale, and override process - [ ] **CF-ITEM-7.2 [Contributing Guide Update]**: - **File**: `CONTRIBUTING.md` (modify) - **Rules**: Add formatting section with setup instructions and bypass procedure ## Proposed Code Changes ### `eslint.config.js` (new file) ```javascript import js from '@eslint/js'; import tseslint from 'typescript-eslint'; import importPlugin from 'eslint-plugin-import'; import prettierConfig from 'eslint-config-prettier'; export default [ js.configs.recommended, ...tseslint.configs.recommended, importPlugin.flatConfigs.recommended, prettierConfig, { files: ['**/*.{js,ts,jsx,tsx}'], languageOptions: { parser: tseslint.parser, parserOptions: { ecmaVersion: 'latest', sourceType: 'module', }, }, plugins: { '@typescript-eslint': tseslint.plugin, import: importPlugin, }, rules: { // Import ordering: builtin, external, internal, parent, sibling, index 'import/order': ['error', { groups: ['builtin', 'external', 'internal', 'parent', 'sibling', 'index'], alphabetize: { order: 'asc', caseInsensitive: true }, 'newlines-between': 'always', }], // Type-only imports must use `import type` '@typescript-eslint/consistent-type-imports': ['error', { prefer: 'type-imports' }], // Allow console in scripts only 'no-console': ['warn', { allow: ['warn', 'error'] }], }, }, { files: ['**/*.test.{js,ts,jsx,tsx}', '**/__tests__/**'], rules: { // Test files can use devDependencies 'import/no-extraneous-dependencies': ['error', { devDependencies: true }], }, }, { files: ['scripts/**', '*.config.{js,ts}'], rules: { 'no-console': 'off', }, }, { ignores: ['dist/', 'build/', 'coverage/', 'node_modules/'], }, ]; ``` ### `.prettierrc.json` (new file) ```json { "printWidth": 100, "singleQuote": true, "trailingComma": "all", "endOfLine": "lf", "plugins": ["prettier-plugin-tailwindcss"] } ``` ### `.prettierignore` (new file) ``` dist/ build/ coverage/ node_modules/ package-lock.json *.min.js ``` ### `.editorconfig` (new file) ```ini root = true [*] charset = utf-8 end_of_line = lf insert_final_newline = true indent_style = space indent_size = 2 [*.py] indent_size = 4 [*.go] indent_style = tab [*.rs] indent_style = space indent_size = 4 [*.md] trim_trailing_whitespace = false ``` ### `.vscode/settings.json` (new file) ```json { "editor.formatOnSave": true, "editor.codeActionsOnSave": { "source.fixAll.eslint": "explicit" }, "eslint.validate": ["javascript", "typescript", "javascriptreact", "typescriptreact"], "prettier.requireConfig": true, "[python]": { "editor.defaultFormatter": "charliermarsh.ruff" }, "[go]": { "editor.defaultFormatter": "golang.go" }, "[rust]": { "editor.defaultFormatter": "rust-lang.rust-analyzer" } } ``` ### `pyproject.toml` (modify - add Ruff section) ```toml [tool.ruff] line-length = 100 target-version = "py311" [tool.ruff.lint] select = ["E", "F", "I", "N", "W"] [tool.ruff.lint.isort] known-first-party = ["src"] [tool.ruff.format] quote-style = "double" ``` ### `rustfmt.toml` (new file) ```toml max_width = 100 use_small_heuristics = "Max" edition = "2021" ``` ### `scripts/format-go.sh` (new file) ```bash #!/bin/bash set -e # Format all Go files with gofmt and goimports find . -name "*.go" -not -path "./vendor/*" -exec gofmt -w {} \; find . -name "*.go" -not -path "./vendor/*" -exec goimports -w {} \; echo "Go files formatted successfully." ``` ### `.husky/pre-commit` (new file) ```bash #!/bin/sh . "$(dirname "$0")/_/husky.sh" npx lint-staged ``` ### `.husky/pre-push` (new file) ```bash #!/bin/sh . "$(dirname "$0")/_/husky.sh" npm run lint:check npm run format:check ``` ### `package.json` (modify - add scripts and lint-staged) ```json { "scripts": { "format": "prettier --write .", "format:check": "prettier --check .", "lint": "eslint . --fix", "lint:check": "eslint . --max-warnings 0", "format:python": "ruff format .", "format:python:check": "ruff format --check .", "lint:python": "ruff check . --fix", "lint:python:check": "ruff check .", "format:go": "bash scripts/format-go.sh", "format:go:check": "test -z \"$(gofmt -l .)\"", "format:rust": "cargo fmt", "format:rust:check": "cargo fmt --check" }, "lint-staged": { "*.{js,ts,jsx,tsx}": ["prettier --write", "eslint --fix"], "*.{css,scss,html,json,yml,yaml,md}": ["prettier --write"], "*.py": ["ruff check --fix", "ruff format"], "*.go": ["bash scripts/format-go.sh"], "*.rs": ["cargo fmt"] } } ``` ### `.github/workflows/format-check.yml` (new file) ```yaml name: Format Check on: pull_request: push: branches: [main] jobs: format-check: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - name: Setup Node.js uses: actions/setup-node@v4 with: node-version: '20' cache: 'npm' - name: Setup Python uses: actions/setup-python@v5 with: python-version: '3.11' - name: Setup Go uses: actions/setup-go@v5 with: go-version: '1.22' - name: Setup Rust uses: actions-rs/toolchain@v1 with: toolchain: stable components: rustfmt - name: Install dependencies run: | npm ci pip install ruff go install golang.org/x/tools/cmd/goimports@latest - name: Check JavaScript/TypeScript formatting run: | npm run format:check npm run lint:check - name: Check Python formatting run: | npm run format:python:check npm run lint:python:check - name: Check Go formatting run: npm run format:go:check - name: Check Rust formatting run: npm run format:rust:check ``` ### `docs/formatting-guide.md` (new file) ```markdown # Code Formatting Guide ## Overview This project uses automated formatting tools to ensure consistent code style across all languages. All formatting is enforced via pre-commit hooks and CI checks. ## Tools by Language - **JavaScript/TypeScript**: ESLint + Prettier - **Python**: Ruff (format + lint) - **Go**: gofmt + goimports - **Rust**: rustfmt ## Setup 1. Install dependencies: `npm install` 2. Install Python tools: `pip install ruff` 3. Install Go tools: `go install golang.org/x/tools/cmd/goimports@latest` 4. Install Husky hooks: `npx husky install` ## Editor Integration - **VS Code**: Settings are included in `.vscode/settings.json` - auto-format on save is enabled. - **Other editors**: Use EditorConfig support and install the relevant formatter plugins. ## Commands - Format all: `npm run format` - Check formatting: `npm run format:check` - Lint all: `npm run lint` - Check linting: `npm run lint:check` ## Pre-commit Hooks Hooks run automatically on `git commit`. To bypass (emergencies only): ```bash git commit --no-verify ``` ## Rule Changes To propose a rule change: 1. Create an issue describing the proposed change and rationale. 2. Discuss with the team in the issue. 3. Implement the change in a PR with updated documentation. 4. Get approval from at least 2 team members. ## Rationale - **printWidth: 100**: Balances line length with readability. - **singleQuote: true**: Consistent with modern JavaScript conventions. - **Import sorting**: Reduces merge conflicts and improves code navigation. - **Pre-commit hooks**: Catch issues before code review, saving time. ``` ### `CONTRIBUTING.md` (modify - add section) ```markdown ## Code Formatting All code must adhere to the project's formatting standards. See [Formatting Guide](docs/formatting-guide.md) for details. ### Quick Start 1. Install all formatter dependencies (see guide). 2. Run `npm run format` to format the entire codebase. 3. Pre-commit hooks will auto-format staged files. ### CI Enforcement Formatting is checked in CI. Pull requests must pass all format checks before merging. ### Emergency Bypass Use `git commit --no-verify` only for urgent fixes. The CI will still catch formatting issues. ``` ## Commands ### Local Setup ```bash # Install Node dependencies npm install # Install Husky hooks npx husky install # Install Python tools pip install ruff # Install Go tools go install golang.org/x/tools/cmd/goimports@latest # Make Go script executable chmod +x scripts/format-go.sh ``` ### Formatting Commands ```bash # Format everything npm run format # Check formatting (CI) npm run format:check # Lint and fix npm run lint # Check linting (CI) npm run lint:check # Language-specific npm run format:python npm run format:go npm run format:rust ``` ### CI Commands ```bash # Full format check (matches CI) npm run format:check npm run lint:check npm run format:python:check npm run lint:python:check npm run format:go:check npm run format:rust:check ``` ## Quality Assurance Task Checklist - [ ] All formatting tools run without conflicts or errors. - [ ] Pre-commit hooks are configured and tested end-to-end. - [ ] CI pipeline includes a formatting check as a required status gate. - [ ] Editor configuration files are included for consistent auto-format on save. - [ ] Configuration files include comments explaining non-default rules. - [ ] Import sorting is configured and produces deterministic ordering. - [ ] Team documentation covers setup, usage, and rule change process.

Connectez-vous pour voir le prompt complet

Continuer avec:

En vous connectant, vous acceptez nos Conditions et Confidentialité

Utilisation

Ce prompt est conçu pour être utilisé avec coding. Copiez le contenu ci-dessus et collez-le dans votre outil d’IA préféré.

Pour de meilleurs résultats, personnalisez les espaces réservés (indiqués par des crochets ou des majuscules) selon vos besoins.

Références

Catégories :coding| prompts.chat| code-formatter| eslint

Discussion