Software Vision: Enforced Code Conventions

Status Draft for review
Last updated 2026-12-04
Related Architecture · Conventions catalog

1. Problem

AI-assisted development is increasing the amount of code we write. Agents write code quickly and confidently, but the style varies from one prompt to the next. Without hard limits and/or careful scrutiny, repositories can tend to drift toward a mix of naming schemes, oversized functions, missing tests, leftover placeholders and comments that narrate the code instead of explaining it. Review can’t catch all of this at the volume agents produce.

No infrastructure is currently set up to manage this. A survey of the 100 most recently active projects (activity from Nov 2025 to Dec 2026, out of 541 total) found the following; details are in Appendix A:

Conventions that exist only in a document, or in a prompt, are suggestions. Agents and people follow them some of the time.

2. Vision

All code that reaches a protected branch meets one agreed, versioned set of conventions, whether a person or an agent wrote it. Machines check those conventions as early as possible: ideally while the agent is still writing the code, and at the latest before merge. The only way around a rule is an explicit, reviewed exception.

For an AI agent, a convention is part of the environment rather than an instruction it can forget. The agent’s edits are checked as it makes them, and the agent cannot report “done” while its changes violate a rule. For a developer, conventions are mostly invisible: the formatter fixes style on save, and the merge request shows any remaining problem inline. For reviewers, review time goes to design and intent, not spacing and naming.

3. Goals

  1. One source of truth. A single, versioned conventions repository holds the rules, the tool configurations and the pinned tool versions. Every enforcement point uses it.
  2. Enforcement, not guidance. Every rule that a machine can check is checked deterministically and blocks the merge. Rules that need judgment are labeled as such, so nobody assumes they are guaranteed.
  3. Enforce as early as possible.
  4. Same results everywhere. A file that passes on a developer’s machine or in an agent session passes in CI. Every enforcement point uses the same tool versions and configs.
  5. A full set of conventions. They cover far more than formatting: naming, structure, dependencies, complexity, design, types, error handling, documentation, logging, configuration, dead code, duplication, idioms, styling, testing, security and accessibility. See the catalog.
  6. Language-specific depth where it matters. Languages used in more than one project, or heavily in one, get a full profile. Others get basic formatting and linting, or none.
  7. Legacy code is not a blocker. Only changed files are checked. Existing violations are fixed when the code is touched, not in a big-bang cleanup.
  8. Exceptions are explicit and require approval. Inline “disable” comments are not accepted. Every exception lives in one reviewable place in the repository, and an owner must approve changes there.
  9. Established tools over new ones. We use standard, widely adopted formatters, linters, runners and GitLab features. Custom code is limited to thin glue.

4. Non-goals

5. Principles

Principle What it means in practice
Deterministic first, advisory second Formatters and linters decide. AI review and human review handle only what tools cannot judge, and they are labeled that way.
Fix automatically when possible If a tool can fix a problem (formatting, import order, simple lint fixes), it does, and nobody discusses it.
Enforce where the code is written The cheapest place to fix a violation is in the agent’s own edit loop, before a human ever sees it.
The merge gate is the guarantee Local checks are fast feedback that can be bypassed. The CI gate on a mandatory merge request is what cannot be bypassed.
Only changed code is gated Each change is judged by the files it touches; old code is not held against it.
Exceptions are data, not comments An exception is a reviewed entry in .conventions/, never a // eslint-disable added in passing.
Rules are versioned and staged Rules change through releases. A new rule warns before it blocks.

6. Stakeholders and users

Who What they need
Developers Fast, clear feedback; automatic fixes; no surprises at merge time; a clear way to request an exception.
AI coding agents (Claude Code, Codex) Immediate, machine-readable feedback after each edit; a hard stop before reporting work done; written conventions for the rules that need judgment.
Reviewers and maintainers MRs that already meet the mechanical rules; findings shown inline in the diff; reviews focused on design.
Conventions owners (a small group of engineering leads) Own the rules and their versions, approve exceptions, decide on threshold changes, watch the rollout measures.
GitLab administrators Group-level settings and policies that roll out in rings and can’t be removed project by project.
Clients and auditors (indirectly) Consistent, maintainable, accessible and secure deliverables across client projects.

7. Scope

7.1 Convention categories

The conventions are organized into 19 categories, plus one process rule. The full table is in the conventions catalog.

  1. Formatting & layout
  2. Naming
  3. Project & file structure
  4. Module organization & dependencies
  5. Size & complexity
  6. Function & code design
  7. Types & data contracts
  8. Error handling
  9. Comments & documentation
  10. Logging & observability
  11. Configuration & environment
  12. Dead code
  13. Duplication & reuse
  14. Language idioms & framework conventions
  15. Styling (CSS/SCSS)
  16. Testing
  17. Security & secrets
  18. Accessibility (web & email)
  19. Generated, vendored & AI-specific code
  20. Process rule PR-01: all code reaches protected branches through an approved merge request.

7.2 Languages

