Appearance
JavaScript Style guide
It is very useful to respect some norms and standards in your code, for various reasons, such as:
- Better code readability: it becomes easier to write and to read the code
- Better maintainability: having a more readable code is easier to modify if necessary
- Better performances management: coding conventions allow a better optimization of the resources
If you are developing with Vue, you can use this .eslintrc.js configuration file.
You will find a file name CONVENTIONS.md in the various provided boilerplates. Hereafter are some of the rules we respect:
Block indentation: 2 spaces
We recommend that each time a new block or block-like construct is opened, the indent increases by two spaces.
Column limit: 120
We also recommend a column limit of 120 characters.
Arrow functions
When the body of an arrow function is a single line, we do not add unnecessary brackets or return statement.
YES:
javascript
return this.contracts.filter(o => o._deleted !== true)NO:
javascript
return this.contracts.filter(o => { return o._deleted !== true })Use single quotes
We recommend that ordinary string literals are delimated with single quotes ( ' ), rather than double quotes ( " ).
Exception: use double quotes ( " ) if the string contains a single quote ( ' ).
For example:
javascript
const steps = {
Admissiblity: {
id: 1,
name: 'Recevabilité',
},
EvaluationSummary: {
id: 2,
name: "Dépôt d'avis",
},
}Naming events
We recommend to give events simple names that describe what is happening. For example: openDocument would be emitted when a document is actually opened.
Naming handlers
We recommend the handlers to begin with on. For example: onDocumentViewRequest().
If the code in the handler must be called by other parts of code, we extract the reused code into its own function. For example, the handler onDocumentViewRequest may call a method called openDocument(). No code should explicitly call onDocumentViewRequest.
Next chapter
This clarified, we can go the next chapter, dealing with tools and technology.