Monolith repo for Minti v0
- Do not commit directly to master.
- All changes must be tested.
- Branch names must be kebab-cased with appropriate names.
- Commit messages must be descriptive.
Inspired by: felixge's Node Style Guide. This is just a basic guide for Node.js styling so there is a consistent flow across the project. Please make sure you and others abide by it to minimize any confusion.
There will be a force-linter file to make sure that we stick to the styling guidelines as best as possible.
2 space tabs for indentation
Newlines
No trailing whitespaces
Use semicolons
Wrap your text
Single quotes
One variable per statement
Opening braces on the same line
lowerCamelCase for variables, properties, and functions
UpperCamelCase for class names and components
UPPERCASE for constants
Correct:
if (true) {
console.log("Correct!");
}
Avoid the usage of \r
followed by \n
. Only have \n
.
Correct:
console.log("Hello: \n Minti");
Wrong:
console.log("Hello: \r\n Minti");
Don't have whitespaces floating around like this
.
Always end your lines with a semicolon;
If you run out of space on a line, go to a new one. Don't have it go on forever.
Use single quotes unless you are writing JSON.
Don't group variables declarations together. Correct:
var nums = [1, 2, 3, 4];
var vals = ["One", "Two", "Three", "Four"];
Wrong:
var nums = [1, 2, 3, 4],
vals = ["One", "Two", "Three", "Four"];
Correct:
if (true) {
console.log("this is true");
}
Wrong:
if (true) {
console.log("this is wrong");
}
Use variableName
, propertyName
, functionName
naming convention for variables, properties, and functions.
Use ClassName
, ComponentName
naming convention for classes and components.
Use CONSTNAME
naming convention for constants.
Correct:
var a = 0;
if (a !== "") {
console.log("this is right");
}
Wrong:
var a = 0;
if (a == "") {
console.log("not right");
}
Correct:
var isValidEntry = entry.length >= 4 && /^(?=.*\d).{4,}$/.test(entry);
if (isValidEntry) {
console.log("it's valid");
}
Wrong:
if (entry.length >= 4 && /^(?=.*\d).{4,}$/.test(entry)) {
console.log('it\'s valid');
}
Keep functions short. Don't have them going on and on.
To prevent deep if-statement nesting, we want to return early where possible. Correct:
function isPercentage(val) {
if (val < 0) {
return false;
}
if (val > 100) {
return false;
}
return true;
}
Wrong:
function isPercentage(val) {
if (val >= 0) {
if (val < 100) {
return true;
} else {
return false;
}
} else {
return false;
}
}
Or for this particular example it may also be fine to shorten things even further:
function isPercentage(val) {
var isInRange = val >= 0 && val <= 100;
return isInRange;
}
Be sure to include try-catch blocks
and throw
statements.
Correct:
try {
if (isValid) {
return "this is valid";
}
throw "isValid came out false";
} catch (err) {
console.log(err);
return "oops. there has been an internal error";
}
Wrong:
if (isValid) {
return "this is valid";
}
return "oops. there has been an internal error";
=>
is good.
Correct:
const Component = (props) => {
// code here
};
Wrong:
function Component(props) {
// code here
}
One method per line when chaining