]> git.proxmox.com Git - pve-eslint.git/blame - eslint/docs/src/user-guide/migrating-to-1.0.0.md
build: add missing dh-nodejs to build-dependencies
[pve-eslint.git] / eslint / docs / src / user-guide / migrating-to-1.0.0.md
CommitLineData
8f9d1d4d
DC
1---
2title: Migrating to v1.0.0
3layout: doc
4
5---
eb39fafa
DC
6
7ESLint v1.0.0 is the first major version release. As a result, there are some significant changes between how ESLint worked during its life in 0.x and how it will work going forward. These changes are the direct result of feedback from the ESLint community of users and were not made without due consideration for the upgrade path. We believe that these changes make ESLint even better, and while some work is necessary to upgrade, we hope the pain of this upgrade is small enough that you will see the benefit of upgrading.
8
9## All Rules Off by Default
10
11The most important difference in v1.0.0 is that all rules are off by default. We made this change after numerous requests to allow turning off the default rules from within configuration files. While that wasn't technically feasible, it was feasible to have all rules off by default and then re-enable rules in configuration files using `extends`. As such, we've made the `--reset` behavior the default and removed this command line option.
12
13When using `--init`, your configuration file will automatically include the following line:
14
15```json
16{
17 "extends": "eslint:recommended"
18}
19```
20
21This setting mimics some of the default behavior from 0.x, but not all. If you don't want to use any of the recommended rules, you can delete this line.
22
23**To address:** If you are currently using `--reset`, then you should stop passing `--reset` on the command line; no other changes are necessary. If you are not using `--reset`, then you should review your configuration to determine which rules should be on by default. You can partially restore some of the default behavior by adding the following to your configuration file:
24
25The `"eslint:recommended"` configuration contains many of the same default rule settings from 0.x, but not all. These rules are no longer on by default, so you should review your settings to ensure they are still as you expect:
26
27* [no-alert](https://eslint.org/docs/rules/no-alert)
28* [no-array-constructor](https://eslint.org/docs/rules/no-array-constructor)
29* [no-caller](https://eslint.org/docs/rules/no-caller)
30* [no-catch-shadow](https://eslint.org/docs/rules/no-catch-shadow)
31* [no-empty-label](https://eslint.org/docs/rules/no-empty-label)
32* [no-eval](https://eslint.org/docs/rules/no-eval)
33* [no-extend-native](https://eslint.org/docs/rules/no-extend-native)
34* [no-extra-bind](https://eslint.org/docs/rules/no-extra-bind)
35* [no-extra-strict](https://eslint.org/docs/rules/no-extra-strict)
36* [no-implied-eval](https://eslint.org/docs/rules/no-implied-eval)
37* [no-iterator](https://eslint.org/docs/rules/no-iterator)
38* [no-label-var](https://eslint.org/docs/rules/no-label-var)
39* [no-labels](https://eslint.org/docs/rules/no-labels)
40* [no-lone-blocks](https://eslint.org/docs/rules/no-lone-blocks)
41* [no-loop-func](https://eslint.org/docs/rules/no-loop-func)
42* [no-multi-spaces](https://eslint.org/docs/rules/no-multi-spaces)
43* [no-multi-str](https://eslint.org/docs/rules/no-multi-str)
44* [no-native-reassign](https://eslint.org/docs/rules/no-native-reassign)
45* [no-new](https://eslint.org/docs/rules/no-new)
46* [no-new-func](https://eslint.org/docs/rules/no-new-func)
47* [no-new-object](https://eslint.org/docs/rules/no-new-object)
48* [no-new-wrappers](https://eslint.org/docs/rules/no-new-wrappers)
49* [no-octal-escape](https://eslint.org/docs/rules/no-octal-escape)
50* [no-process-exit](https://eslint.org/docs/rules/no-process-exit)
51* [no-proto](https://eslint.org/docs/rules/no-proto)
52* [no-return-assign](https://eslint.org/docs/rules/no-return-assign)
53* [no-script-url](https://eslint.org/docs/rules/no-script-url)
54* [no-sequences](https://eslint.org/docs/rules/no-sequences)
55* [no-shadow](https://eslint.org/docs/rules/no-shadow)
56* [no-shadow-restricted-names](https://eslint.org/docs/rules/no-shadow-restricted-names)
57* [no-spaced-func](https://eslint.org/docs/rules/no-spaced-func)
58* [no-trailing-spaces](https://eslint.org/docs/rules/no-trailing-spaces)
59* [no-undef-init](https://eslint.org/docs/rules/no-undef-init)
60* [no-underscore-dangle](https://eslint.org/docs/rules/no-underscore-dangle)
61* [no-unused-expressions](https://eslint.org/docs/rules/no-unused-expressions)
62* [no-use-before-define](https://eslint.org/docs/rules/no-use-before-define)
63* [no-with](https://eslint.org/docs/rules/no-with)
64* [no-wrap-func](https://eslint.org/docs/rules/no-wrap-func)
65* [camelcase](https://eslint.org/docs/rules/camelcase)
66* [comma-spacing](https://eslint.org/docs/rules/comma-spacing)
67* [consistent-return](https://eslint.org/docs/rules/consistent-return)
68* [curly](https://eslint.org/docs/rules/curly)
69* [dot-notation](https://eslint.org/docs/rules/dot-notation)
70* [eol-last](https://eslint.org/docs/rules/eol-last)
71* [eqeqeq](https://eslint.org/docs/rules/eqeqeq)
72* [key-spacing](https://eslint.org/docs/rules/key-spacing)
73* [new-cap](https://eslint.org/docs/rules/new-cap)
74* [new-parens](https://eslint.org/docs/rules/new-parens)
75* [quotes](https://eslint.org/docs/rules/quotes)
76* [semi](https://eslint.org/docs/rules/semi)
77* [semi-spacing](https://eslint.org/docs/rules/semi-spacing)
78* [space-infix-ops](https://eslint.org/docs/rules/space-infix-ops)
79* [space-return-throw-case](https://eslint.org/docs/rules/space-return-throw-case)
80* [space-unary-ops](https://eslint.org/docs/rules/space-unary-ops)
81* [strict](https://eslint.org/docs/rules/strict)
82* [yoda](https://eslint.org/docs/rules/yoda)
83
84See also: the [full diff](https://github.com/eslint/eslint/commit/e3e9dbd9876daf4bdeb4e15f8a76a9d5e6e03e39#diff-b01a5cfd9361ca9280a460fd6bb8edbbL1) where the defaults were changed.
85
86Here's a configuration file with the closest equivalent of the old defaults:
87
88```json
89{
90 "extends": "eslint:recommended",
91 "rules": {
92 "no-alert": 2,
93 "no-array-constructor": 2,
94 "no-caller": 2,
95 "no-catch-shadow": 2,
96 "no-empty-label": 2,
97 "no-eval": 2,
98 "no-extend-native": 2,
99 "no-extra-bind": 2,
100 "no-implied-eval": 2,
101 "no-iterator": 2,
102 "no-label-var": 2,
103 "no-labels": 2,
104 "no-lone-blocks": 2,
105 "no-loop-func": 2,
106 "no-multi-spaces": 2,
107 "no-multi-str": 2,
108 "no-native-reassign": 2,
109 "no-new": 2,
110 "no-new-func": 2,
111 "no-new-object": 2,
112 "no-new-wrappers": 2,
113 "no-octal-escape": 2,
114 "no-process-exit": 2,
115 "no-proto": 2,
116 "no-return-assign": 2,
117 "no-script-url": 2,
118 "no-sequences": 2,
119 "no-shadow": 2,
120 "no-shadow-restricted-names": 2,
121 "no-spaced-func": 2,
122 "no-trailing-spaces": 2,
123 "no-undef-init": 2,
124 "no-underscore-dangle": 2,
125 "no-unused-expressions": 2,
126 "no-use-before-define": 2,
127 "no-with": 2,
128 "camelcase": 2,
129 "comma-spacing": 2,
130 "consistent-return": 2,
131 "curly": [2, "all"],
132 "dot-notation": [2, { "allowKeywords": true }],
133 "eol-last": 2,
134 "no-extra-parens": [2, "functions"],
135 "eqeqeq": 2,
136 "key-spacing": [2, { "beforeColon": false, "afterColon": true }],
137 "new-cap": 2,
138 "new-parens": 2,
139 "quotes": [2, "double"],
140 "semi": 2,
141 "semi-spacing": [2, {"before": false, "after": true}],
142 "space-infix-ops": 2,
143 "space-return-throw-case": 2,
144 "space-unary-ops": [2, { "words": true, "nonwords": false }],
145 "strict": [2, "function"],
146 "yoda": [2, "never"]
147 }
148}
149```
150
151## Removed Rules
152
153Over the past several releases, we have been deprecating rules and introducing new rules to take their place. The following is a list of the removed rules and their replacements:
154
155* [generator-star](https://eslint.org/docs/rules/generator-star) is replaced by [generator-star-spacing](https://eslint.org/docs/rules/generator-star-spacing)
156* [global-strict](https://eslint.org/docs/rules/global-strict) is replaced by [strict](https://eslint.org/docs/rules/strict)
157* [no-comma-dangle](https://eslint.org/docs/rules/no-comma-dangle) is replaced by [comma-dangle](https://eslint.org/docs/rules/comma-dangle)
158* [no-empty-class](https://eslint.org/docs/rules/no-empty-class) is replaced by [no-empty-character-class](https://eslint.org/docs/rules/no-empty-character-class)
159* [no-extra-strict](https://eslint.org/docs/rules/no-extra-strict) is replaced by [strict](https://eslint.org/docs/rules/strict)
160* [no-reserved-keys](https://eslint.org/docs/rules/no-reserved-keys) is replaced by [quote-props](https://eslint.org/docs/rules/quote-props)
161* [no-space-before-semi](https://eslint.org/docs/rules/no-space-before-semi) is replaced by [semi-spacing](https://eslint.org/docs/rules/semi-spacing)
162* [no-wrap-func](https://eslint.org/docs/rules/no-wrap-func) is replaced by [no-extra-parens](https://eslint.org/docs/rules/no-extra-parens)
163* [space-after-function-name](https://eslint.org/docs/rules/space-after-function-name) is replaced by [space-before-function-paren](https://eslint.org/docs/rules/space-before-function-paren)
164* [space-before-function-parentheses](https://eslint.org/docs/rules/space-before-function-parentheses) is replaced by [space-before-function-paren](https://eslint.org/docs/rules/space-before-function-paren)
165* [space-in-brackets](https://eslint.org/docs/rules/space-in-brackets) is replaced by[object-curly-spacing](https://eslint.org/docs/rules/object-curly-spacing) and [array-bracket-spacing](https://eslint.org/docs/rules/array-bracket-spacing)
166* [space-unary-word-ops](https://eslint.org/docs/rules/space-unary-word-ops) is replaced by [space-unary-ops](https://eslint.org/docs/rules/space-unary-ops)
167* [spaced-line-comment](https://eslint.org/docs/rules/spaced-line-comment) is replaced by [spaced-comment](https://eslint.org/docs/rules/spaced-comment)
168
169**To address:** You'll need to update your rule configurations to use the new rules. ESLint v1.0.0 will also warn you when you're using a rule that has been removed and will suggest the replacement rules. Hopefully, this will result in few surprises during the upgrade process.
170
171## Column Numbers are 1-based
172
173From the beginning, ESLint has reported errors using 0-based columns because that's what Esprima, and later Espree, reported. However, most tools and editors use 1-based columns, which made for some tricky integrations with ESLint. In v1.0.0, we've switched over to reporting errors using 1-based columns to fall into line with the tools developers use everyday.
174
175**To address:** If you've created an editor integration, or a tool that had to correct the column number, you'll need to update to just pass through the column number from ESLint. Otherwise, no change is necessary.
176
177## No Longer Exporting cli
178
179In 0.x, the `cli` object was exported for use by external tools. It was later deprecated in favor of `CLIEngine`. In v1.0.0, we are no longer exporting `cli` as it should not be used by external tools. This will break existing tools that make use of it.
180
181**To address:** If you are using the exported `cli` object, switch to using `CLIEngine` instead.
182
183## Deprecating eslint-tester
184
185The `eslint-tester` module, which has long been the primary tester for ESLint rules, has now been moved into the `eslint` module. This was the result of a difficult relationship between these two modules that created circular dependencies and was causing a lot of problems in rule tests. Moving the tester into the `eslint` module fixed a lot of those issues.
186
187The replacement for `eslint-tester` is called `RuleTester`. It's a simplified version of `ESLintTester` that's designed to work with any testing framework. This object is exposed by the package.
188
189**To address:** Convert all of your rule tests to use `RuleTester`. If you have this as a test using `ESLintTester`:
190
191```js
192var eslint = require("../../../lib/eslint"),
193 ESLintTester = require("eslint-tester");
194
195var eslintTester = new ESLintTester(eslint);
196eslintTester.addRuleTest("lib/rules/your-rule", {
197 valid: [],
198 invalid: []
199});
200```
201
202Then you can change to:
203
204```js
205var rule = require("../../../lib/rules/your-rule"),
206 RuleTester = require("eslint").RuleTester;
207
208var ruleTester = new RuleTester();
209ruleTester.run("your-rule", rule, {
210 valid: [],
211 invalid: []
212});
213```