1 | <div align="center">
|
2 | <img width="500" src="https://cdn.rawgit.com/crystal-ball/eslint-config-eloquence/master/assets/logos.png" alt="Extends Airbnb code quality rules with Prettier.js formatting">
|
3 | </div>
|
4 |
|
5 | # Crystal Ball ESLint Configs
|
6 | [![styled with prettier](https://img.shields.io/badge/styled_with-prettier-ff69b4.svg)](https://github.com/prettier/prettier)
|
7 |
|
8 | ## Installing:
|
9 | Add the package and Prettier as a dev dependencies to your project:
|
10 | ```sh
|
11 | npm i eslint-config-healthsparq prettier -D
|
12 | ```
|
13 | _We recommend adding Prettier as a project dependency. (Some editors will only use
|
14 | Prettier as a dependency if it is in the `package.json`)_
|
15 |
|
16 | If you are using the web configs, install the webpack resolver as well:
|
17 | ```sh
|
18 | npm i eslint-import-resolver-webpack -D
|
19 | ```
|
20 |
|
21 | #### Flow
|
22 | Static typing using flow is supported through the `eslint-plugin-import` package.
|
23 |
|
24 | ## Usage
|
25 | Extending this package's config will handle setting the base parserOptions, parser,
|
26 | plugins and env. There are seperate configs for Node projects and web projects
|
27 | to handle turning on/off features like JSX, webpack resolving, `.mjs` file
|
28 | extensions, etc. The configs are `node` and `web` and can be extended like so:
|
29 |
|
30 | #### Webpack Project
|
31 | ```javascript
|
32 | // .eslintrc.js
|
33 | module.exports = { extends: '@crystal-ball/eloquence/web' }
|
34 | ```
|
35 | #### Node Project
|
36 | ```javascript
|
37 | // .eslintrc.js
|
38 | module.exports = { extends: '@crystal-ball/eloquence/node' }
|
39 | ```
|
40 |
|
41 | #### Overriden Rules
|
42 | The only Airbnb code quality rule that is overriden is setting
|
43 | [no-use-before-define](https://eslint.org/docs/rules/no-use-before-define) to
|
44 | `{ functions: false }`. This allows propTypes of
|
45 | stateless functional components to be decalred before the component defintion using
|
46 | a function declarartion:
|
47 |
|
48 | ```javascript
|
49 | Radical.propTypes = {
|
50 | name: string.isRequired
|
51 | }
|
52 |
|
53 | export default function Radical({ name }) {
|
54 | return <h1>{name} is RADICAL!</h1>
|
55 | }
|
56 | ```
|
57 |
|
58 | This lets us always declare our prop types before the component definition, which
|
59 | is helpful when evaluating some new component.
|
60 |
|
61 | #### Dependencies
|
62 | All dependencies required for running ESLint will be installed as dependencies of
|
63 | this package. This ensures that there are no conflicting versions of ESLint in a
|
64 | consuming project's dependencies. Installed dependencies include:
|
65 | - eslint
|
66 | - babel-eslint
|
67 | - eslint-config-airbnb
|
68 | - eslint-config-prettier
|
69 | - eslint-plugin-flowtype
|
70 | - eslint-plugin-import
|
71 | - eslint-plugin-jsx-a11y
|
72 | - eslint-plugin-prettier
|
73 | - eslint-plugin-react
|
74 |
|
75 | ## TypeScript
|
76 | Linting for TypeScript is an opt-in. First, add the ESLint TS parser:
|
77 |
|
78 | ```shell
|
79 | npm i typescript-eslint-parser
|
80 | ```
|
81 |
|
82 | Then extend the TyepScript configuration:
|
83 |
|
84 | ```javascript
|
85 | // .eslintrc.js
|
86 | module.exports = {
|
87 | extends: '@crystal-ball/eloquence/typescript'
|
88 | }
|
89 | ```
|