Coding Guidelines
The primary objective of these guidelines is not merely aesthetic consistency, but to ensure that any engineer can open the repository months later and safely modify or extend features without regressions.
Core Principles
- 1. Standards Before Frameworks
- Solve problems with standard HTML and CSS first. Introduce external libraries only when native browser capabilities genuinely cannot fulfill requirements.
- 2. Least Intervention
- Prefer declarative CSS over imperative JavaScript, and avoid introducing unnecessary external dependencies.
- 3. Progressive Enhancement MUSTCD-R01
- Core content and essential navigation must function when JavaScript is disabled or fails to load. Advanced interactive behaviors layer on top of this foundation.
- Check:
CD-01 - 4. Predictability Over Cleverness
- Code is read far more often than it is written. Avoid obscure patterns; prioritize clarity and self-documenting structures.
Directory and File Layout
src/
├── index.html
├── assets/
│ ├── css/
│ │ ├── style.css # Primary entry point
│ │ ├── base/ # Reset, tokens, element defaults
│ │ ├── layout/ # Page-level structures (headers, footers, grid)
│ │ ├── components/ # Reusable UI components
│ │ └── utilities/ # Single-purpose utility classes
│ ├── js/
│ │ └── main.js
│ └── images/
└── favicon.svgNaming Conventions
- Lowercase and Kebab-Case MUSTCD-R02
- All file and directory names must use lowercase letters separated by hyphens (
-), e.g.,news-detail.html,card-list.css. Spaces, uppercase characters, and special characters must not be used. - Check:
CD-02 - One Component Per File
- Each component CSS file defines exactly one block. The file name must strictly match the component block name.
- Purpose-Driven Asset Naming
- Image assets must be named according to their functional role (e.g.,
hero-visual.avif), never their page position (e.g.,img01.avif). For format and export specifications, refer to Images & Assets.
Formatting Standards
To eliminate subjective style debates and diff clutter during code reviews, formatting is strictly governed by automated tools.
| Item | Requirement | Rationale |
|---|---|---|
| Indentation | 2 spaces, no tabs | Eliminates visual disparity across different environments |
| Line Endings | LF (\n) | Prevents cross-platform diff noise (Windows/macOS/Linux) |
| Encoding | UTF-8 without BOM | Adheres to international standards; prevents corruption |
| Final Newline | Required (1 trailing newline) | POSIX compliance and clean Git diff display |
| Trailing Whitespace | Removed | Prevents unnecessary whitespace diffs |
| Quotes | HTML: "JS/CSS: ' | Aligns with standard language conventions |
Quote Examples
<!-- Incorrect: Single quotes in HTML attribute -->
<a href='/news/'>News</a>
<!-- Correct: Double quotes in HTML attributes -->
<a href="/news/">News</a>// Incorrect: Double quotes in JavaScript string literal
const label = "News"
// Correct: Single quotes in JS and CSS strings
const label = 'News'Indentation Examples
<!-- Incorrect: Indented using tabs -->
<ul>
<li>News</li>
</ul>
<!-- Correct: Indented using 2 spaces -->
<ul>
<li>News</li>
</ul>.editorconfig Configuration MUST
Every repository root MUST contain an .editorconfig file configured as follows:
root = true
[*]
charset = utf-8
end_of_line = lf
indent_style = space
indent_size = 2
insert_final_newline = true
trim_trailing_whitespace = true
[*.md]
trim_trailing_whitespace = falseFormatters such as Prettier (along with Stylelint and ESLint where applicable) SHOULD execute automatically on save or pre-commit hook to maintain consistent repositories SHOULD.
Commenting Standards
- Document the "Why", Not the "What"
Code expresses what is being done; comments must record why an unusual or specific approach was chosen.
- Example:
/* Safari 15 flexbox workaround: requires explicit width */(Valuable) - Example:
/* set width */(Noise)
- Example:
- Operational Comments
- Guidance intended for future content editors or operators—such as marking CMS template insertion areas or seasonal feature toggles—is explicitly permitted and encouraged.
Deliverable Restrictions MUST NOT
Production releases must not contain any of the following items:
- 1. Commented-Out Dead Code
- Version control preserves history; remove obsolete code entirely.
- 2. Debug Artifacts
- Lingering
console.log,debugger, oralert()statements. - 3. Environment-Specific Secrets
- Hardcoded staging URLs, local file paths, API credentials, or private keys.
- 4. Superfluous Files
- Unused source assets, unreferenced dependencies, or committed
node_modules.