[GH-ISSUE #5311] [Feature]: Introduce a code formatter for frontend #3722

Open
opened 2026-10-31 20:34:29 +07:00 by bsakaguchi · 1 comment
Owner

Originally created by @NikanZeyaei on GitHub (Jun 14, 2026).
Original GitHub issue: https://github.com/MHSanaei/3x-ui/issues/5311

The frontend/ package currently enforces code quality through ESLint, but it has no automatic formatter. As a result, style decisions such as quote style, trailing commas, line length, and import wrapping are left to individual contributors. This creates inconsistent formatting across the codebase, noisy diffs in PRs, and unnecessary review rounds purely over style.

Describe the solution you'd like

Add a dedicated formatter to frontend/ and wire it into the existing development workflow.

  1. Tool choice: Add Prettier as a dev dependency. It is the de-facto standard in the React/TypeScript/Vite ecosystem and integrates cleanly with the existing ESLint flat config.
  2. Configuration: Create frontend/.prettierrc (or prettier.config.js) with a minimal, opinionated setup. Suggested starting point:
{
  "semi": true,
  "singleQuote": true,
  "trailingComma": "es5",
  "printWidth": 100,
  "tabWidth": 2
}
  1. Integration with ESLint: Use eslint-config-prettier to turn off all ESLint rules that conflict with Prettier, and add it as the last config in eslint.config.js.
  2. npm scripts: Add to frontend/package.json:
"format": "prettier --write .",
"format:check": "prettier --check ."
  1. CI integration: Update the frontend CI job to run npm run format:check alongside typecheck, lint, and test.
  2. Initial formatting run: Apply npm run format once in a dedicated PR so future PRs start from a clean baseline. Exclude generated files (src/generated/) and build output (../internal/web/dist/) from formatting.

Alternatives you've considered

Biome / Oxlint are faster all-in-one alternatives to the current ESLint + Prettier combo, but switching tools would require more config changes and risk destabilizing the existing flat-config setup. Sticking with Prettier for now keeps the change minimal and focused on formatting only.

Concrete use case

No response

Mockups, screenshots, or examples

No response

Which parts of the panel would this affect?

Frontend (UI / panel pages)

Are you willing to help?

  • I'd like to implement this feature myself and open a PR.
  • I can help test once a PR is open.

Before submitting

  • I searched existing issues and this feature has not been requested.
  • This feature request is written in English.
Originally created by @NikanZeyaei on GitHub (Jun 14, 2026). Original GitHub issue: https://github.com/MHSanaei/3x-ui/issues/5311 ### Is your feature request related to a problem? The frontend/ package currently enforces code quality through ESLint, but it has no automatic formatter. As a result, style decisions such as quote style, trailing commas, line length, and import wrapping are left to individual contributors. This creates inconsistent formatting across the codebase, noisy diffs in PRs, and unnecessary review rounds purely over style. ### Describe the solution you'd like Add a dedicated formatter to frontend/ and wire it into the existing development workflow. 1. Tool choice: Add Prettier as a dev dependency. It is the de-facto standard in the React/TypeScript/Vite ecosystem and integrates cleanly with the existing ESLint flat config. 2. Configuration: Create frontend/.prettierrc (or prettier.config.js) with a minimal, opinionated setup. Suggested starting point: ```json { "semi": true, "singleQuote": true, "trailingComma": "es5", "printWidth": 100, "tabWidth": 2 } ``` 3. Integration with ESLint: Use eslint-config-prettier to turn off all ESLint rules that conflict with Prettier, and add it as the last config in eslint.config.js. 4. npm scripts: Add to frontend/package.json: ``` "format": "prettier --write .", "format:check": "prettier --check ." ``` 5. CI integration: Update the frontend CI job to run npm run format:check alongside typecheck, lint, and test. 6. Initial formatting run: Apply npm run format once in a dedicated PR so future PRs start from a clean baseline. Exclude generated files (src/generated/**) and build output (../internal/web/dist/**) from formatting. ### Alternatives you've considered Biome / Oxlint are faster all-in-one alternatives to the current ESLint + Prettier combo, but switching tools would require more config changes and risk destabilizing the existing flat-config setup. Sticking with Prettier for now keeps the change minimal and focused on formatting only. ### Concrete use case _No response_ ### Mockups, screenshots, or examples _No response_ ### Which parts of the panel would this affect? Frontend (UI / panel pages) ### Are you willing to help? - [x] I'd like to implement this feature myself and open a PR. - [ ] I can help test once a PR is open. ### Before submitting - [x] I searched [existing issues](../issues?q=is%3Aissue) and this feature has not been requested. - [x] This feature request is written in English.
Author
Owner

@github-actions[bot] commented on GitHub (Jun 14, 2026):

The proposal is technically accurate and the implementation path is straightforward. Here is what is confirmed in the current source and a few details worth accounting for in the PR.

Current state (confirmed in source)

  • frontend/package.json has no Prettier or eslint-config-prettier in devDependencies. No .prettierrc or prettier.config.js exists.
  • frontend/eslint.config.js uses the ESLint flat-config format (an array export). Adding eslint-config-prettier as the final spread entry is the correct approach for this format.
  • The frontend CI job in .github/workflows/ci.yml runs lint, typecheck, test, build, and audit steps, but no format-check step.

Implementation notes

  1. Generated files. frontend/src/generated/ contains four auto-generated files (examples.ts, schemas.ts, types.ts, zod.ts) produced by npm run gen. These should be listed in a .prettierignore to avoid format drift between generation runs. The existing eslint.config.js already ignores node_modules/** and ../internal/web/dist/**; mirroring those in .prettierignore is prudent.

  2. Flat-config integration. eslint-config-prettier exports a plain config object, so in the flat-config array it should be spread last:

    import prettierConfig from 'eslint-config-prettier';
    // ...existing entries...
    prettierConfig,
    
  3. CI step placement. In .github/workflows/ci.yml, the format:check step is best inserted before the Build step in the frontend job so it fails fast without spending time on a full Vite build.

  4. Initial formatting PR. Running npm run format once on the existing source before the feature PR is merged (or as a combined first PR) avoids polluting future diffs. The codegen CI job already enforces that generated files are not stale (git diff --exit-code), so after the initial format pass the generated files should be re-generated and committed together to keep that check green.

The proposed Prettier config (semi, singleQuote, trailingComma: es5, printWidth: 100, tabWidth: 2) is a reasonable starting point; the project can adjust it before the initial format run without consequence since no baseline exists yet.

This reply was generated automatically; a maintainer may follow up.

<!-- gh-comment-id:4701188406 --> @github-actions[bot] commented on GitHub (Jun 14, 2026): The proposal is technically accurate and the implementation path is straightforward. Here is what is confirmed in the current source and a few details worth accounting for in the PR. **Current state (confirmed in source)** - `frontend/package.json` has no Prettier or `eslint-config-prettier` in `devDependencies`. No `.prettierrc` or `prettier.config.js` exists. - `frontend/eslint.config.js` uses the ESLint flat-config format (an array export). Adding `eslint-config-prettier` as the final spread entry is the correct approach for this format. - The `frontend` CI job in `.github/workflows/ci.yml` runs `lint`, `typecheck`, `test`, `build`, and `audit` steps, but no format-check step. **Implementation notes** 1. **Generated files.** `frontend/src/generated/` contains four auto-generated files (`examples.ts`, `schemas.ts`, `types.ts`, `zod.ts`) produced by `npm run gen`. These should be listed in a `.prettierignore` to avoid format drift between generation runs. The existing `eslint.config.js` already ignores `node_modules/**` and `../internal/web/dist/**`; mirroring those in `.prettierignore` is prudent. 2. **Flat-config integration.** `eslint-config-prettier` exports a plain config object, so in the flat-config array it should be spread last: ```js import prettierConfig from 'eslint-config-prettier'; // ...existing entries... prettierConfig, ``` 3. **CI step placement.** In `.github/workflows/ci.yml`, the `format:check` step is best inserted before the `Build` step in the `frontend` job so it fails fast without spending time on a full Vite build. 4. **Initial formatting PR.** Running `npm run format` once on the existing source before the feature PR is merged (or as a combined first PR) avoids polluting future diffs. The `codegen` CI job already enforces that generated files are not stale (`git diff --exit-code`), so after the initial format pass the generated files should be re-generated and committed together to keep that check green. The proposed Prettier config (`semi`, `singleQuote`, `trailingComma: es5`, `printWidth: 100`, `tabWidth: 2`) is a reasonable starting point; the project can adjust it before the initial format run without consequence since no baseline exists yet. *This reply was generated automatically; a maintainer may follow up.*
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
MHSanaei/3x-ui#3722
No description provided.