UNPKG

2.26 kBMarkdownView Raw
1# @tokenfoundry/eslint-config
2
3Please use this configuration to maintain a common and homogeneous code base.
4
5## Install
6
7Install this package as any other package with:
8
9```sh
10yarn add --dev eslint @tokenfoundry/eslint-config
11```
12
13Create a `.eslintignore` and add any files that are bundled, builded and/or _transpiled_:
14
15```txt
16!.eslintrc.js # allow self-formating
17
18dist
19lib
20```
21
22In the `package.json` file add the following in the `"scripts"` section:
23
24```json
25 {
26 // ...
27 "scripts": {
28 // ...
29 "lint": "eslint src .eslintrc.js"
30 },
31 }
32```
33
34> Assuming that the main code is in the `src` directory, change as needed.
35
36### Configure for Node.js
37
38Create a `.eslintrc.js` file in the root of your project and add the following:
39
40```js
41// .eslintrc.js
42
43module.exports = {
44 extends: ["@tokenfoundry/eslint-config"],
45};
46```
47
48### Configure for ESNext (Babel) projects
49
50Create a `.eslintrc.js` file in the root of your project and add the following:
51
52```js
53// .eslintrc.js
54
55module.exports = {
56 extends: ["@tokenfoundry/eslint-config/babel"],
57};
58```
59
60### Configure for React.js and React-Native
61
62Create a `.eslintrc.js` file in the root of your project and add the following:
63
64```js
65// .eslintrc.js
66
67module.exports = {
68 extends: ["@tokenfoundry/eslint-config/react"],
69};
70```
71
72## Usage
73
74To lint the files run:
75
76```sh
77yarn lint
78```
79
80To lint the files and **auto-format** run:
81
82```sh
83yarn lint --fix
84```
85
86### Recommended usage
87
88Install [`typicode/husky`](https://github.com/typicode/husky) so you always have to run the linter before committing:
89
90```sh
91yarn add --dev husky@next
92```
93
94And add to the `package.json`:
95
96```json
97 {
98 // ...
99 "scripts": {
100 // ...
101 "lint": "eslint src .eslintrc.js"
102 },
103 "husky": {
104 "hooks": {
105 "pre-commit": "yarn lint"
106 }
107 },
108}
109```
110
111### Custom rules
112
113Modify the `.eslintrc.js` and add a `"rules"` field:
114
115```js
116// .eslintrc.js
117
118module.exports = {
119 extends: ["@tokenfoundry/eslint-config/react"],
120 rules: [
121 "react/prop-types": 0, // disabled
122 "react/display-name": 1, // warning
123 "react/jsx-boolean-value": 2, // throw error
124 ],
125};
126```
127
128## Publishing
129
130To publish and update of this package run:
131
132```sh
133# git add ...
134# git commit ...
135
136yarn publish --access=public
137git push --follow-tags
138```