All files must start with the MergerJS copyright information as a comment,
with the exception of the merger.js file which must start with the shebang #!/usr/bin/env node
before the copyright information.
The license headers must be followed by 'use strict'
;
Filenames must be camelCase
.
- Use spaces, not tabs.
- Lines (line breaks) should end in
LF
characters (UNIX) and notCRLF
(Windows).
Use two (2) spaces.
All expresions must end with a semicollon.
Example:
doThis();
const PI = 3.14;
-
const
Static constant values must have thePASCAL_ALL_CAPS
style.
In case they are constant value variables from function calls, they must have thecamelCase
style.
If you don't expect the value to change, always opt to useconst
. -
let
Variables must have thecamelCase
style. -
var
Never usevar
.
Variables and constants should have JSDoc type definitions (Official specification, Wikipedia) documentation when suited, or if you think it will improve the readability or development of the code.
You must use single quotes const MESSAGE = 'Hello World!';
.
You must insert a space after opening and before closing non-empty parenthesis.
Example:
doThis( 'with this string' );
Braces must be used in all control structures (i.e. if, else, for, do, while, as well as any others), even if the body contains only a single statement.
Example:
if ( something ) {
doThis( 'now' );
}
The else
statement must be separated by an extra line break.
Example:
if ( isNight ) {
console.log( 'Good night!' );
} else {
console.log( 'Good day!' );
}
- Classes must have
PascalCase
as naming style. - Methods and properties must have
camelCase
naming style. - Private methods and properties (methods and properties that will be used only by that class), must start with four (4) undescores characters in their name.
- Always prefer using classes instead of functions.
- Most classes will be static, so those must inherit from
models/staticClassBase.js
. - Methods must have JSDoc (Official specification, Wikipedia) documentation.
-
If it's a module, try to create a class instead, but, if it makes sense, do use a function.
-
Do NOT create constructor functions, use well structured classes instead.
-
Functions names must have the
camelCase
naming convention. -
Private functions (internal functions in a class or module) must start with four (4) undescores characters in their name:
const ____privateFunction = ...
-
Functions must have JSDoc (Official specification, Wikipedia) documentation.
-
Functions must follow the ES arrow function syntax and use the
const
keyword when they are a defenition and not part of an object. -
Parameters must have parenthesis, even if the function only has one parameter.
-
Lambdas must have braces, even if there is only only one expression inside the function.
Example:
/**
* Description of the function and what it returns.
*
* @param { string } withThis Description of the parameter.
*
* @returns { void }
*/
const doThis = ( withThis ) => {
console.log( withThis );
};
// No:
let var1, var2, var3;
// Yes:
let var1;
let var2;
let var3;
// No:
listArray[listSize++] = it;
// Yes:
listArray[listSize + 1] = it;
++listsSize;
After following these style conventions, you should also follow the Airbnb style guide: https://github.com/airbnb/javascript
This document may change in the future.
Before starting to contribute to MergerJS, you must have in mind that this was my first
software project, before any kind of personal or professional experience.
The first version was made in one weekend and, with time, it was added new features without
really thinking about future maintainability and evolution.
Therefore, there are a lot of architectural problems and "spaghetti" code.
With each new release, the codebase gets small architectural refactorings and improvements,
but a lot of work still needs to be done.