Code Convention - MirageAegis/Sushi-Bot GitHub Wiki

Working with Sushi Bot's source code, you're expected to follow these coding conventions wherever applicable.

If any questions arise, contact the team through Sushi Hub.

File- and Directory names

All file- and directory names should be in kebab-case

Example:

// Single word file name
index.ts

// Multi-word file name
this-is-a-long-file-name.ts

This doesn't apply to the .github/ folder.

TypeScript Source Files

Variables and Constants

We prefer to use consts in our code, even for potential variables. If a variable is reassigned, use let over var.

Names

Variable names should be in camelCase while constants should be in SCREAMING_SNAKE_CASE. The type of the variable/constant must also be explicitly declared.

Example:

// Variables
let oof: boolean = true;
let oofLevel: number = 69;

// Constants
const OOFER: string = "Zahatikoff";
const OOFER_TYPE: string = "Clown";

Declarations

When declaring variables/constants, the identifier should be immediately exceeded by a colon (:) and the colon with one space before the type of the variable/constant.

Example:

// Do this
let kekw: boolean;

// Don't do this
let kekl :boolean;

Assignments

When assigning values, the equals sign (=) should be wrapped with one space.

Example:

// Do this
kekw = true;

// Don't do this
kekl=false;

Casting

When casting, the cast operation and identifier should be separated by one space.

Example:

// Do this
const superclassInstance: Superclass = <Superclass> subclassInstance;

// Don't do this
const superclassInstance: Superclass = <Superclass>subclassInstance;

Brace Style

We make use of the One True Brace Style in our code but also allow single line statements.

Example:

if (something) {
    doSomething();
}

if (somethingElse) doSomethingElse();

Indentation

Code blocks should be indented with four spaces for each level.

Example:

for (;;) {
    // Code here
}

Control Flow Statements

All control flow statements' declarations; i.e. if-else, for, do-while, and try-catch-finally; should have the different parts separated by one space.

Example:

// Do this
for (let i: number = 0; i < 10; i++) {
    // Code
}

// Don't do this
for(let i: number = 0; i < 10; i++){
    // Code
}

For Loop Semicolons

Furthermore, the semi colons (;) in for loops should be exceeded with one space.

Example:

// Do this
for (let i: number = 0; i < 10; i++) {
    // Code
}

// Don't do this
for (let i: number = 0;i < 10;i++) {
    // Code
}

Functions

Function Style

We prefer to use const arrow functions over regular functions.

// Arrow function
const send = (): void => {
    // Code
};

// Regular function
function send(): void {
    // Code
}

Type Declaration

You don't need to explicitly declare the type of an arrow function, only the return type.

Example:

// Do this
const send = (): void => {
    // Code
};

// This is unnecessary
const send: { (): void } = (): void => {
    // Code
};

Return Type and Arrow Spacing

The signature of functions should follow the same conventions as variable declarations and have each token to the left of the colon (:) separated by one space.

Example:

// Do this
const send = (): void => {
    // Code
};

// Don't do this
const SEND=() :void=>{
    // Code
}

Arguments

When declaring function arguments, the arguments should follow the same conventions as variables (not constants). When dealing with multiple arguments, they should be separated by a comma (,) and space in that order.

Example:

// Do this
const foo = (bar: string, baz: boolean): string => {
    // Code
};

// Don't do this
const foo = (bar:string,baz:boolean): string => {
    // Code
};

Class-, Type-, and Interface names

These three should be in PascalCase and have one space between their names and the opening brace.

Example:

class Cheese {
    // Implementation
}

interface DairyProduct {
    // Implementation
}

type Food = {
    // Implementation
}

Class Members

Class members should follow the same naming convention as variables. Each member must also have an access modifier (private, public, or protected).

Class constants are preferred over class variables.

Example:

class Unit {
    // Instance variable
    private hp: number;

    // Instance constant
    private readonly id: string;

    // Class constant
    public static readonly faction: string = "Player";
}

Discord Commands

Discord's application commands follow slightly different naming conventions.

Command Names

Command names should be in lowercase, without spaces. This also applies to subcommands.

Example:

// Single word command name
const name: string = "command";

// Multi-word command name
const name: string = "longcommandname";

Command Options

Command options should have their names in snake_case.

Example:

// Single word option name
option.setName("user");

// Multi-word option name
option.setName("member_or_user");
⚠️ **GitHub.com Fallback** ⚠️