An ESLint Shareable Config for my preferable code style.
- Two spaces
- Single quotes
- No semicolons
See all rules here.
// only ES2015
import fetch from 'fetch' // empty line after import
// space after function's name
export function hello (name = 'world') { // single quotes
return `Hello, ${name}!` // two spaces for indent
} // no semicolons
// consts everywhere
export const fetchData = uri => { // no parens if single argument
return fetch(uri)
.then(res => res.json()) // arrow callback
.then(data => ({ a: data.a, b: data.b }))
// spacing inside single-line blocks
}
// empty line at the end of code
You need ESLint
yarn add --dev eslint
Also you need babel-parser
and some plugins
yarn add --dev babel-eslint eslint-plugin-import eslint-plugin-fp
Finally, install this shareable config
yarn add --dev @sadorlovsky/eslint-config
Add this to your .eslintrc file:
{
"extends": "@sadorlovsky"
}
yarn add --dev eslint-plugin-ava
{
"extends": [
"@sadorlovsky",
"@sadorlovsky/eslint-config/ava"
]
}
yarn add --dev eslint-plugin-react
{
"extends": [
"@sadorlovsky",
"@sadorlovsky/eslint-config/react"
]
}
{
"extends": [
"@sadorlovsky",
"@sadorlovsky/eslint-config/ava",
"@sadorlovsky/eslint-config/react"
]
}
{
"extends": [
"@sadorlovsky",
"@sadorlovsky/eslint-config/ava",
"@sadorlovsky/eslint-config/react"
],
"rules": {
"semi": ["error", "always"]
}
}