Coding standards are a set of guidelines and best practices that are used to create consistent, high-quality code. It is best to adopt these basic coding standards before creating Pull requests.
- Please use spaces for indentation (2 spaces) and not tabs.
- Utilize the available tools in VSCode for automatic indentation.
- Create types for:
i. New variables
ii. New function return types
iii. New arguments to functions
// i. New variables
let myString: string;
let myNumber: number;
// ii. New function return types
function exampleFunction(): boolean {
return true;
}
// iii. New arguments to functions
function processInput(input: string): void {
// Code to process the input
}
- Start type definitions for complex object structures (Type or Interface).
// Type definition for a user object
type User = {
id: number;
name: string;
age: number;
};
- Avoid using "any" as a type.
- Ensure accurate naming:
i. Use indicative names for Booleans, like isXXXX or hasXXXX or XXXXInd. - Use camelCase for all variables and class functions (statics should be all CAPITALIZED).
- Prefer const over let; completely avoid using var.
- Review the necessity of @state, as it's used almost by default
- Avoid direct DOM manipulation.
- Lifecycle functions should always start by calling the super version (except for render()).
- Comment functions and new blocks of code.
- Add comments for tricky problem-solving to aid understanding.
- If modifying the behavior of a function, update the comment or add a new one.
- Remove code instead of just commenting it out.
- Avoid very long functions; break them down.
- Eliminate duplication; create functions for common tasks.
- Avoid deeply nested if() statements:
i. This can be done by keeping functions short
ii. Also can sometimes be achieved by early returning from function based on negative condition - Minimize nesting of ternary operators (x ? y : x) if possible.