]> git.proxmox.com Git - pve-eslint.git/blame - eslint/docs/src/use/migrating-from-jscs.md
import 8.41.0 source
[pve-eslint.git] / eslint / docs / src / use / migrating-from-jscs.md
CommitLineData
8f9d1d4d
DC
1---
2title: Migrating from JSCS
8f9d1d4d
DC
3
4---
eb39fafa
DC
5
6In April 2016, we [announced](https://eslint.org/blog/2016/04/welcoming-jscs-to-eslint) that the JSCS project was shutting down and the JSCS team would be joining the ESLint team. This guide is intended to help those who are using JSCS to migrate their settings and projects to use ESLint. We've tried to automate as much of the conversion as possible, but there are some manual changes that are needed.
7
8## Terminology
9
10Before beginning the process of migrating to ESLint, it's helpful to understand some of the terminology that ESLint uses and how it relates to terminology that JSCS uses.
11
12* **Configuration File** - In JSCS, the configuration file is `.jscsrc`, `.jscsrc.json`, `.jscsrc.yaml`, or `.jscsrs.js`. In ESLint, the configuration file can be `.eslintrc.json`, `.eslintrc.yml`, `.eslintrc.yaml`, or `.eslintrc.js` (there is also a deprecated `.eslintrc` file format).
f2a92ac6 13* **Presets** - In JSCS, there were numerous predefined configurations shipped directly within JSCS. ESLint ships with just one predefined configuration (`eslint:recommended`) that has no style rules enabled. However, ESLint does support [shareable configs](../extend/shareable-configs). Shareable configs are configurations that are published on their own to npm and there are shareable configs available for almost all of the JSCS presets (see [the "Converting Presets" section](#converting-presets) below). Additionally, the `preset` option in a configuration file is the equivalent of the ESLint `extends` option.
eb39fafa
DC
14
15## Convert Configuration Files Using Polyjuice
16
17[Polyjuice](https://github.com/brenolf/polyjuice) is a utility for converting JSCS (and JSHint) configuration files into ESLint configuration files automatically. It understands the equivalent rules from each utility and will automatically output an ESLint configuration file that is a good approximation of your existing JSCS file.
18
19To install Polyjuice:
20
8f9d1d4d
DC
21```shell
22npm install -g polyjuice
eb39fafa
DC
23```
24
25Polyjuice works with JSON configuration files, so if you're using a JavaScript or YAML JSCS configuration file, you should first convert it into a JSON configuration file.
26
27To convert your configuration file, pass in the location of your `.jscs.json` file using the `--jscs` flag:
28
8f9d1d4d
DC
29```shell
30polyjuice --jscs .jscsrc.json > .eslintrc.json
eb39fafa
DC
31```
32
f2a92ac6 33This creates an `.eslintrc.json` with the equivalent rules from `.jscsrc.json`.
eb39fafa
DC
34
35If you have multiple `.jscsrc.json` files, you can pass them all and Polyjuice will combine them into one `.eslintrc.json` file:
36
8f9d1d4d
DC
37```shell
38polyjuice --jscs .jscsrc.json ./foo/.jscsrc.json > .eslintrc.json
eb39fafa
DC
39```
40
8f9d1d4d 41**Note:** Polyjuice does a good job of creating a reasonable ESLint configuration from your JSCS configuration, but it may not be 100%. You may still see different warnings than you saw with JSCS, and so you may need to further modify your configuration after using Polyjuice. This is especially true if you're using inline comments to enable/disable certain rules in JSCS (you'll need to manually convert those to use ESLint-style comments instead, [see "Disabling Rules Inline"](#disabling-rules-inline) later in this page).
eb39fafa
DC
42
43### Creating a New Configuration From Scratch
44
45If you don't want to convert your JSCS configuration directly into an ESLint configuration, then you can use ESLint's built-in wizard to get you started. Just run:
46
8f9d1d4d
DC
47```shell
48npm init @eslint/config
eb39fafa
DC
49```
50
51You'll be guided through a series of questions that will help you setup a basic configuration file to get you started.
52
53## Converting Presets
54
55There are shareable configs available for most JSCS presets. The equivalent shareable configs for each JSCS preset are listed in the following table:
56
57| **JSCS Preset** | **ESLint Shareable Config** |
58|-----------------|-----------------------------|
59| `airbnb` | [`eslint-config-airbnb-base`](https://github.com/airbnb/javascript/tree/master/packages/eslint-config-airbnb-base) |
60| `crockford` | (not available) |
61| `google` | [`eslint-config-google`](https://github.com/google/eslint-config-google) |
62| `grunt` | [`eslint-config-grunt`](https://github.com/markelog/eslint-config-grunt) |
63| `idiomatic` | [`eslint-config-idiomatic`](https://github.com/jamespamplin/eslint-config-idiomatic) |
64| `jquery` | [`eslint-config-jquery`](https://github.com/jquery/eslint-config-jquery) |
65| `mdcs` | [`eslint-config-mdcs`](https://github.com/zz85/mrdoobapproves) |
66| `node-style-guide` | [`eslint-config-node-style-guide`](https://github.com/pdehaan/eslint-config-node-style-guide) |
67| `wikimedia` | [`eslint-config-wikimedia`](https://github.com/wikimedia/eslint-config-wikimedia) |
68| `wordpress` | [`eslint-config-wordpress`](https://github.com/WordPress-Coding-Standards/eslint-config-wordpress) |
69
70As an example, suppose that you are using the `airbnb` preset, so your `.jscsrc` file looks like this:
71
72```json
73{
74 "preset": "airbnb"
75}
76```
77
78In order to get the same functionality in ESLint, you would first need to install the `eslint-config-airbnb` shareable config package:
79
8f9d1d4d
DC
80```shell
81npm install eslint-config-airbnb-base --save-dev
eb39fafa
DC
82```
83
84And then you would modify your configuration file like this:
85
86```json
87{
88 "extends": "airbnb-base"
89}
90```
91
92ESLint sees `"airbnb-base"` and will look for `eslint-config-airbnb-base` (to save you some typing).
93
94## Disabling Rules Inline
95
96Both JSCS and ESLint use comments inside of files to disable rules around certain parts of your code. The following table lists out the JSCS inline configuration comments and their ESLint equivalents.
97
98| **Description** | **JSCS Comment** | **ESLint Comment** |
99|-----------------|------------------|--------------------|
100| Disable all rules | `// jscs:disable` or `/* jscs:disable */` | `/* eslint-disable */` |
101| Enable all rules | `// jscs:enable` or `/* jscs:enable */` | `/* eslint-enable */` |
102| Disable one rule | `// jscs:disable ruleName` or `/* jscs:disable ruleName */` | `/* eslint-disable rule-name */` |
103| Enable one rule | `// jscs:enable ruleName` or `/* jscs:enable ruleName */` | `/* eslint-enable rule-name */` |
104| Disable multiple rules | `// jscs:disable ruleName1, ruleName2` or `/* jscs:disable ruleName1, ruleName2 */` | `/* eslint-disable rule-name1, rule-name2 */` |
105| Enable multiple rules | `// jscs:enable ruleName1, ruleName2` or `/* jscs:enable ruleName1, ruleName2 */` | `/* eslint-enable rule-name1, rule-name2 */` |
106| Disable one rule on single line | `// jscs:ignore ruleName` | `// eslint-disable-line rule-name` |
107
108## Command Line Options
109
110Both JSCS and ESLint have command line arguments corresponding to many of their configuration options. The following are the ESLint equivalents of JSCS command line options.
111
112### `--fix`
113
114JSCS uses the `--fix` option to apply automatic fixes to code:
115
8f9d1d4d
DC
116```shell
117jscs --fix file.js
eb39fafa
DC
118```
119
120ESLint has the same option:
121
8f9d1d4d
DC
122```shell
123eslint --fix file.js
eb39fafa
DC
124```
125
126### `--auto-configure`
127
128The JSCS `--auto-configure` option created a configuration based on what it found in a given file:
129
8f9d1d4d
DC
130```shell
131jscs --auto-configure file.js
eb39fafa
DC
132```
133
134In ESLint, there's a similar option when you use `--init`. Just select "Inspect your JavaScript file(s)":
135
8f9d1d4d
DC
136```shell
137eslint --init
eb39fafa
DC
138? How would you like to configure ESLint? (Use arrow keys)
139> Answer questions about your style
140 Use a popular style guide
141 Inspect your JavaScript file(s)
142```
143
144## `--config`, `-c`
145
146JSCS allows you to specify a configuration file to use on the command line using either `--config` or `-c`, such as:
147
8f9d1d4d
DC
148```shell
149jscs --config myconfig.json file.js
150jscs -c myconfig.json file.js
eb39fafa
DC
151```
152
153Both flags are also supported by ESLint:
154
8f9d1d4d
DC
155```shell
156eslint --config myconfig.json file.js
157eslint -c myconfig.json file.js
eb39fafa
DC
158```
159
eb39fafa
DC
160## Piping Code Into ESLint
161
162In JSCS, you can pipe code in like this:
163
8f9d1d4d
DC
164```shell
165cat file.js | jscs
eb39fafa
DC
166```
167
168In ESLint, you can also pipe in code, but you need to use the `--stdin` flag:
169
8f9d1d4d
DC
170```shell
171cat file.js | eslint --stdin
eb39fafa 172```