22.0.0 • Published 10 months ago

eslint-config-algolia v22.0.0

Weekly downloads
2,077
License
MIT
Repository
github
Last release
10 months ago

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-parser prettier \
eslint-config-algolia eslint-config-prettier \
eslint-plugin-import eslint-plugin-prettier \
eslint-plugin-eslint-comments eslint-plugin-jsdoc \
--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', 'algolia/jest']
};

package.json

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

React

terminal

yarn add eslint-plugin-react eslint-plugin-react-hooks eslint-plugin-jsx-a11y --dev

.eslintrc.js

module.exports = {
  extends: ['algolia', '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', 'algolia/flowtype']
};

Flow with React

terminal

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

.eslintrc.js

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

package.json

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

TypeScript

terminal

yarn add @typescript-eslint/parser @typescript-eslint/eslint-plugin typescript --dev

.eslintrc.js

module.exports = {
  extends: ['algolia', 'algolia/typescript']

  parserOptions: {
    project: '<path-to-tsconfig.json>',
  },
};

package.json

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

You also need to make sure that all the files you want to lint are also included in tsconfig.json with the include property.

TypeScript with React

terminal

yarn add @typescript-eslint/parser @typescript-eslint/eslint-plugin typescript eslint-plugin-react eslint-plugin-react-hooks eslint-plugin-jsx-a11y --dev

.eslintrc.js

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

Note: Be sure to put the algolia/typescript configuration last so the parser is properly set for TypeScript files.

package.json

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

Vue

terminal

yarn add eslint-plugin-vue --dev

.eslintrc.js

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

package.json

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

VSCode

{
  "eslint.validate": [
    {
      "language": "vue",
      "autoFix": true
    }
  ]
}

Node.js

package.json

{
  "scripts": {
    "test": "npm run lint",
    "lint": "eslint .",
    "lint:fix": "npm run lint -- --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.

Contributing

Test

We have a sample-project.

yarn test

Release

npm run release
22.0.0

10 months ago

21.0.0

1 year ago

20.1.0

1 year ago

20.0.0

2 years ago

19.0.1

3 years ago

19.0.0

3 years ago

19.0.2

3 years ago

18.0.0

3 years ago

17.0.1

3 years ago

17.0.0

3 years ago

16.0.0

4 years ago

15.0.0

5 years ago

14.0.1

5 years ago

14.0.0

5 years ago

13.4.0

5 years ago

13.3.0

5 years ago

13.2.3

6 years ago

13.2.2

6 years ago

13.2.1

6 years ago

13.2.0

6 years ago

13.1.0

6 years ago

13.0.1

6 years ago

13.0.0

6 years ago

13.0.0-beta.1

7 years ago

13.0.0-beta.0

7 years ago

12.0.0

7 years ago

12.0.0-beta.0

7 years ago

12.0.0-beta1

7 years ago

12.0.0-beta0

7 years ago

11.1.0-beta2

7 years ago

11.1.0-beta1

7 years ago

11.1.0-beta

7 years ago

11.0.0

7 years ago

11.0.1-beta

7 years ago

11.0.0-beta

7 years ago

10.1.0-next

7 years ago

10.1.0

7 years ago

10.0.0

7 years ago

9.0.0

7 years ago

8.0.0

7 years ago

7.0.3

7 years ago

7.0.2

7 years ago

7.0.1

7 years ago

7.0.0

7 years ago

6.0.1

8 years ago

6.0.0

8 years ago

5.5.1

8 years ago

5.5.0

8 years ago

5.4.0

8 years ago

5.3.1

8 years ago

5.3.0

8 years ago

5.2.2

8 years ago

5.2.1

8 years ago

5.2.0

8 years ago

5.1.0

8 years ago

5.0.0

8 years ago

4.7.0

8 years ago

4.6.0

8 years ago

4.5.0

8 years ago

4.4.0

8 years ago

4.3.3

8 years ago

4.3.2

8 years ago

4.3.1

8 years ago

4.3.0

8 years ago

4.2.0

9 years ago

4.1.0

9 years ago

4.0.0

9 years ago

3.0.0

9 years ago

2.2.0

9 years ago

2.1.2

9 years ago

2.1.1

9 years ago

2.1.0

9 years ago

2.0.4

9 years ago

2.0.3

9 years ago

2.0.2

9 years ago

2.0.1

9 years ago

2.0.0

9 years ago

1.0.1

9 years ago

1.0.0

9 years ago