UNPKG

4.1 kBMarkdownView Raw
1# eslint-config-egg
2
3Node Style Guide for Egg.
4
5## Install
6
7```bash
8npm i eslint eslint-config-egg --save-dev
9```
10
11## Usage
12
13- `package.json`
14
15```json
16{
17 "devDependencies": {
18 "eslint-config-egg": "7",
19 "eslint": "4"
20 }
21}
22```
23
24- `.eslintrc.js`
25
26```js
27module.exports = {
28 extends: 'eslint-config-egg',
29};
30```
31
32### Use with TypeScript project
33
34- `package.json`
35
36```json
37{
38 "devDependencies": {
39 "eslint-config-egg": "7",
40 "typescript": "^3.5.3"
41 }
42}
43```
44
45- `.eslintrc.js`
46
47```js
48module.exports = {
49 extends: 'eslint-config-egg/typescript',
50 parserOptions: {
51 // recommend to use another config file like tsconfig.eslint.json and extends tsconfig.json in it.
52 // because you may be need to lint test/**/*.test.ts but no need to emit to js.
53 // @see https://github.com/typescript-eslint/typescript-eslint/issues/890
54 project: './tsconfig.json'
55 }
56};
57```
58
59- `scripts`
60
61```json
62{
63 "lint": "eslint . --ext .ts"
64}
65```
66
67- `settings.json` in vscode
68
69```json
70{
71 "eslint.validate": [
72 "javascript",
73 "javascriptreact",
74 {
75 "language": "typescript",
76 "autoFix": true
77 },
78 ]
79}
80```
81
82### Use with Experimental Features
83
84If you want to use eslint-config-egg with experimental features such as `async function`, you should use `babel-eslint` parser:
85
86- `package.json`
87
88```json
89{
90 "devDependencies": {
91 "eslint-config-egg": "7",
92 "eslint": "4",
93 "babel-eslint": "8"
94 }
95}
96```
97
98- `.eslintrc.js`
99
100```js
101module.exports = {
102 extends: 'eslint-config-egg',
103 // for experimental features support
104 parser: 'babel-eslint',
105 rules: {
106 // see https://github.com/eslint/eslint/issues/6274
107 'generator-star-spacing': 'off',
108 'babel/generator-star-spacing': 'off',
109 }
110};
111```
112
113### Use with React in Front-End
114
115If you want to use eslint-config-egg with react, jsx and es6 modules:
116
117- `package.json`
118
119```json
120{
121 "devDependencies": {
122 "eslint-config-egg": "7",
123 "eslint": "4",
124 "babel-eslint": "8",
125 "eslint-plugin-react": "7"
126 }
127}
128```
129
130- `.eslintrc.js`
131
132```js
133module.exports = {
134 extends: 'eslint-config-egg',
135 // for experimental features support
136 parser: 'babel-eslint',
137 parserOptions: {
138 // for es6 module
139 sourceType: 'module',
140 },
141 plugins: [
142 'react',
143 ],
144 rules: {
145 // for variables in jsx
146 'react/jsx-uses-vars': 'error',
147 // see https://github.com/eslint/eslint/issues/6274
148 'generator-star-spacing': 'off',
149 'babel/generator-star-spacing': 'off',
150 },
151};
152```
153
154## License
155
156[MIT](LICENSE)
157
158<!-- GITCONTRIBUTOR_START -->
159
160## Contributors
161
162|[<img src="https://avatars1.githubusercontent.com/u/360661?v=4" width="100px;"/><br/><sub><b>popomore</b></sub>](https://github.com/popomore)<br/>|[<img src="https://avatars0.githubusercontent.com/u/156269?v=4" width="100px;"/><br/><sub><b>fengmk2</b></sub>](https://github.com/fengmk2)<br/>|[<img src="https://avatars2.githubusercontent.com/u/227713?v=4" width="100px;"/><br/><sub><b>atian25</b></sub>](https://github.com/atian25)<br/>|[<img src="https://avatars0.githubusercontent.com/u/3580607?v=4" width="100px;"/><br/><sub><b>benjycui</b></sub>](https://github.com/benjycui)<br/>|[<img src="https://avatars0.githubusercontent.com/u/3274850?v=4" width="100px;"/><br/><sub><b>geekdada</b></sub>](https://github.com/geekdada)<br/>|[<img src="https://avatars3.githubusercontent.com/u/985607?v=4" width="100px;"/><br/><sub><b>dead-horse</b></sub>](https://github.com/dead-horse)<br/>|
163| :---: | :---: | :---: | :---: | :---: | :---: |
164[<img src="https://avatars1.githubusercontent.com/u/10082151?v=4" width="100px;"/><br/><sub><b>bowei-jbw</b></sub>](https://github.com/bowei-jbw)<br/>|[<img src="https://avatars2.githubusercontent.com/u/13050025?v=4" width="100px;"/><br/><sub><b>aladdin-add</b></sub>](https://github.com/aladdin-add)<br/>|[<img src="https://avatars1.githubusercontent.com/u/143572?v=4" width="100px;"/><br/><sub><b>hotoo</b></sub>](https://github.com/hotoo)<br/>
165
166This project follows the git-contributor [spec](https://github.com/xudafeng/git-contributor), auto updated at `Mon Mar 11 2019 15:51:28 GMT+0800`.
167
168<!-- GITCONTRIBUTOR_END -->