Skip to content

sadorlovsky/codestyle

Repository files navigation

Sad Orlovsky Codestyle - ESLint Shareable Config

An ESLint Shareable Config for my preferable code style.

THE RULES OF FIGHT CLUB

  • Two spaces
  • Single quotes
  • No semicolons

See all rules here.

Nice code example

// 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

Usage

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

Use with AVA

yarn add --dev eslint-plugin-ava
{
  "extends": [
    "@sadorlovsky",
    "@sadorlovsky/eslint-config/ava"
  ]
}

Use with React

yarn add --dev eslint-plugin-react
{
  "extends": [
    "@sadorlovsky",
    "@sadorlovsky/eslint-config/react"
  ]
}

Use with both

{
  "extends": [
    "@sadorlovsky",
    "@sadorlovsky/eslint-config/ava",
    "@sadorlovsky/eslint-config/react"
  ]
}

You can override any option

{
  "extends": [
    "@sadorlovsky",
    "@sadorlovsky/eslint-config/ava",
    "@sadorlovsky/eslint-config/react"
  ],

  "rules": {
    "semi": ["error", "always"]
  }
}