Skip to content

Standards

The requirements every change has to pass and every piece of software has to meet, and what happens when something fails them.

One standard for the whole organization

The rules are one shared preset, @trebired/configs, and @trebired/code-discipline enforces it in every Trebired codebase, whatever it is written in: TypeScript, JavaScript, Rust, Go, C++, C#, Python, QML, shell, SCSS and CSS. A repository adds only what is specific to it.

Break a rule and the app does not run

Every app runs behind the code-discipline gate. It checks the whole repository before anything starts, so a single broken rule is enough to keep the app from running.

  • 0

    No violations

    The app starts.

  • 1

    One violation

    Nothing starts, not even on your own machine, until it is fixed.

Every file has a name nobody chose

@trebired/code-discipline gives every source file a random alias and keeps the whole map in sync. An import that climbs out of its folder with ../ is rewritten to that alias, so code points at a file, not at the route to it. The alias is random on purpose: it says nothing about where the file lives.

Instead of

../../components/chrome/hero/tones

Every import reads

#0s6jb8phbwma
#0s6jb8phbwma
  • One map, committed

    Every alias lives in .trebired/code-discipline/imports beside the code. The compiler's view of it is generated and never committed.

  • ./ stays as written

    An import that starts with ./ is left as written. Only one that climbs out with ../ is rewritten.

  • Dead imports go

    An imported name that nothing in the file uses is removed when the rule fixes the repository.

The numbers, drawn to scale

The limits the preset and this standard set, each drawn at its real size.

  • 350

    lines in a file at most. A longer one is split before the project starts again.

  • 50

    lines in a function at most. A longer one is doing two jobs and becomes two functions.

  • 500 MB

    of memory per application at most, with 200 MB as the target. Above the cap nothing ships, and the fix goes to the cause, never to the cap.

  • 150

    characters on a line. The formatter wraps what it can wrap safely, and the rest stays reported until it is rewritten.

  • 120

    characters is where the DRY rule starts. It compares every function in the source tree with names, whitespace and comments stripped, so two functions that do the same thing are one duplicate group even when renamed, and one of them has to go.

  • 72

    characters in a commit subject, in the imperative, describing behaviour and never the files that moved.