https://github.com/indec-it/javascript
JavaScript Style Guide
https://github.com/indec-it/javascript
arrow-functions es2015 es6 eslint javascript linting naming-conventions style-guide style-linter styleguide
Last synced: 3 months ago
JSON representation
JavaScript Style Guide
- Host: GitHub
- URL: https://github.com/indec-it/javascript
- Owner: indec-it
- License: mit
- Created: 2018-03-15T16:00:21.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2019-05-02T16:08:21.000Z (over 7 years ago)
- Last Synced: 2025-05-16T19:47:43.949Z (about 1 year ago)
- Topics: arrow-functions, es2015, es6, eslint, javascript, linting, naming-conventions, style-guide, style-linter, styleguide
- Size: 7.81 KB
- Stars: 1
- Watchers: 11
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# INDEC JavaScript Style Guide() {
*A mostly reasonable approach to JavaScript*
> **Note**: this guide is base on airbnb guide [Airbnb JavaScript Style Guide](https://github.com/airbnb/javascript/blob/master/README.md),
it reinforces the most important rules and overwrites some of them.
## Table of Contents
1. [Functions](#functions)
1. [Blocks](#blocks)
1. [WhiteSpace](#whitespace)
1. [ES7](#es7)
## Functions
- [1.1](#functions) **Method Naming**: Methods should be named with a verb in infinitive.
```js
// bad
function validating() {
//...
};
// good
function validate() {
// ...
};
```
## Blocks
- [2.1](#blocks--braces) Use braces with all single-line blocks.
```js
// bad
if (test) return false;
// good
if (test) {
return false;
}
```
**[⬆ back to top](#table-of-contents)**
## Whitespace
- [3.1](#whitespace--spaces) Use soft tabs (space character) set to 4 spaces.
```js
// bad
function foo() {
∙let name;
}
// bad
function bar() {
∙∙let name;
}
// good
function baz() {
∙∙∙∙let name;
}
```
**[⬆ back to top](#table-of-contents)**
## ES7
- [4.1](#Async/Await) **Async/Await**: use `async/await` instead of `then` (promises)
```js
// bad
const fetchUser = url => getAuthHeader().then(
authorization => fetch(url, { headers: {authorization} })
).then(
response => response.json
).then(
data => new User(data.user)
)catch(
err => console.log(err);
);
// good
const fetchUser = async url => {
try {
const response = await fetch(url, {
credentials: 'same-origin',
headers: {
authorization: await getAuthHeader()
}
});
const data = await response.json();
return new User(data.user);
} catch (err) {
console.log(err);
throw err;
}
}
```
**[⬆ back to top](#table-of-contents)**
# }