Set of guidelines I built from my developper experience. Gathered here to remind me how to keep my code scalable over time.
- Function updating a boolean property
- Function returning the value of a boolean property
- Function returning an array
- Function checking if has element
- Function removing an element
- Function removing multiple elements
- Use kebab case
- Prefixed by
enable
ordisable
keywords to update a boolean value
class Response {
static enableFetchingFromCache() {
Response.fetchFromCache = true;
}
static disableFetchingFromCache() {
Response.fetchFromCache = false;
}
}
- Use kebab case
- Name is positive
- Suffixed by
enabled
class Response {
static fetchingFromCacheEnabled() {
return Response.fetchFromCache === true;
}
}
- Use kebab case
- Prefixed by
get
- Plural
const Router {
static _routes = [];
static getRoutes() {
return Router._routes;
}
}
- Use kebab case
- Name positive
- Prefixed by
has
class Router {
static _routes = [];
static hasRoute(route) {
return Router._routes.includes(route);
}
}
- Use kebab case
- Singular naming
- Prefixed with
remove
function removeNotification() {}
- Use kebab case
- Plural naming
- Prefixed with
remove
function removeImages() {}
If the subject is not pluralizable, suffix it with list
:
function removeFluxList() {}
- Use kebab case
- Plural
const repositories = ["rs-json", "browser-worker", "JUR"];
- If not pluralizable, suffix it by
list
const fluxList = ["incoming", "outgoing"];
- Use kebab case
- Name positive
class Response {
static fetchFromCache = true;
}
- Use kebab case
for ... of
orforeach ... as
variable loop should have singular form
const buttons = document.querySelectorAll("button");
for (const button of buttons) {
// ...
}
- regular
for
index name should be namedindex
for (let index = 0; index < 5; index++) {
// ...
}
- Use kebab case
- Suffixed with
count
const languages = ["php", "c#", "nodejs"];
const languagesCount = languages.length;