“Significant” means used in more than one active project, or used heavily in one.

Profile Languages
Full (every applicable category) JavaScript, TypeScript, Svelte, Astro · CSS/SCSS · HTML (a web profile and an email profile) · PHP (WordPress) · Python · Go · Shell/Bash · PowerShell · C#
Config/infra (format and lint) YAML (including CI files), JSON, Dockerfile, Markdown, SQL
Not covered Java and Rust (too little use); data files (XML, CSV, SVG, RTF); generated, vendored or minified output

The language list will be confirmed against all non-archived projects before rollout. The current survey covers only the 100 most recently active.

8. Mandatory merge requests (PR-01)

Today, code can be pushed directly to default branches. No gate can work while that is true, so making merge requests mandatory is a prerequisite and a convention in its own right:

These are set as group-level defaults, so each new project is covered automatically when its group joins the rollout.

9. Rollout

Rollout expands in rings, one group at a time. Each ring goes through the same steps: turn on mandatory MRs → conventions in warn mode → conventions blocking.

Ring Scope Entry state
0 – Pilot 4–6 representative repos (Svelte/TS, TS/SCSS, WordPress, Python, Go, email) MRs required; conventions warn only
1 – Early adopters 2–3 internal groups (e.g. cg-life, toolhouse) MRs required; conventions blocking on changed files
2 – Active client groups e.g. novo, scholar-rock, genmab Two weeks of warn mode, then blocking
3 – Everywhere Every group; the instance-wide default Blocking; new projects covered automatically

A ring is ready to expand when: - False positives are under the agreed rate. - Agent per-edit check latency is within target. - The exception request rate is stable. - Developer feedback has been addressed.

A rule added later follows the same warn-then-block cycle.

10. Success measures

Measure Target
Projects in scope that require MRs and run the conventions gate 100% of Ring 3 scope
Changes merged to protected branches without an MR (outside logged emergencies) 0
Agent sessions that finish with convention violations in changed files ≈ 0 (enforced by the Stop hook)
Agent per-edit check latency p95 under 2 s
MRs that fail the gate in CI after passing local and agent checks Under 2% (a measure of local/CI parity)
Exceptions per 1,000 changed lines Watched; a rising trend triggers a rule review
Review comments about formatting or naming style Trending to near zero

11. Risks and open questions

Item Notes / mitigation
Managed GitLab tier unknown The cleanest design needs Ultimate: pipeline execution policies centrally inject a job that projects can’t remove. On Premium, each project includes the gate and a scheduled audit catches removal. Both are described in the architecture.
Codex hook details Codex supports PostToolUse and Stop-style hooks with managed configuration. The exact matcher names and behavior must be checked against the current Codex docs during implementation.
Thresholds too strict or too loose The pilot tunes complexity and size limits. New rules start in warn mode.
Developer friction Autofix on save and in agent hooks; changed files only; a clear, fast exception path.
Email and generated HTML Email HTML gets its own profile (layout tables and inline styles allowed). Generated output (e.g. Google Web Designer exports) is excluded by path.
Unmanaged agents and cloud agents They may skip local hooks, but the merge gate still catches every violation.
Rule ownership Requires a named conventions-owners group with time set aside to answer exception requests promptly.

Appendix A: GitLab survey results

Collected on 2026-12-04 with scripts/gitlab-metrics.sh (code metrics from scc), plus a read-only GitLab API survey of each project’s root files, package.json and .gitlab-ci.yml. The raw database is not kept; re-run the script for fresh numbers.

Coverage: 100 of the 541 projects, the most recently active ones (last activity between Nov 2025 and Dec 2026). 44 of the 541 are archived.

Languages in active projects

Language Projects Code lines Notes
HTML 55 881k Mostly email templates and banner ads
JavaScript 62 199k Includes generated Google Web Designer banner output (gwd-banner-ads/*, ~85k)
CSS 38 127k
Sass/SCSS 32 114k
Svelte 9 46k SvelteKit sites and apps
TypeScript 23 35k
PHP 4 20k WordPress themes and sites
C# 1 12k One backend project
Python 5 7k
PowerShell 2 6.6k
Astro 1 5.4k
Shell / Bash 19 6k
Go 6 3k
Java 1 1.2k Below the threshold
SQL 4 1.1k
Rust 1 0.4k Below the threshold
YAML / JSON / Markdown / Dockerfile 76 / 84 / 87 / 53 — Config and infrastructure
XML, CSV, SVG, RTF — — Data files; out of scope

Existing tooling (100 active projects)

Finding Count
Projects with .gitlab-ci.yml 72
CI pipelines that run a linter 0
CI pipelines that check formatting 1 (yarn format:check, i.e. Prettier)
CI files that use a shared include: 1
Projects with a lint or format dependency in package.json 22
Projects with a Prettier / ESLint / Stylelint / EditorConfig config file 13 / 9 / 5 / 6
Projects with AGENTS.md / .claude/ 7 / 3