Skip to content

Software Style Guide

Converse uses Prettier to enforce a consistent code style across the codebase. The configuration lives in .prettierrc at the project root.

Run Prettier on your changes before committing:

Terminal window
npx prettier --write src/path/to/file.js

Many of the conventions below are enforced by Prettier automatically. Where Prettier doesn’t cover something (naming conventions, architectural patterns), the rules below apply.

Our Prettier settings:

SettingValue
tabWidth4 spaces
useTabsfalse (spaces, not tabs)
singleQuotetrue
printWidth120
spaceBeforeFunctionParentrue
bracketSpacingtrue

We use snake_case for variable names and camelCase for function names.

function thisIsAFunction () {
let this_is_a_variable;
...
}

Use PascalCase for class names.

Global identifiers that denote constant values should be written in UPPER_CASE, with underscores between words.

const SECONDS_IN_HOUR = 3600;
function update () {
const timeout = 20;
let seconds_since_message = 0;
}

Try to use const whenever possible. If a variable won’t be reassigned, use const, otherwise use let.

JavaScript has a strict === and less strict == equality operator. The stricter equality operator also does type checking. To avoid subtle bugs when doing comparisons, always use the strict equality check.

When writing a block such as an if or while statement, always use curly brackets around that block of code. Even when not strictly required by the compiler (for example if its only one line inside the if statement).

if (condition === true) {
this.updateRoomsList();
}
somethingElse();

and NOT like this:

if (converse.auto_list_rooms)
this.updateRoomsList();
somethingElse();

This is to aid in readability and to avoid subtle bugs where certain lines are wrongly assumed to be executed within a block.

Thank you to our sponsors

If you'd like to sponsor this project, please visit Github, Patreon, Liberapay or contact us.