Skip to content

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 ​

text
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.svg

Naming 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.

Formatting standards
ItemRequirementRationale
Indentation2 spaces, no tabsEliminates visual disparity across different environments
Line EndingsLF (\n)Prevents cross-platform diff noise (Windows/macOS/Linux)
EncodingUTF-8 without BOMAdheres to international standards; prevents corruption
Final NewlineRequired (1 trailing newline)POSIX compliance and clean Git diff display
Trailing WhitespaceRemovedPrevents unnecessary whitespace diffs
QuotesHTML: "
JS/CSS: '
Aligns with standard language conventions

Quote Examples ​

html
<!-- Incorrect: Single quotes in HTML attribute -->
<a href='/news/'>News</a>

<!-- Correct: Double quotes in HTML attributes -->
<a href="/news/">News</a>
javascript
// Incorrect: Double quotes in JavaScript string literal
const label = "News"

// Correct: Single quotes in JS and CSS strings
const label = 'News'

Indentation Examples ​

html
<!-- 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:

ini
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 = false

Formatters 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)
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, or alert() 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.

Next Steps ​