Code Monkey home page Code Monkey logo

eslint-config-algolia's Introduction

eslint-config-algolia

Version Build Status License Downloads

This is Algolia's linting and formatting of JavaScript projects (Vanilla, React, Vue) repository.

It explains to you how to setup your project to use it and never worry again about indentation, curly spaces, let vs const etc...

This code style is only as useful as you activate travis for your project so that it runs linting in your test phase and warns you.

Just focus on coding.

Table of Contents

Setup your project

Base requirements

yarn add \
eslint babel-eslint prettier \
eslint-config-algolia eslint-config-prettier \
eslint-plugin-import eslint-plugin-prettier \
--dev

Vanilla

.eslintrc.js

module.exports = {
  extends: 'algolia'
};

package.json

{
  "scripts": {
    "test": "npm run lint",
    "lint": "eslint .",
    "lint:fix": "npm run lint -- --fix"
  }
}

Jest

We recommend using Jest as a test runner.

terminal

yarn add eslint-plugin-jest --dev

.eslintrc.js

module.exports = {
  extends: 'algolia/jest'
};

package.json

{
  "scripts": {
    "test": "npm run lint",
    "lint": "eslint .",
    "lint:fix": "npm run lint -- --fix"
  }
}

React

terminal

yarn add eslint-plugin-react --dev

.eslintrc.js

module.exports = {
  extends: 'algolia/react'
};

package.json

{
  "scripts": {
    "test": "npm run lint",
    "lint": "eslint .",
    "lint:fix": "npm run lint -- --fix"
  }
}

Flow

terminal

yarn add eslint-plugin-flowtype --dev

.eslintrc.js

module.exports = {
  extends: 'algolia/flowtype'
};

Flow with React

terminal

yarn add eslint-plugin-flowtype eslint-plugin-react --dev

.eslintrc.js

module.exports = {
  extends: ['algolia/flowtype', 'algolia/react']
};

package.json

{
  "scripts": {
    "test": "npm run lint",
    "lint": "eslint .",
    "lint:fix": "npm run lint -- --fix"
  }
}

Vue

terminal

yarn add eslint-plugin-html --dev

.eslintrc.js

module.exports = {
  extends: 'algolia/vue'
};

package.json

{
  "scripts": {
    "test": "npm run lint",
    "lint": "eslint --ext .js,.vue .",
    "lint:fix": "eslint --ext .js,.vue . --fix"
  }
}

Drawbacks: prettier will format first line of script tags badly, they are working on it.

We will soon afterwards switch to good prettier formatting for vue and proper eslint-plugin-vue. Those are all in the works but this setup already provides good defaults.

Please also check "Lint HTML files" in your linter, that should lint '.vue' files.

Node.js

package.json

{
  "scripts": {
    "test": "npm run lint",
    "lint": "eslint --ext .js,.vue .",
    "lint:fix": "eslint --ext .js,.vue . --fix"
  }
}

.eslintrc.js

module.exports = {
  extends: 'algolia',
  rules: {
    'import/no-commonjs': 'off'
  }
};

Existing codebase setup

If you have a lot of files already written and wants to now use our linting tools, you might have a lot of errors. There's hope!

Just reformat all the files automatically and then manually fix remaining errors.

terminal

npm run lint:fix

Setup autofix in IDE

Don't overlook this part, autofixing on save is a huge productivity boost.

Use any ESLint integration and activate "Fix on save" option.

Also activate "Lint HTML files" when dealing with .vue components.

Ignoring files

See "Ignoring Files and Directories" on ESLint website.

Contibuting

Test

We have a sample-project.

yarn test

Release

npm run release

eslint-config-algolia's People

Contributors

greenkeeperio-bot avatar haroenv avatar iam4x avatar jerska avatar pixelastic avatar rayrutjes avatar vvo avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.