Frontend Development 13 min read

Clean Code Practices and Tooling for Frontend Development

This article explains the concepts of external and internal code beauty, introduces essential frontend tooling such as ESLint, Prettier, Stylelint, husky, lint‑staged, EditorConfig, and CSSComb, and shares practical habits on documentation, naming, and commenting to help developers produce elegant, maintainable code.

Rare Earth Juejin Tech Community
Rare Earth Juejin Tech Community
Rare Earth Juejin Tech Community
Clean Code Practices and Tooling for Frontend Development

When working on long‑lived, multi‑developer projects, unreadable or messy code can become a major obstacle; the article defines clean code through two aspects: “external beauty” (proper formatting, comments, indentation, spacing, and avoidance of duplication) and “internal beauty” (minimal dependencies, clear abstractions, straightforward control flow, and good design patterns).

To achieve external beauty, the author recommends a set of frontend tools—ESLint, Stylelint, Prettier, lint‑staged, and husky—that enforce consistent code style and automatically format code before commits. The typical workflow is: add files to the Git staging area, run git commit , trigger husky’s pre‑commit hook, execute lint‑staged on staged files, and abort the commit if any lint errors remain.

{
  "eslint.run": "onSave",
  "eslint.format.enable": true,
  "eslint.options": {
    "extensions": [".js", ".vue", ".ts", ".tsx"]
  },
  "eslint.validate": ["javascript", "typescript", "vue"],
  "stylelint.validate": ["css", "less", "postcss", "scss", "sass", "vue"],
  // Save‑time formatting rule
  "editor.codeActionsOnSave": {
    "source.fixAll": true,
    "source.fixAll.eslint": true
  },
  "files.autoSave": "afterDelay",
  "files.autoSaveDelay": 2000
}

For CSS formatting, the author suggests using CSSComb (or alternatives like stylelint‑order) to enforce a consistent property order, improving readability and potentially page‑load performance.

# Editor configuration, see http://editorconfig.org

# Top‑level file
root = true

[*] # Apply to all files
charset = utf-8
indent_style = space
indent_size = 2
end_of_line = lf
insert_final_newline = true
trim_trailing_whitespace = true

Commit message consistency is addressed with the Conventional Commits specification, aided by tools such as commitlint, commitizen, cz‑customizable, and commitlint‑config‑cz, which together enforce a readable, machine‑parsable commit history.

The second part shares personal experience: writing clear documentation (referencing Chinese and Google style guides), adopting naming conventions that balance brevity and information (e.g., min‑length & max‑information principle), and using verb‑first function names. A comprehensive list of common action verbs for naming is provided.

Regarding comments, the author proposes a pragmatic approach: write comments only when the code cannot be made self‑explanatory, and always ask whether the author (or a teammate) could understand the code after three months without additional explanation.

In summary, adopting these tools and habits leads to cleaner, more maintainable code, reduces onboarding costs, improves team collaboration, and provides personal satisfaction for developers who value code elegance.

frontendgitcode-styleclean codeeslintprettierNaming
Rare Earth Juejin Tech Community
Written by

Rare Earth Juejin Tech Community

Juejin, a tech community that helps developers grow.

0 followers
Reader feedback

How this landed with the community

login Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.