]> git.proxmox.com Git - pve-eslint.git/blob - eslint/docs/src/user-guide/getting-started.md
import 8.23.1 source
[pve-eslint.git] / eslint / docs / src / user-guide / getting-started.md
1 ---
2 title: Getting Started with ESLint
3 layout: doc
4 eleventyNavigation:
5 key: getting started
6 parent: user guide
7 title: Getting Started
8 order: 1
9
10 ---
11
12 ESLint is a tool for identifying and reporting on patterns found in ECMAScript/JavaScript code, with the goal of making code more consistent and avoiding bugs. In many ways, it is similar to JSLint and JSHint with a few exceptions:
13
14 * ESLint uses [Espree](https://github.com/eslint/espree) for JavaScript parsing.
15 * ESLint uses an AST to evaluate patterns in code.
16 * ESLint is completely pluggable, every single rule is a plugin and you can add more at runtime.
17
18 ## Installation and Usage
19
20 Prerequisites: [Node.js](https://nodejs.org/en/) (`^12.22.0`, `^14.17.0`, or `>=16.0.0`) built with SSL support. (If you are using an official Node.js distribution, SSL is always built in.)
21
22 You can install and configure ESLint using this command:
23
24 ```shell
25 npm init @eslint/config
26 ```
27
28 **Note:** `npm init @eslint/config` assumes you have a `package.json` file already. If you don't, make sure to run `npm init` or `yarn init` beforehand.
29
30 After that, you can run ESLint on any file or directory like this:
31
32 ```shell
33 npx eslint yourfile.js
34
35 # or
36
37 yarn run eslint yourfile.js
38 ```
39
40 It is also possible to install ESLint globally rather than locally (using `npm install eslint --global`). However, this is not recommended, and any plugins or shareable configs that you use must be installed locally in either case.
41
42 ## Configuration
43
44 **Note:** If you are coming from a version before 1.0.0 please see the [migration guide](migrating-to-1.0.0).
45
46 After running `npm init @eslint/config`, you'll have a `.eslintrc.{js,yml,json}` file in your directory. In it, you'll see some rules configured like this:
47
48 ```json
49 {
50 "rules": {
51 "semi": ["error", "always"],
52 "quotes": ["error", "double"]
53 }
54 }
55 ```
56
57 The names `"semi"` and `"quotes"` are the names of [rules](/docs/rules) in ESLint. The first value is the error level of the rule and can be one of these values:
58
59 * `"off"` or `0` - turn the rule off
60 * `"warn"` or `1` - turn the rule on as a warning (doesn't affect exit code)
61 * `"error"` or `2` - turn the rule on as an error (exit code will be 1)
62
63 The three error levels allow you fine-grained control over how ESLint applies rules (for more configuration options and details, see the [configuration docs](configuring/)).
64
65 Your `.eslintrc.{js,yml,json}` configuration file will also include the line:
66
67 ```json
68 {
69 "extends": "eslint:recommended"
70 }
71 ```
72
73 Because of this line, all of the rules marked "(recommended)" on the [rules page](/docs/rules) will be turned on. Alternatively, you can use configurations that others have created by searching for "eslint-config" on [npmjs.com](https://www.npmjs.com/search?q=eslint-config). ESLint will not lint your code unless you extend from a shared configuration or explicitly turn rules on in your configuration.
74
75 ---
76
77 ## Next Steps
78
79 * Learn about [advanced configuration](configuring/) of ESLint.
80 * Get familiar with the [command line options](command-line-interface).
81 * Explore [ESLint integrations](integrations) into other tools like editors, build systems, and more.
82 * Can't find just the right rule? Make your own [custom rule](/docs/developer-guide/working-with-rules).
83 * Make ESLint even better by [contributing](/docs/developer-guide/contributing/).