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