UNPKG

16 kBMarkdownView Raw
1[![NPM version][npm-image]][npm-url]
2[![build status][travis-image]][travis-url]
3[![Build status][appveyor-image]][appveyor-url]
4[![Downloads][downloads-image]][downloads-url]
5[![Bountysource](https://www.bountysource.com/badge/tracker?tracker_id=282608)](https://www.bountysource.com/trackers/282608-eslint?utm_source=282608&utm_medium=shield&utm_campaign=TRACKER_BADGE)
6[![Join the chat at https://gitter.im/eslint/eslint](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/eslint/eslint?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
7[![FOSSA Status](https://app.fossa.io/api/projects/git%2Bhttps%3A%2F%2Fgithub.com%2Feslint%2Feslint.svg?type=shield)](https://app.fossa.io/projects/git%2Bhttps%3A%2F%2Fgithub.com%2Feslint%2Feslint?ref=badge_shield)
8
9# ESLint
10
11[Website](https://eslint.org) |
12[Configuring](https://eslint.org/docs/user-guide/configuring) |
13[Rules](https://eslint.org/docs/rules/) |
14[Contributing](https://eslint.org/docs/developer-guide/contributing) |
15[Reporting Bugs](https://eslint.org/docs/developer-guide/contributing/reporting-bugs) |
16[Code of Conduct](https://js.foundation/community/code-of-conduct) |
17[Twitter](https://twitter.com/geteslint) |
18[Mailing List](https://groups.google.com/group/eslint) |
19[Chat Room](https://gitter.im/eslint/eslint)
20
21ESLint is a tool for identifying and reporting on patterns found in ECMAScript/JavaScript code. In many ways, it is similar to JSLint and JSHint with a few exceptions:
22
23* ESLint uses [Espree](https://github.com/eslint/espree) for JavaScript parsing.
24* ESLint uses an AST to evaluate patterns in code.
25* ESLint is completely pluggable, every single rule is a plugin and you can add more at runtime.
26
27## Installation and Usage
28
29Prerequisites: [Node.js](https://nodejs.org/en/) (>=6.14), npm version 3+.
30
31There are two ways to install ESLint: globally and locally.
32
33### Local Installation and Usage
34
35If you want to include ESLint as part of your project's build system, we recommend installing it locally. You can do so using npm:
36
37```
38$ npm install eslint --save-dev
39```
40
41You should then set up a configuration file:
42
43```
44$ ./node_modules/.bin/eslint --init
45```
46
47After that, you can run ESLint on any file or directory like this:
48
49```
50$ ./node_modules/.bin/eslint yourfile.js
51```
52
53Any plugins or shareable configs that you use must also be installed locally to work with a locally-installed ESLint.
54
55### Global Installation and Usage
56
57If you want to make ESLint available to tools that run across all of your projects, we recommend installing ESLint globally. You can do so using npm:
58
59```
60$ npm install -g eslint
61```
62
63You should then set up a configuration file:
64
65```
66$ eslint --init
67```
68
69After that, you can run ESLint on any file or directory like this:
70
71```
72$ eslint yourfile.js
73```
74
75Any plugins or shareable configs that you use must also be installed globally to work with a globally-installed ESLint.
76
77**Note:** `eslint --init` is intended for setting up and configuring ESLint on a per-project basis and will perform a local installation of ESLint and its plugins in the directory in which it is run. If you prefer using a global installation of ESLint, any plugins used in your configuration must also be installed globally.
78
79## Configuration
80
81After running `eslint --init`, you'll have a `.eslintrc` file in your directory. In it, you'll see some rules configured like this:
82
83```json
84{
85 "rules": {
86 "semi": ["error", "always"],
87 "quotes": ["error", "double"]
88 }
89}
90```
91
92The names `"semi"` and `"quotes"` are the names of [rules](https://eslint.org/docs/rules) in ESLint. The first value is the error level of the rule and can be one of these values:
93
94* `"off"` or `0` - turn the rule off
95* `"warn"` or `1` - turn the rule on as a warning (doesn't affect exit code)
96* `"error"` or `2` - turn the rule on as an error (exit code will be 1)
97
98The three error levels allow you fine-grained control over how ESLint applies rules (for more configuration options and details, see the [configuration docs](https://eslint.org/docs/user-guide/configuring)).
99
100## Code of Conduct
101
102ESLint adheres to the [JS Foundation Code of Conduct](https://js.foundation/community/code-of-conduct).
103
104## Filing Issues
105
106Before filing an issue, please be sure to read the guidelines for what you're reporting:
107
108* [Bug Report](https://eslint.org/docs/developer-guide/contributing/reporting-bugs)
109* [Propose a New Rule](https://eslint.org/docs/developer-guide/contributing/new-rules)
110* [Proposing a Rule Change](https://eslint.org/docs/developer-guide/contributing/rule-changes)
111* [Request a Change](https://eslint.org/docs/developer-guide/contributing/changes)
112
113## Frequently Asked Questions
114
115### I'm using JSCS, should I migrate to ESLint?
116
117Maybe, depending on how much you need it. [JSCS has reached end of life](https://eslint.org/blog/2016/07/jscs-end-of-life), but if it is working for you then there is no reason to move yet. There are still [a few issues](https://github.com/eslint/eslint/milestones/JSCS%20Compatibility) pending. We’ll announce when all of the changes necessary to support JSCS users in ESLint are complete and will start encouraging JSCS users to switch to ESLint at that time.
118
119If you are having issues with JSCS, you can try to move to ESLint. Have a look at our [migration guide](https://eslint.org/docs/user-guide/migrating-from-jscs).
120
121### Does Prettier replace ESLint?
122
123No, ESLint does both traditional linting (looking for problematic patterns) and style checking (enforcement of conventions). You can use ESLint for everything, or you can combine both using Prettier to format your code and ESLint to catch possible errors.
124
125### Why can't ESLint find my plugins?
126
127ESLint can be [globally or locally installed](#installation-and-usage). If you install ESLint globally, your plugins must also be installed globally; if you install ESLint locally, your plugins must also be installed locally.
128
129If you are trying to run globally, make sure your plugins are installed globally (use `npm ls -g`).
130
131If you are trying to run locally:
132
133* Make sure your plugins (and ESLint) are both in your project's `package.json` as devDependencies (or dependencies, if your project uses ESLint at runtime).
134* Make sure you have run `npm install` and all your dependencies are installed.
135
136In all cases, make sure your plugins' peerDependencies have been installed as well. You can use `npm view eslint-plugin-myplugin peerDependencies` to see what peer dependencies `eslint-plugin-myplugin` has.
137
138### Does ESLint support JSX?
139
140Yes, ESLint natively supports parsing JSX syntax (this must be enabled in [configuration](https://eslint.org/docs/user-guide/configuring)). Please note that supporting JSX syntax *is not* the same as supporting React. React applies specific semantics to JSX syntax that ESLint doesn't recognize. We recommend using [eslint-plugin-react](https://www.npmjs.com/package/eslint-plugin-react) if you are using React and want React semantics.
141
142### What ECMAScript versions does ESLint support?
143
144ESLint has full support for ECMAScript 3, 5 (default), 2015, 2016, 2017, and 2018. You can set your desired ECMAScript syntax (and other settings, like global variables or your target environments) through [configuration](https://eslint.org/docs/user-guide/configuring).
145
146### What about experimental features?
147
148ESLint's parser only officially supports the latest final ECMAScript standard. We will make changes to core rules in order to avoid crashes on stage 3 ECMAScript syntax proposals (as long as they are implemented using the correct experimental ESTree syntax). We may make changes to core rules to better work with language extensions (such as JSX, Flow, and TypeScript) on a case-by-case basis.
149
150In other cases (including if rules need to warn on more or fewer cases due to new syntax, rather than just not crashing), we recommend you use other parsers and/or rule plugins. If you are using Babel, you can use the [babel-eslint](https://github.com/babel/babel-eslint) parser and [eslint-plugin-babel](https://github.com/babel/eslint-plugin-babel) to use any option available in Babel.
151
152Once a language feature has been adopted into the ECMAScript standard (stage 4 according to the [TC39 process](https://tc39.github.io/process-document/)), we will accept issues and pull requests related to the new feature, subject to our [contributing guidelines](https://eslint.org/docs/developer-guide/contributing). Until then, please use the appropriate parser and plugin(s) for your experimental feature.
153
154### Where to ask for help?
155
156Join our [Mailing List](https://groups.google.com/group/eslint) or [Chatroom](https://gitter.im/eslint/eslint).
157
158## Releases
159
160We have scheduled releases every two weeks on Friday or Saturday. You can follow a [release issue](https://github.com/eslint/eslint/issues?q=is%3Aopen+is%3Aissue+label%3Arelease) for updates about the scheduling of any particular release.
161
162## Semantic Versioning Policy
163
164ESLint follows [semantic versioning](https://semver.org). However, due to the nature of ESLint as a code quality tool, it's not always clear when a minor or major version bump occurs. To help clarify this for everyone, we've defined the following semantic versioning policy for ESLint:
165
166* Patch release (intended to not break your lint build)
167 * A bug fix in a rule that results in ESLint reporting fewer errors.
168 * A bug fix to the CLI or core (including formatters).
169 * Improvements to documentation.
170 * Non-user-facing changes such as refactoring code, adding, deleting, or modifying tests, and increasing test coverage.
171 * Re-releasing after a failed release (i.e., publishing a release that doesn't work for anyone).
172* Minor release (might break your lint build)
173 * A bug fix in a rule that results in ESLint reporting more errors.
174 * A new rule is created.
175 * A new option to an existing rule that does not result in ESLint reporting more errors by default.
176 * An existing rule is deprecated.
177 * A new CLI capability is created.
178 * New capabilities to the public API are added (new classes, new methods, new arguments to existing methods, etc.).
179 * A new formatter is created.
180* Major release (likely to break your lint build)
181 * `eslint:recommended` is updated.
182 * A new option to an existing rule that results in ESLint reporting more errors by default.
183 * An existing formatter is removed.
184 * Part of the public API is removed or changed in an incompatible way.
185
186According to our policy, any minor update may report more errors than the previous release (ex: from a bug fix). As such, we recommend using the tilde (`~`) in `package.json` e.g. `"eslint": "~3.1.0"` to guarantee the results of your builds.
187
188## License
189
190[![FOSSA Status](https://app.fossa.io/api/projects/git%2Bhttps%3A%2F%2Fgithub.com%2Feslint%2Feslint.svg?type=large)](https://app.fossa.io/projects/git%2Bhttps%3A%2F%2Fgithub.com%2Feslint%2Feslint?ref=badge_large)
191
192## Team
193
194These folks keep the project moving and are resources for help.
195
196<!-- NOTE: This section is autogenerated. Do not manually edit.-->
197<!--teamstart-->
198
199### Technical Steering Committee (TSC)
200
201The people who manage releases, review feature requests, and meet regularly to ensure ESLint is properly maintained.
202
203<table><tbody><tr><td align="center" valign="top" width="11%">
204<a href="https://github.com/nzakas">
205<img src="https://github.com/nzakas.png?s=75" width="75" height="75"><br />
206Nicholas C. Zakas
207</a>
208</td><td align="center" valign="top" width="11%">
209<a href="https://github.com/platinumazure">
210<img src="https://github.com/platinumazure.png?s=75" width="75" height="75"><br />
211Kevin Partington
212</a>
213</td><td align="center" valign="top" width="11%">
214<a href="https://github.com/ilyavolodin">
215<img src="https://github.com/ilyavolodin.png?s=75" width="75" height="75"><br />
216Ilya Volodin
217</a>
218</td><td align="center" valign="top" width="11%">
219<a href="https://github.com/btmills">
220<img src="https://github.com/btmills.png?s=75" width="75" height="75"><br />
221Brandon Mills
222</a>
223</td><td align="center" valign="top" width="11%">
224<a href="https://github.com/mysticatea">
225<img src="https://github.com/mysticatea.png?s=75" width="75" height="75"><br />
226Toru Nagashima
227</a>
228</td><td align="center" valign="top" width="11%">
229<a href="https://github.com/gyandeeps">
230<img src="https://github.com/gyandeeps.png?s=75" width="75" height="75"><br />
231Gyandeep Singh
232</a>
233</td><td align="center" valign="top" width="11%">
234<a href="https://github.com/kaicataldo">
235<img src="https://github.com/kaicataldo.png?s=75" width="75" height="75"><br />
236Kai Cataldo
237</a>
238</td><td align="center" valign="top" width="11%">
239<a href="https://github.com/not-an-aardvark">
240<img src="https://github.com/not-an-aardvark.png?s=75" width="75" height="75"><br />
241Teddy Katz
242</a>
243</td></tr></tbody></table>
244
245
246
247
248### Committers
249
250The people who review and fix bugs and help triage issues.
251
252<table><tbody><tr><td align="center" valign="top" width="11%">
253<a href="https://github.com/aladdin-add">
254<img src="https://github.com/aladdin-add.png?s=75" width="75" height="75"><br />
255薛定谔的猫
256</a>
257</td><td align="center" valign="top" width="11%">
258<a href="https://github.com/g-plane">
259<img src="https://github.com/g-plane.png?s=75" width="75" height="75"><br />
260Pig Fang
261</a>
262</td></tr></tbody></table>
263
264
265<!--teamend-->
266
267## Sponsors
268
269The following companies, organizations, and individuals support ESLint's ongoing maintenance and development. [Become a Sponsor](https://opencollective.com/eslint) to get your logo on our README and website.
270
271<!-- NOTE: This section is autogenerated. Do not manually edit.-->
272<!--sponsorsstart-->
273<h3>Gold Sponsors</h3>
274<p><a href="https://www.airbnb.com/"><img src="https://images.opencollective.com/proxy/images/?src=https%3A%2F%2Fopencollective-production.s3-us-west-1.amazonaws.com%2F098e3bd0-4d57-11e8-9324-0f6cc1f92bf1.png&height=96" alt="Airbnb" height="96"></a> <a href="https://code.facebook.com/projects/"><img src="https://images.opencollective.com/proxy/images/?src=https%3A%2F%2Fres.cloudinary.com%2Fopencollective%2Fimage%2Fupload%2Fv1508519428%2FS9gk78AS_400x400_fulq2l.jpg&height=96" alt="Facebook Open Source" height="96"></a> <a href="https://badoo.com/team?utm_source=eslint"><img src="https://images.opencollective.com/proxy/images/?src=https%3A%2F%2Fopencollective-production.s3-us-west-1.amazonaws.com%2Fbbdb9cc0-3b5d-11e9-9537-ad85092287b8.png&height=96" alt="Badoo" height="96"></a></p><h3>Silver Sponsors</h3>
275<p><a href="https://www.ampproject.org/"><img src="https://images.opencollective.com/proxy/images/?src=https%3A%2F%2Fopencollective-production.s3-us-west-1.amazonaws.com%2F68ed8b70-ebf2-11e6-9958-cb7e79408c56.png&height=96" alt="AMP Project" height="64"></a></p><h3>Bronze Sponsors</h3>
276<p><a href="http://faithlife.com/ref/about"><img src="https://images.opencollective.com/proxy/images/?src=https%3A%2F%2Flogo.clearbit.com%2Ffaithlife.com&height=96" alt="Faithlife" height="32"></a> <a href="https://jsheroes.io/"><img src="https://images.opencollective.com/proxy/images/?src=https%3A%2F%2Flogo.clearbit.com%2Fjsheroes.io&height=96" alt="JSHeroes " height="32"></a></p>
277<!--sponsorsend-->
278
279## Technology Sponsors
280
281* Site search ([eslint.org](https://eslint.org)) is sponsored by [Algolia](https://www.algolia.com)
282
283
284[npm-image]: https://img.shields.io/npm/v/eslint.svg?style=flat-square
285[npm-url]: https://www.npmjs.com/package/eslint
286[travis-image]: https://img.shields.io/travis/eslint/eslint/master.svg?style=flat-square
287[travis-url]: https://travis-ci.org/eslint/eslint
288[appveyor-image]: https://ci.appveyor.com/api/projects/status/iwxmiobcvbw3b0av/branch/master?svg=true
289[appveyor-url]: https://ci.appveyor.com/project/nzakas/eslint/branch/master
290[coveralls-image]: https://img.shields.io/coveralls/eslint/eslint/master.svg?style=flat-square
291[coveralls-url]: https://coveralls.io/r/eslint/eslint?branch=master
292[downloads-image]: https://img.shields.io/npm/dm/eslint.svg?style=flat-square
293[downloads-url]: https://www.npmjs.com/package/eslint