eslint 4.1.1 → 4.4.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +106 -0
- package/bin/eslint.js +5 -4
- package/conf/category-list.json +2 -2
- package/conf/config-schema.js +3 -1
- package/conf/eslint-recommended.js +12 -14
- package/lib/cli-engine.js +4 -3
- package/lib/cli.js +12 -1
- package/lib/config/config-file.js +5 -5
- package/lib/config/config-initializer.js +123 -14
- package/lib/config/config-validator.js +43 -14
- package/lib/config/plugins.js +13 -1
- package/lib/linter.js +26 -15
- package/lib/rule-context.js +53 -41
- package/lib/rules/arrow-parens.js +5 -2
- package/lib/rules/comma-dangle.js +40 -40
- package/lib/rules/curly.js +1 -1
- package/lib/rules/dot-notation.js +9 -0
- package/lib/rules/getter-return.js +176 -0
- package/lib/rules/id-blacklist.js +7 -3
- package/lib/rules/id-match.js +8 -4
- package/lib/rules/indent-legacy.js +2 -2
- package/lib/rules/indent.js +354 -349
- package/lib/rules/key-spacing.js +2 -2
- package/lib/rules/multiline-ternary.js +8 -2
- package/lib/rules/no-cond-assign.js +7 -3
- package/lib/rules/no-constant-condition.js +62 -6
- package/lib/rules/no-debugger.js +6 -1
- package/lib/rules/no-else-return.js +1 -1
- package/lib/rules/no-extra-parens.js +24 -11
- package/lib/rules/no-inner-declarations.js +8 -4
- package/lib/rules/no-multi-spaces.js +53 -115
- package/lib/rules/no-regex-spaces.js +4 -4
- package/lib/rules/no-restricted-globals.js +50 -9
- package/lib/rules/no-restricted-properties.js +19 -11
- package/lib/rules/no-sync.js +15 -3
- package/lib/rules/no-tabs.js +8 -4
- package/lib/rules/no-underscore-dangle.js +28 -1
- package/lib/rules/object-curly-newline.js +18 -0
- package/lib/rules/object-curly-spacing.js +1 -1
- package/lib/rules/padded-blocks.js +2 -2
- package/lib/rules/padding-line-between-statements.js +1 -1
- package/lib/rules/prefer-destructuring.js +70 -32
- package/lib/rules/prefer-numeric-literals.js +36 -7
- package/lib/rules/prefer-reflect.js +8 -4
- package/lib/rules/prefer-template.js +2 -2
- package/lib/rules/space-infix-ops.js +1 -1
- package/lib/rules/spaced-comment.js +2 -2
- package/lib/rules/valid-jsdoc.js +15 -7
- package/lib/testers/rule-tester.js +23 -30
- package/lib/testers/test-parser.js +48 -0
- package/lib/util/ajv.js +29 -0
- package/lib/util/npm-util.js +9 -8
- package/lib/util/source-code-fixer.js +47 -19
- package/package.json +11 -7
- package/conf/json-schema-schema.json +0 -150
package/CHANGELOG.md
CHANGED
@@ -1,3 +1,109 @@
|
|
1
|
+
v4.4.1 - August 7, 2017
|
2
|
+
|
3
|
+
* ec93614 Fix: no-multi-spaces to avoid reporting consecutive tabs (fixes #9079) (#9087) (Teddy Katz)
|
4
|
+
|
5
|
+
v4.4.0 - August 5, 2017
|
6
|
+
|
7
|
+
* 89196fd Upgrade: Espree to 3.5.0 (#9074) (Gyandeep Singh)
|
8
|
+
* b3e4598 Fix: clarify AST and don't use `node.start`/`node.end` (fixes #8956) (#8984) (Toru Nagashima)
|
9
|
+
* 62911e4 Update: Add ImportDeclaration option to indent rule (#8955) (David Irvine)
|
10
|
+
* de75f9b Chore: enable object-curly-newline & object-property-newline.(fixes #9042) (#9068) (薛定谔的猫)
|
11
|
+
* 5ae8458 Docs: fix typo in object-shorthand.md (#9066) (Jon Berry)
|
12
|
+
* c3d5b39 Docs: clarify options descriptions (fixes #8875) (#9060) (Brandon Mailhiot)
|
13
|
+
* 37158c5 Docs: clarified behavior of globalReturn option (fixes #8953) (#9058) (Brandon Mailhiot)
|
14
|
+
* c2f3553 Docs: Update example for MemberExpression option of indent (fixes #9056) (#9057) (Jeff)
|
15
|
+
* 78a85e0 Fix: no-extra-parens incorrectly reports async function expressions (#9035) (薛定谔的猫)
|
16
|
+
* c794f86 Fix: getter-return reporting method named 'get' (fixes #8919) (#9004) (薛定谔的猫)
|
17
|
+
* d0f78ec Docs: update rule deprecation policy (fixes #8635) (#9033) (Teddy Katz)
|
18
|
+
* 5ab282f Fix: Print error message in bin/eslint.js (fixes #9011) (#9041) (Victor Hom)
|
19
|
+
* 50e3cf3 Docs: Update sort-keys doc to define natural ordering (fixes #9043) (#9045) (Karan Sharma)
|
20
|
+
* 7ecfe6a Chore: enable eslint-plugin/test-case-property-ordering (#9040) (薛定谔的猫)
|
21
|
+
* ad32697 Upgrade: js-yaml to 3.9.1 (refs #9011) (#9044) (Teddy Katz)
|
22
|
+
* 66c1d43 Docs: Create SUPPORT.md (#9031) (Teddy Katz)
|
23
|
+
* 7247b6c Update: handle indentation of custom destructuring syntax (fixes #8990) (#9027) (Teddy Katz)
|
24
|
+
* cdb82f2 Fix: padding-line-between-statements crash on semicolons after blocks (#8748) (Alexander Madyankin)
|
25
|
+
* 3141872 Chore: remove unnecessary eslint-disable comments in codebase (#9032) (Teddy Katz)
|
26
|
+
* 0f97279 Fix: refactor no-multi-spaces to avoid regex backtracking (fixes #9001) (#9008) (Teddy Katz)
|
27
|
+
* b74514d Fix: refactor RuleContext to not modify report locations (fixes #8980) (#8997) (Teddy Katz)
|
28
|
+
* 31d7fd2 Fix: inconsistent `indent` behavior on computed properties (fixes #8989) (#8999) (Teddy Katz)
|
29
|
+
* 3393894 Fix: avoid reporting the entire AST for missing rules (#8998) (Teddy Katz)
|
30
|
+
* b3b95b8 Chore: enable additional rules on ESLint codebase (#9013) (Teddy Katz)
|
31
|
+
* 9b6c552 Upgrade: eslint-plugin-eslint-plugin@0.8.0 (#9012) (薛定谔的猫)
|
32
|
+
* acbe86a Chore: disallow .substr and .substring in favor of .slice (#9010) (Teddy Katz)
|
33
|
+
* d0536d6 Chore: Optimizes adding Linter methods (fixes #9000) (#9007) (Sean C Denison)
|
34
|
+
* 0a0401f Chore: fix spelling error. (#9003) (薛定谔的猫)
|
35
|
+
* 3d020b9 Update: emit a warning for ecmaFeatures rather than throwing an error (#8974) (Teddy Katz)
|
36
|
+
* d2f8f9f Fix: include name of invalid config in validation messages (fixes #8963) (#8973) (Teddy Katz)
|
37
|
+
* c3ee46b Chore: fix misleading comment in RuleTester (#8995) (Teddy Katz)
|
38
|
+
|
39
|
+
v4.3.0 - July 21, 2017
|
40
|
+
|
41
|
+
* 91dccdf Update: support more options in prefer-destructuring (#8796) (Victor Hom)
|
42
|
+
* 3bebcfd Update: Support generator yields in no constant condition (#8762) (Victor Hom)
|
43
|
+
* 96df8c9 Fix: Handle fixing objects containing comments (fixes #8484) (#8944) (Brian Schemp)
|
44
|
+
* e39d41d Docs: Make `peerDependencies` package.json snippet valid JSON (#8971) (Sam Adams)
|
45
|
+
* a5fd101 Fix: duplicated error message if a crash occurs (fixes #8964) (#8965) (Teddy Katz)
|
46
|
+
* f8d122c Docs: trailing commas not allowed in json (#8969) (Scott Fletcher)
|
47
|
+
* d09288a Chore: Use `output: null` to assert that a test case is not autofixed. (#8960) (薛定谔的猫)
|
48
|
+
* e639358 Update: add question to confirm downgrade (fixes #8870) (#8911) (Toru Nagashima)
|
49
|
+
* 601039d Docs: fix badge in eslint-config-eslint readme (#8954) (Teddy Katz)
|
50
|
+
* 3c231fa Update: add enforceInMethodNames to no-underscore-dangle (fixes #7065) (#7234) (Gabriele Petronella)
|
51
|
+
* 128591f Update: prefer-numeric-literals warns Number.parseInt (fixes #8913) (#8929) (Kevin Partington)
|
52
|
+
* 846f8b1 Docs: Clarified that core PRs require issue in maintainer guide (#8927) (Kevin Partington)
|
53
|
+
* 55bc35d Fix: Avoid shell mangling during eslint --init (#8936) (Anders Kaseorg)
|
54
|
+
* 10c3d78 Chore: fix misleading `indent` test (#8925) (Teddy Katz)
|
55
|
+
* fb8005d Update: no-restricted-globals custom error messages (fixes #8315) (#8932) (Kevin Partington)
|
56
|
+
* a747b6f Chore: make minor improvements to `indent` internals (#8947) (Teddy Katz)
|
57
|
+
* 1ea3723 Update: fix indentation of parenthesized MemberExpressions (fixes #8924) (#8928) (Teddy Katz)
|
58
|
+
* 9abc6f7 Update: fix BinaryExpression indentation edge case (fixes #8914) (#8930) (Teddy Katz)
|
59
|
+
* 0e90453 Docs: Fixing broken cyclomatic complexity link (fixes #8396) (#8937) (Chris Bargren)
|
60
|
+
* a8a8350 Chore: improve performance of `indent` rule (#8905) (Teddy Katz)
|
61
|
+
* 764b2a9 Chore: update header info in `indent` (#8926) (Teddy Katz)
|
62
|
+
* 597c217 Fix: confusing error if plugins from config is not an array (#8888) (Calvin Freitas)
|
63
|
+
* 3c1dd6d Docs: add description of no-sync `allowAtRootLevel` option (fixes #8902) (#8906) (Teddy Katz)
|
64
|
+
* 933a9cf Chore: add a fuzzer to detect bugs in core rules (#8422) (Teddy Katz)
|
65
|
+
* 45f8cd9 Docs: fix verifyAndFix result property name (#8903) (Tino Vyatkin)
|
66
|
+
* 1a89e1c Docs: Fix always-multiline example in multiline-ternary docs (#8904) (Nathan Woltman)
|
67
|
+
|
68
|
+
v4.2.0 - July 8, 2017
|
69
|
+
|
70
|
+
* e0f0101 Update: fix indentation of nested function parameters (fixes #8892) (#8900) (Teddy Katz)
|
71
|
+
* 9f95a3e Chore: remove unused helper method from `indent` (#8901) (Teddy Katz)
|
72
|
+
* 11ffe6b Fix: no-regex-spaces rule incorrectly fixes quantified spaces (#8773) (Keri Warr)
|
73
|
+
* 975dacf Update: fix indentation of EmptyStatements (fixes #8882) (#8885) (Teddy Katz)
|
74
|
+
* 88ed041 Build: Turnoff CI branch build (fixes #8804) (#8873) (Gyandeep Singh)
|
75
|
+
* 72f22eb Chore: replace is-my-json-valid with Ajv (#8852) (Gajus Kuizinas)
|
76
|
+
* 7c8de92 Docs: Clarified PR guidelines in maintainer guide (#8876) (Kevin Partington)
|
77
|
+
* d1fc408 Docs: Update CLA link in Contributing docs (#8883) (Calvin Freitas)
|
78
|
+
* 931a9f1 Fix: indent false positive with multi-line await expression (#8837) (薛定谔的猫)
|
79
|
+
* 3767cda Update: add no-sync option to allow at root level (fixes #7985) (#8859) (Victor Hom)
|
80
|
+
* 1ce553d Docs: Fix wording of minProperties in object-curly-newline (fixes #8874) (#8878) (solmsted)
|
81
|
+
* f00854e Fix: --quiet no longer fixes warnings (fixes #8675) (#8858) (Kevin Partington)
|
82
|
+
* b678535 Chore: Add collapsible block for config in ISSUE_TEMPLATE (#8872) (Gyandeep Singh)
|
83
|
+
* 1f5bfc2 Update: Add always-multiline option to multiline-ternary (fixes #8770) (#8841) (Nathan Woltman)
|
84
|
+
* 22116f2 Fix: correct comma-dangle JSON schema (#8864) (Evgeny Poberezkin)
|
85
|
+
* 676af9e Update: fix indentation of JSXExpressionContainer contents (fixes #8832) (#8850) (Teddy Katz)
|
86
|
+
* 330dd58 Chore: fix title of linter test suite (#8861) (Teddy Katz)
|
87
|
+
* 60099ed Chore: enable for-direction rule on ESLint codebase (#8853) (薛定谔的猫)
|
88
|
+
* e0d1a84 Chore: upgrade eslint-plugin-eslint-plugin & eslint-plugin-node (#8856) (薛定谔的猫)
|
89
|
+
* 0780d86 Chore: remove identical tests (#8851) (Teddy Katz)
|
90
|
+
* 5c3ac8e Fix: arrow-parens fixer gets tripped up with trailing comma in args (#8838) (薛定谔的猫)
|
91
|
+
* c4f2e29 Build: fix race condition in demo (#8827) (Teddy Katz)
|
92
|
+
* c693be5 New: Allow passing a function as `fix` option (fixes #8039) (#8730) (Ian VanSchooten)
|
93
|
+
* 8796d55 Docs: add missing item to 4.0 migration guide table of contents (#8835) (薛定谔的猫)
|
94
|
+
* 742998c doc md update: false -> `false` (#8825) (Erik Vold)
|
95
|
+
* ce969f9 Docs: add guidelines for patch release communication (fixes #7277) (#8823) (Teddy Katz)
|
96
|
+
* 5c83c99 Docs: Clarify arrow function parens in no-extra-parens (fixes #8741) (#8822) (Kevin Partington)
|
97
|
+
* 84d921d Docs: Added note about Node/CJS scoping to no-redeclare (fixes #8814) (#8820) (Kevin Partington)
|
98
|
+
* 85c9327 Update: fix parenthesized CallExpression indentation (fixes #8790) (#8802) (Teddy Katz)
|
99
|
+
* be8d354 Update: simplify variable declarator indent handling (fixes #8785) (#8801) (Teddy Katz)
|
100
|
+
* 9417818 Fix: no-debugger autofixer produced invalid syntax (#8806) (Teddy Katz)
|
101
|
+
* 8698a92 New: getter-return rule (fixes #8449) (#8460) (薛定谔的猫)
|
102
|
+
* eac06f2 Fix: no-extra-parens false positives for variables called "let" (#8808) (Teddy Katz)
|
103
|
+
* 616587f Fix: dot-notation autofix produces syntax errors for object called "let" (#8807) (Teddy Katz)
|
104
|
+
* a53ef7e Fix: don't require a third argument in linter.verifyAndFix (fixes #8805) (#8809) (Teddy Katz)
|
105
|
+
* 5ad8b70 Docs: add minor formatting improvement to paragraph about parsers (#8816) (Teddy Katz)
|
106
|
+
|
1
107
|
v4.1.1 - June 25, 2017
|
2
108
|
|
3
109
|
* f307aa0 Fix: ensure configs from a plugin are cached separately (fixes #8792) (#8798) (Teddy Katz)
|
package/bin/eslint.js
CHANGED
@@ -44,11 +44,12 @@ process.once("uncaughtException", err => {
|
|
44
44
|
if (typeof err.messageTemplate === "string" && err.messageTemplate.length > 0) {
|
45
45
|
const template = lodash.template(fs.readFileSync(path.resolve(__dirname, `../messages/${err.messageTemplate}.txt`), "utf-8"));
|
46
46
|
|
47
|
-
console.
|
48
|
-
console.
|
47
|
+
console.error("\nOops! Something went wrong! :(");
|
48
|
+
console.error(`\n${template(err.messageData || {})}`);
|
49
49
|
} else {
|
50
|
-
|
51
|
-
console.
|
50
|
+
|
51
|
+
console.error(err.message);
|
52
|
+
console.error(err.stack);
|
52
53
|
}
|
53
54
|
|
54
55
|
process.exitCode = 1;
|
package/conf/category-list.json
CHANGED
@@ -10,12 +10,12 @@
|
|
10
10
|
],
|
11
11
|
"deprecated": {
|
12
12
|
"name": "Deprecated",
|
13
|
-
"description": "These rules have been deprecated and replaced by newer rules:",
|
13
|
+
"description": "These rules have been deprecated in accordance with the [deprecation policy](/docs/user-guide/rule-deprecation), and replaced by newer rules:",
|
14
14
|
"rules": []
|
15
15
|
},
|
16
16
|
"removed": {
|
17
17
|
"name": "Removed",
|
18
|
-
"description": "These rules from older versions of ESLint have been replaced by newer rules:",
|
18
|
+
"description": "These rules from older versions of ESLint (before the [deprecation policy](/docs/user-guide/rule-deprecation) existed) have been replaced by newer rules:",
|
19
19
|
"rules": [
|
20
20
|
{ "removed": "generator-star", "replacedBy": ["generator-star-spacing"] },
|
21
21
|
{ "removed": "global-strict", "replacedBy": ["strict"] },
|
package/conf/config-schema.js
CHANGED
@@ -12,7 +12,9 @@ const baseConfigProperties = {
|
|
12
12
|
parserOptions: { type: "object" },
|
13
13
|
plugins: { type: "array" },
|
14
14
|
rules: { type: "object" },
|
15
|
-
settings: { type: "object" }
|
15
|
+
settings: { type: "object" },
|
16
|
+
|
17
|
+
ecmaFeatures: { type: "object" } // deprecated; logs a warning when used
|
16
18
|
};
|
17
19
|
|
18
20
|
const overrideProperties = Object.assign(
|
@@ -6,13 +6,10 @@
|
|
6
6
|
|
7
7
|
"use strict";
|
8
8
|
|
9
|
-
/* eslint sort-keys: ["error", "asc"]
|
10
|
-
/* eslint-disable sort-keys */
|
9
|
+
/* eslint sort-keys: ["error", "asc"] */
|
11
10
|
|
12
11
|
module.exports = {
|
13
12
|
rules: {
|
14
|
-
|
15
|
-
/* eslint-enable sort-keys */
|
16
13
|
"accessor-pairs": "off",
|
17
14
|
"array-bracket-newline": "off",
|
18
15
|
"array-bracket-spacing": "off",
|
@@ -25,36 +22,37 @@ module.exports = {
|
|
25
22
|
"block-spacing": "off",
|
26
23
|
"brace-style": "off",
|
27
24
|
"callback-return": "off",
|
28
|
-
|
25
|
+
camelcase: "off",
|
29
26
|
"capitalized-comments": "off",
|
30
27
|
"class-methods-use-this": "off",
|
31
28
|
"comma-dangle": "off",
|
32
29
|
"comma-spacing": "off",
|
33
30
|
"comma-style": "off",
|
34
|
-
|
31
|
+
complexity: "off",
|
35
32
|
"computed-property-spacing": "off",
|
36
33
|
"consistent-return": "off",
|
37
34
|
"consistent-this": "off",
|
38
35
|
"constructor-super": "error",
|
39
|
-
|
36
|
+
curly: "off",
|
40
37
|
"default-case": "off",
|
41
38
|
"dot-location": "off",
|
42
39
|
"dot-notation": "off",
|
43
40
|
"eol-last": "off",
|
44
|
-
|
41
|
+
eqeqeq: "off",
|
45
42
|
"for-direction": "off",
|
46
43
|
"func-call-spacing": "off",
|
47
44
|
"func-name-matching": "off",
|
48
45
|
"func-names": "off",
|
49
46
|
"func-style": "off",
|
50
47
|
"generator-star-spacing": "off",
|
48
|
+
"getter-return": "off",
|
51
49
|
"global-require": "off",
|
52
50
|
"guard-for-in": "off",
|
53
51
|
"handle-callback-err": "off",
|
54
52
|
"id-blacklist": "off",
|
55
53
|
"id-length": "off",
|
56
54
|
"id-match": "off",
|
57
|
-
|
55
|
+
indent: "off",
|
58
56
|
"indent-legacy": "off",
|
59
57
|
"init-declarations": "off",
|
60
58
|
"jsx-quotes": "off",
|
@@ -233,13 +231,13 @@ module.exports = {
|
|
233
231
|
"prefer-spread": "off",
|
234
232
|
"prefer-template": "off",
|
235
233
|
"quote-props": "off",
|
236
|
-
|
237
|
-
|
234
|
+
quotes: "off",
|
235
|
+
radix: "off",
|
238
236
|
"require-await": "off",
|
239
237
|
"require-jsdoc": "off",
|
240
238
|
"require-yield": "error",
|
241
239
|
"rest-spread-spacing": "off",
|
242
|
-
|
240
|
+
semi: "off",
|
243
241
|
"semi-spacing": "off",
|
244
242
|
"semi-style": "off",
|
245
243
|
"sort-imports": "off",
|
@@ -251,7 +249,7 @@ module.exports = {
|
|
251
249
|
"space-infix-ops": "off",
|
252
250
|
"space-unary-ops": "off",
|
253
251
|
"spaced-comment": "off",
|
254
|
-
|
252
|
+
strict: "off",
|
255
253
|
"switch-colon-spacing": "off",
|
256
254
|
"symbol-description": "off",
|
257
255
|
"template-curly-spacing": "off",
|
@@ -264,6 +262,6 @@ module.exports = {
|
|
264
262
|
"wrap-iife": "off",
|
265
263
|
"wrap-regex": "off",
|
266
264
|
"yield-star-spacing": "off",
|
267
|
-
|
265
|
+
yoda: "off"
|
268
266
|
}
|
269
267
|
};
|
package/lib/cli-engine.js
CHANGED
@@ -45,7 +45,7 @@ const debug = require("debug")("eslint:cli-engine");
|
|
45
45
|
* @property {string} cwd The value to use for the current working directory.
|
46
46
|
* @property {string[]} envs An array of environments to load.
|
47
47
|
* @property {string[]} extensions An array of file extensions to check.
|
48
|
-
* @property {boolean} fix Execute in autofix mode.
|
48
|
+
* @property {boolean|Function} fix Execute in autofix mode. If a function, should return a boolean.
|
49
49
|
* @property {string[]} globals An array of global variables to declare.
|
50
50
|
* @property {boolean} ignore False disables use of .eslintignore.
|
51
51
|
* @property {string} ignorePath The ignore file to use instead of .eslintignore.
|
@@ -135,7 +135,7 @@ function calculateStatsPerRun(results) {
|
|
135
135
|
* @param {string} text The source code to check.
|
136
136
|
* @param {Object} configHelper The configuration options for ESLint.
|
137
137
|
* @param {string} filename An optional string representing the texts filename.
|
138
|
-
* @param {boolean} fix Indicates if fixes should be processed.
|
138
|
+
* @param {boolean|Function} fix Indicates if fixes should be processed.
|
139
139
|
* @param {boolean} allowInlineConfig Allow/ignore comments that change config.
|
140
140
|
* @param {Linter} linter Linter context
|
141
141
|
* @returns {LintResult} The results for linting on this text.
|
@@ -195,7 +195,8 @@ function processText(text, configHelper, filename, fix, allowInlineConfig, linte
|
|
195
195
|
if (fix) {
|
196
196
|
fixedResult = linter.verifyAndFix(text, config, {
|
197
197
|
filename,
|
198
|
-
allowInlineConfig
|
198
|
+
allowInlineConfig,
|
199
|
+
fix
|
199
200
|
});
|
200
201
|
messages = fixedResult.messages;
|
201
202
|
} else {
|
package/lib/cli.js
CHANGED
@@ -28,6 +28,17 @@ const debug = require("debug")("eslint:cli");
|
|
28
28
|
// Helpers
|
29
29
|
//------------------------------------------------------------------------------
|
30
30
|
|
31
|
+
/**
|
32
|
+
* Predicate function for whether or not to apply fixes in quiet mode.
|
33
|
+
* If a message is a warning, do not apply a fix.
|
34
|
+
* @param {LintResult} lintResult The lint result.
|
35
|
+
* @returns {boolean} True if the lint message is an error (and thus should be
|
36
|
+
* autofixed), false otherwise.
|
37
|
+
*/
|
38
|
+
function quietFixPredicate(lintResult) {
|
39
|
+
return lintResult.severity === 2;
|
40
|
+
}
|
41
|
+
|
31
42
|
/**
|
32
43
|
* Translates the CLI options into the options expected by the CLIEngine.
|
33
44
|
* @param {Object} cliOptions The CLI options to translate.
|
@@ -52,7 +63,7 @@ function translateOptions(cliOptions) {
|
|
52
63
|
cache: cliOptions.cache,
|
53
64
|
cacheFile: cliOptions.cacheFile,
|
54
65
|
cacheLocation: cliOptions.cacheLocation,
|
55
|
-
fix: cliOptions.fix,
|
66
|
+
fix: cliOptions.fix && (cliOptions.quiet ? quietFixPredicate : true),
|
56
67
|
allowInlineConfig: cliOptions.inlineConfig
|
57
68
|
};
|
58
69
|
}
|
@@ -3,8 +3,6 @@
|
|
3
3
|
* @author Nicholas C. Zakas
|
4
4
|
*/
|
5
5
|
|
6
|
-
/* eslint no-use-before-define: 0 */
|
7
|
-
|
8
6
|
"use strict";
|
9
7
|
|
10
8
|
//------------------------------------------------------------------------------
|
@@ -418,6 +416,8 @@ function applyExtends(config, configContext, filePath, relativeTo) {
|
|
418
416
|
);
|
419
417
|
}
|
420
418
|
debug(`Loading ${parentPath}`);
|
419
|
+
|
420
|
+
// eslint-disable-next-line no-use-before-define
|
421
421
|
return ConfigOps.merge(load(parentPath, configContext, relativeTo), previousValue);
|
422
422
|
} catch (e) {
|
423
423
|
|
@@ -502,8 +502,8 @@ function resolve(filePath, relativeTo) {
|
|
502
502
|
|
503
503
|
if (filePath.startsWith("plugin:")) {
|
504
504
|
const configFullName = filePath;
|
505
|
-
const pluginName = filePath.
|
506
|
-
const configName = filePath.
|
505
|
+
const pluginName = filePath.slice(7, filePath.lastIndexOf("/"));
|
506
|
+
const configName = filePath.slice(filePath.lastIndexOf("/") + 1);
|
507
507
|
|
508
508
|
normalizedPackageName = normalizePackageName(pluginName, "eslint-plugin");
|
509
509
|
debug(`Attempting to resolve ${normalizedPackageName}`);
|
@@ -546,7 +546,7 @@ function loadFromDisk(resolvedPath, configContext) {
|
|
546
546
|
}
|
547
547
|
|
548
548
|
// validate the configuration before continuing
|
549
|
-
validator.validate(config, resolvedPath, configContext.linterContext.rules, configContext.linterContext.environments);
|
549
|
+
validator.validate(config, resolvedPath.configFullName, configContext.linterContext.rules, configContext.linterContext.environments);
|
550
550
|
|
551
551
|
/*
|
552
552
|
* If an `extends` property is defined, it represents a configuration file to use as
|
@@ -12,10 +12,12 @@
|
|
12
12
|
const util = require("util"),
|
13
13
|
inquirer = require("inquirer"),
|
14
14
|
ProgressBar = require("progress"),
|
15
|
+
semver = require("semver"),
|
15
16
|
autoconfig = require("./autoconfig.js"),
|
16
17
|
ConfigFile = require("./config-file"),
|
17
18
|
ConfigOps = require("./config-ops"),
|
18
19
|
getSourceCodeOfFiles = require("../util/source-code-util").getSourceCodeOfFiles,
|
20
|
+
ModuleResolver = require("../util/module-resolver"),
|
19
21
|
npmUtil = require("../util/npm-util"),
|
20
22
|
recConfig = require("../../conf/eslint-recommended"),
|
21
23
|
log = require("../logging");
|
@@ -56,12 +58,35 @@ function writeFile(config, format) {
|
|
56
58
|
}
|
57
59
|
}
|
58
60
|
|
61
|
+
/**
|
62
|
+
* Get the peer dependencies of the given module.
|
63
|
+
* This adds the gotten value to cache at the first time, then reuses it.
|
64
|
+
* In a process, this function is called twice, but `npmUtil.fetchPeerDependencies` needs to access network which is relatively slow.
|
65
|
+
* @param {string} moduleName The module name to get.
|
66
|
+
* @returns {Object} The peer dependencies of the given module.
|
67
|
+
* This object is the object of `peerDependencies` field of `package.json`.
|
68
|
+
*/
|
69
|
+
function getPeerDependencies(moduleName) {
|
70
|
+
let result = getPeerDependencies.cache.get(moduleName);
|
71
|
+
|
72
|
+
if (!result) {
|
73
|
+
log.info(`Checking peerDependencies of ${moduleName}`);
|
74
|
+
|
75
|
+
result = npmUtil.fetchPeerDependencies(moduleName);
|
76
|
+
getPeerDependencies.cache.set(moduleName, result);
|
77
|
+
}
|
78
|
+
|
79
|
+
return result;
|
80
|
+
}
|
81
|
+
getPeerDependencies.cache = new Map();
|
82
|
+
|
59
83
|
/**
|
60
84
|
* Synchronously install necessary plugins, configs, parsers, etc. based on the config
|
61
85
|
* @param {Object} config config object
|
86
|
+
* @param {boolean} [installESLint=true] If `false` is given, it does not install eslint.
|
62
87
|
* @returns {void}
|
63
88
|
*/
|
64
|
-
function installModules(config) {
|
89
|
+
function installModules(config, installESLint) {
|
65
90
|
const modules = {};
|
66
91
|
|
67
92
|
// Create a list of modules which should be installed based on config
|
@@ -73,11 +98,10 @@ function installModules(config) {
|
|
73
98
|
if (config.extends && config.extends.indexOf("eslint:") === -1) {
|
74
99
|
const moduleName = `eslint-config-${config.extends}`;
|
75
100
|
|
76
|
-
log.info(`Checking peerDependencies of ${moduleName}`);
|
77
101
|
modules[moduleName] = "latest";
|
78
102
|
Object.assign(
|
79
103
|
modules,
|
80
|
-
|
104
|
+
getPeerDependencies(`${moduleName}@latest`)
|
81
105
|
);
|
82
106
|
}
|
83
107
|
|
@@ -86,15 +110,17 @@ function installModules(config) {
|
|
86
110
|
return;
|
87
111
|
}
|
88
112
|
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
const installStatus = npmUtil.checkDevDeps(["eslint"]);
|
113
|
+
if (installESLint === false) {
|
114
|
+
delete modules.eslint;
|
115
|
+
} else {
|
116
|
+
const installStatus = npmUtil.checkDevDeps(["eslint"]);
|
94
117
|
|
95
|
-
|
96
|
-
|
97
|
-
|
118
|
+
// Mark to show messages if it's new installation of eslint.
|
119
|
+
if (installStatus.eslint === false) {
|
120
|
+
log.info("Local ESLint installation not found.");
|
121
|
+
modules.eslint = modules.eslint || "latest";
|
122
|
+
config.installedESLint = true;
|
123
|
+
}
|
98
124
|
}
|
99
125
|
|
100
126
|
// Install packages
|
@@ -265,9 +291,10 @@ function processAnswers(answers) {
|
|
265
291
|
/**
|
266
292
|
* process user's style guide of choice and return an appropriate config object.
|
267
293
|
* @param {string} guide name of the chosen style guide
|
294
|
+
* @param {boolean} [installESLint=true] If `false` is given, it does not install eslint.
|
268
295
|
* @returns {Object} config object
|
269
296
|
*/
|
270
|
-
function getConfigForStyleGuide(guide) {
|
297
|
+
function getConfigForStyleGuide(guide, installESLint) {
|
271
298
|
const guides = {
|
272
299
|
google: { extends: "google" },
|
273
300
|
airbnb: { extends: "airbnb" },
|
@@ -279,11 +306,74 @@ function getConfigForStyleGuide(guide) {
|
|
279
306
|
throw new Error("You referenced an unsupported guide.");
|
280
307
|
}
|
281
308
|
|
282
|
-
installModules(guides[guide]);
|
309
|
+
installModules(guides[guide], installESLint);
|
283
310
|
|
284
311
|
return guides[guide];
|
285
312
|
}
|
286
313
|
|
314
|
+
/**
|
315
|
+
* Get the version of the local ESLint.
|
316
|
+
* @returns {string|null} The version. If the local ESLint was not found, returns null.
|
317
|
+
*/
|
318
|
+
function getLocalESLintVersion() {
|
319
|
+
try {
|
320
|
+
const resolver = new ModuleResolver();
|
321
|
+
const eslintPath = resolver.resolve("eslint", process.cwd());
|
322
|
+
const eslint = require(eslintPath);
|
323
|
+
|
324
|
+
return eslint.linter.version || null;
|
325
|
+
} catch (_err) {
|
326
|
+
return null;
|
327
|
+
}
|
328
|
+
}
|
329
|
+
|
330
|
+
/**
|
331
|
+
* Get the shareable config name of the chosen style guide.
|
332
|
+
* @param {Object} answers The answers object.
|
333
|
+
* @returns {string} The shareable config name.
|
334
|
+
*/
|
335
|
+
function getStyleGuideName(answers) {
|
336
|
+
if (answers.styleguide === "airbnb" && !answers.airbnbReact) {
|
337
|
+
return "airbnb-base";
|
338
|
+
}
|
339
|
+
return answers.styleguide;
|
340
|
+
}
|
341
|
+
|
342
|
+
/**
|
343
|
+
* Check whether the local ESLint version conflicts with the required version of the chosen shareable config.
|
344
|
+
* @param {Object} answers The answers object.
|
345
|
+
* @returns {boolean} `true` if the local ESLint is found then it conflicts with the required version of the chosen shareable config.
|
346
|
+
*/
|
347
|
+
function hasESLintVersionConflict(answers) {
|
348
|
+
|
349
|
+
// Get the local ESLint version.
|
350
|
+
const localESLintVersion = getLocalESLintVersion();
|
351
|
+
|
352
|
+
if (!localESLintVersion) {
|
353
|
+
return false;
|
354
|
+
}
|
355
|
+
|
356
|
+
// Get the required range of ESLint version.
|
357
|
+
const configName = getStyleGuideName(answers);
|
358
|
+
const moduleName = `eslint-config-${configName}@latest`;
|
359
|
+
const requiredESLintVersionRange = getPeerDependencies(moduleName).eslint;
|
360
|
+
|
361
|
+
if (!requiredESLintVersionRange) {
|
362
|
+
return false;
|
363
|
+
}
|
364
|
+
|
365
|
+
answers.localESLintVersion = localESLintVersion;
|
366
|
+
answers.requiredESLintVersionRange = requiredESLintVersionRange;
|
367
|
+
|
368
|
+
// Check the version.
|
369
|
+
if (semver.satisfies(localESLintVersion, requiredESLintVersionRange)) {
|
370
|
+
answers.installESLint = false;
|
371
|
+
return false;
|
372
|
+
}
|
373
|
+
|
374
|
+
return true;
|
375
|
+
}
|
376
|
+
|
287
377
|
/* istanbul ignore next: no need to test inquirer*/
|
288
378
|
/**
|
289
379
|
* Ask use a few questions on command prompt
|
@@ -346,6 +436,21 @@ function promptUser() {
|
|
346
436
|
when(answers) {
|
347
437
|
return ((answers.source === "guide" && answers.packageJsonExists) || answers.source === "auto");
|
348
438
|
}
|
439
|
+
},
|
440
|
+
{
|
441
|
+
type: "confirm",
|
442
|
+
name: "installESLint",
|
443
|
+
message(answers) {
|
444
|
+
const verb = semver.ltr(answers.localESLintVersion, answers.requiredESLintVersionRange)
|
445
|
+
? "upgrade"
|
446
|
+
: "downgrade";
|
447
|
+
|
448
|
+
return `The style guide "${answers.styleguide}" requires eslint@${answers.requiredESLintVersionRange}. You are currently using eslint@${answers.localESLintVersion}.\n Do you want to ${verb}?`;
|
449
|
+
},
|
450
|
+
default: true,
|
451
|
+
when(answers) {
|
452
|
+
return answers.source === "guide" && answers.packageJsonExists && hasESLintVersionConflict(answers);
|
453
|
+
}
|
349
454
|
}
|
350
455
|
]).then(earlyAnswers => {
|
351
456
|
|
@@ -355,11 +460,14 @@ function promptUser() {
|
|
355
460
|
log.info("A package.json is necessary to install plugins such as style guides. Run `npm init` to create a package.json file and try again.");
|
356
461
|
return void 0;
|
357
462
|
}
|
463
|
+
if (earlyAnswers.installESLint === false && !semver.satisfies(earlyAnswers.localESLintVersion, earlyAnswers.requiredESLintVersionRange)) {
|
464
|
+
log.info(`Note: it might not work since ESLint's version is mismatched with the ${earlyAnswers.styleguide} config.`);
|
465
|
+
}
|
358
466
|
if (earlyAnswers.styleguide === "airbnb" && !earlyAnswers.airbnbReact) {
|
359
467
|
earlyAnswers.styleguide = "airbnb-base";
|
360
468
|
}
|
361
469
|
|
362
|
-
config = getConfigForStyleGuide(earlyAnswers.styleguide);
|
470
|
+
config = getConfigForStyleGuide(earlyAnswers.styleguide, earlyAnswers.installESLint);
|
363
471
|
writeFile(config, earlyAnswers.format);
|
364
472
|
|
365
473
|
return void 0;
|
@@ -479,6 +587,7 @@ function promptUser() {
|
|
479
587
|
|
480
588
|
const init = {
|
481
589
|
getConfigForStyleGuide,
|
590
|
+
hasESLintVersionConflict,
|
482
591
|
processAnswers,
|
483
592
|
/* istanbul ignore next */initializeConfig() {
|
484
593
|
return promptUser();
|