Skip to content

Latest commit

 

History

History
301 lines (207 loc) · 4.95 KB

README.md

File metadata and controls

301 lines (207 loc) · 4.95 KB

minti-monolith

Monolith repo for Minti v0


Workflow

  • 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.

Node.js Style guide

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.

Formatting

Naming Conventions

Conditionals

Functions

Comments

Formatting


2 space tabs for indentation

Correct:

if (true) {
	console.log("Correct!");
}

Newlines

Avoid the usage of \r followed by \n. Only have \n. Correct:

console.log("Hello: \n Minti");

Wrong:

console.log("Hello: \r\n Minti");

No trailing whitespaces

Don't have whitespaces floating around like this .

Use semicolons

Always end your lines with a semicolon;

Wrap your text

If you run out of space on a line, go to a new one. Don't have it go on forever.

Single quotes

Use single quotes unless you are writing JSON.

One variable per statement

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"];

Opening braces on the same line

Correct:

if (true) {
	console.log("this is true");
}

Wrong:

if (true) {
	console.log("this is wrong");
}

Naming Conventions


lowerCamelCase

Use variableName, propertyName, functionName naming convention for variables, properties, and functions.

UpperCamelCase

Use ClassName, ComponentName naming convention for classes and components.

UPPERCASE

Use CONSTNAME naming convention for constants.

Conditionals


Use the === operator

Correct:

var a = 0;
if (a !== "") {
	console.log("this is right");
}

Wrong:

var a = 0;
if (a == "") {
	console.log("not right");
}

Use descriptive conditionals

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');
}

Functions


Keep functions compact

Keep functions short. Don't have them going on and on.

Return early

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;
}

Error handling

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";

Fat arrows

=> is good. Correct:

const Component = (props) => {
	// code here
};

Wrong:

function Component(props) {
	// code here
}

Method chaining

One method per line when chaining