eslint 5.9.0 → 5.12.0

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.
Files changed (49) hide show
  1. package/CHANGELOG.md +55 -0
  2. package/README.md +2 -2
  3. package/conf/eslint-recommended.js +1 -0
  4. package/lib/cli-engine.js +1 -1
  5. package/lib/config/autoconfig.js +0 -1
  6. package/lib/config/config-file.js +2 -2
  7. package/lib/config/config-rule.js +4 -4
  8. package/lib/config/config-validator.js +2 -2
  9. package/lib/config.js +15 -2
  10. package/lib/linter.js +8 -120
  11. package/lib/rules/array-element-newline.js +0 -1
  12. package/lib/rules/block-spacing.js +2 -2
  13. package/lib/rules/camelcase.js +24 -14
  14. package/lib/rules/capitalized-comments.js +2 -2
  15. package/lib/rules/comma-style.js +7 -2
  16. package/lib/rules/eqeqeq.js +0 -1
  17. package/lib/rules/func-name-matching.js +4 -4
  18. package/lib/rules/handle-callback-err.js +1 -1
  19. package/lib/rules/implicit-arrow-linebreak.js +143 -2
  20. package/lib/rules/indent-legacy.js +0 -3
  21. package/lib/rules/indent.js +29 -23
  22. package/lib/rules/keyword-spacing.js +5 -1
  23. package/lib/rules/max-classes-per-file.js +1 -1
  24. package/lib/rules/newline-before-return.js +1 -1
  25. package/lib/rules/no-constant-condition.js +0 -1
  26. package/lib/rules/no-else-return.js +0 -1
  27. package/lib/rules/no-implied-eval.js +1 -1
  28. package/lib/rules/no-irregular-whitespace.js +1 -1
  29. package/lib/rules/no-param-reassign.js +8 -0
  30. package/lib/rules/no-restricted-imports.js +1 -1
  31. package/lib/rules/no-this-before-super.js +0 -1
  32. package/lib/rules/no-useless-catch.js +52 -0
  33. package/lib/rules/object-curly-newline.js +0 -1
  34. package/lib/rules/one-var.js +0 -1
  35. package/lib/rules/padding-line-between-statements.js +37 -0
  36. package/lib/rules/prefer-object-spread.js +2 -2
  37. package/lib/rules/quotes.js +48 -25
  38. package/lib/rules/require-jsdoc.js +4 -1
  39. package/lib/rules/sort-imports.js +43 -37
  40. package/lib/rules/space-in-parens.js +0 -1
  41. package/lib/rules/space-infix-ops.js +4 -1
  42. package/lib/rules/valid-jsdoc.js +4 -1
  43. package/lib/util/config-comment-parser.js +144 -0
  44. package/lib/util/glob-utils.js +1 -1
  45. package/lib/{ignored-paths.js → util/ignored-paths.js} +4 -4
  46. package/lib/{report-translator.js → util/report-translator.js} +2 -2
  47. package/lib/util/source-code.js +2 -1
  48. package/messages/all-files-ignored.txt +1 -1
  49. package/package.json +7 -8
@@ -36,6 +36,9 @@ module.exports = {
36
36
  minItems: 4,
37
37
  maxItems: 4
38
38
  },
39
+ ignoreDeclarationSort: {
40
+ type: "boolean"
41
+ },
39
42
  ignoreMemberSort: {
40
43
  type: "boolean"
41
44
  }
@@ -51,6 +54,7 @@ module.exports = {
51
54
 
52
55
  const configuration = context.options[0] || {},
53
56
  ignoreCase = configuration.ignoreCase || false,
57
+ ignoreDeclarationSort = configuration.ignoreDeclarationSort || false,
54
58
  ignoreMemberSort = configuration.ignoreMemberSort || false,
55
59
  memberSyntaxSortOrder = configuration.memberSyntaxSortOrder || ["none", "all", "multiple", "single"],
56
60
  sourceCode = context.getSourceCode();
@@ -105,44 +109,48 @@ module.exports = {
105
109
 
106
110
  return {
107
111
  ImportDeclaration(node) {
108
- if (previousDeclaration) {
109
- const currentMemberSyntaxGroupIndex = getMemberParameterGroupIndex(node),
110
- previousMemberSyntaxGroupIndex = getMemberParameterGroupIndex(previousDeclaration);
111
- let currentLocalMemberName = getFirstLocalMemberName(node),
112
- previousLocalMemberName = getFirstLocalMemberName(previousDeclaration);
113
-
114
- if (ignoreCase) {
115
- previousLocalMemberName = previousLocalMemberName && previousLocalMemberName.toLowerCase();
116
- currentLocalMemberName = currentLocalMemberName && currentLocalMemberName.toLowerCase();
117
- }
118
-
119
- /*
120
- * When the current declaration uses a different member syntax,
121
- * then check if the ordering is correct.
122
- * Otherwise, make a default string compare (like rule sort-vars to be consistent) of the first used local member name.
123
- */
124
- if (currentMemberSyntaxGroupIndex !== previousMemberSyntaxGroupIndex) {
125
- if (currentMemberSyntaxGroupIndex < previousMemberSyntaxGroupIndex) {
126
- context.report({
127
- node,
128
- message: "Expected '{{syntaxA}}' syntax before '{{syntaxB}}' syntax.",
129
- data: {
130
- syntaxA: memberSyntaxSortOrder[currentMemberSyntaxGroupIndex],
131
- syntaxB: memberSyntaxSortOrder[previousMemberSyntaxGroupIndex]
132
- }
133
- });
112
+ if (!ignoreDeclarationSort) {
113
+ if (previousDeclaration) {
114
+ const currentMemberSyntaxGroupIndex = getMemberParameterGroupIndex(node),
115
+ previousMemberSyntaxGroupIndex = getMemberParameterGroupIndex(previousDeclaration);
116
+ let currentLocalMemberName = getFirstLocalMemberName(node),
117
+ previousLocalMemberName = getFirstLocalMemberName(previousDeclaration);
118
+
119
+ if (ignoreCase) {
120
+ previousLocalMemberName = previousLocalMemberName && previousLocalMemberName.toLowerCase();
121
+ currentLocalMemberName = currentLocalMemberName && currentLocalMemberName.toLowerCase();
134
122
  }
135
- } else {
136
- if (previousLocalMemberName &&
137
- currentLocalMemberName &&
138
- currentLocalMemberName < previousLocalMemberName
139
- ) {
140
- context.report({
141
- node,
142
- message: "Imports should be sorted alphabetically."
143
- });
123
+
124
+ /*
125
+ * When the current declaration uses a different member syntax,
126
+ * then check if the ordering is correct.
127
+ * Otherwise, make a default string compare (like rule sort-vars to be consistent) of the first used local member name.
128
+ */
129
+ if (currentMemberSyntaxGroupIndex !== previousMemberSyntaxGroupIndex) {
130
+ if (currentMemberSyntaxGroupIndex < previousMemberSyntaxGroupIndex) {
131
+ context.report({
132
+ node,
133
+ message: "Expected '{{syntaxA}}' syntax before '{{syntaxB}}' syntax.",
134
+ data: {
135
+ syntaxA: memberSyntaxSortOrder[currentMemberSyntaxGroupIndex],
136
+ syntaxB: memberSyntaxSortOrder[previousMemberSyntaxGroupIndex]
137
+ }
138
+ });
139
+ }
140
+ } else {
141
+ if (previousLocalMemberName &&
142
+ currentLocalMemberName &&
143
+ currentLocalMemberName < previousLocalMemberName
144
+ ) {
145
+ context.report({
146
+ node,
147
+ message: "Imports should be sorted alphabetically."
148
+ });
149
+ }
144
150
  }
145
151
  }
152
+
153
+ previousDeclaration = node;
146
154
  }
147
155
 
148
156
  if (!ignoreMemberSort) {
@@ -191,8 +199,6 @@ module.exports = {
191
199
  });
192
200
  }
193
201
  }
194
-
195
- previousDeclaration = node;
196
202
  }
197
203
  };
198
204
  }
@@ -61,7 +61,6 @@ module.exports = {
61
61
 
62
62
  /**
63
63
  * Produces an object with the opener and closer exception values
64
- * @param {Object} opts The exception options
65
64
  * @returns {Object} `openers` and `closers` exception values
66
65
  * @private
67
66
  */
@@ -69,7 +69,10 @@ module.exports = {
69
69
  context.report({
70
70
  node: mainNode,
71
71
  loc: culpritToken.loc.start,
72
- message: "Infix operators must be spaced.",
72
+ message: "Operator '{{operator}}' must be spaced.",
73
+ data: {
74
+ operator: culpritToken.value
75
+ },
73
76
  fix(fixer) {
74
77
  const previousToken = sourceCode.getTokenBefore(culpritToken);
75
78
  const afterToken = sourceCode.getTokenAfter(culpritToken);
@@ -64,7 +64,10 @@ module.exports = {
64
64
  }
65
65
  ],
66
66
 
67
- fixable: "code"
67
+ fixable: "code",
68
+
69
+ deprecated: true,
70
+ replacedBy: []
68
71
  },
69
72
 
70
73
  create(context) {
@@ -0,0 +1,144 @@
1
+ /**
2
+ * @fileoverview Config Comment Parser
3
+ * @author Nicholas C. Zakas
4
+ */
5
+
6
+ /* eslint-disable class-methods-use-this*/
7
+ "use strict";
8
+
9
+ //------------------------------------------------------------------------------
10
+ // Requirements
11
+ //------------------------------------------------------------------------------
12
+
13
+ const levn = require("levn"),
14
+ ConfigOps = require("../config/config-ops");
15
+
16
+ const debug = require("debug")("eslint:config-comment-parser");
17
+
18
+ //------------------------------------------------------------------------------
19
+ // Public Interface
20
+ //------------------------------------------------------------------------------
21
+
22
+ /**
23
+ * Object to parse ESLint configuration comments inside JavaScript files.
24
+ * @name ConfigCommentParser
25
+ */
26
+ module.exports = class ConfigCommentParser {
27
+
28
+ /**
29
+ * Parses a list of "name:boolean_value" or/and "name" options divided by comma or
30
+ * whitespace. Used for "global" and "exported" comments.
31
+ * @param {string} string The string to parse.
32
+ * @param {Comment} comment The comment node which has the string.
33
+ * @returns {Object} Result map object of names and boolean values
34
+ */
35
+ parseBooleanConfig(string, comment) {
36
+ debug("Parsing Boolean config");
37
+
38
+ const items = {};
39
+
40
+ // Collapse whitespace around `:` and `,` to make parsing easier
41
+ const trimmedString = string.replace(/\s*([:,])\s*/g, "$1");
42
+
43
+ trimmedString.split(/\s|,+/).forEach(name => {
44
+ if (!name) {
45
+ return;
46
+ }
47
+
48
+ // value defaults to "false" (if not provided), e.g: "foo" => ["foo", "false"]
49
+ const [key, value = "false"] = name.split(":");
50
+
51
+ items[key] = {
52
+ value: value === "true",
53
+ comment
54
+ };
55
+ });
56
+ return items;
57
+ }
58
+
59
+ /**
60
+ * Parses a JSON-like config.
61
+ * @param {string} string The string to parse.
62
+ * @param {Object} location Start line and column of comments for potential error message.
63
+ * @returns {({success: true, config: Object}|{success: false, error: Problem})} Result map object
64
+ */
65
+ parseJsonConfig(string, location) {
66
+ debug("Parsing JSON config");
67
+
68
+ let items = {};
69
+
70
+ // Parses a JSON-like comment by the same way as parsing CLI option.
71
+ try {
72
+ items = levn.parse("Object", string) || {};
73
+
74
+ // Some tests say that it should ignore invalid comments such as `/*eslint no-alert:abc*/`.
75
+ // Also, commaless notations have invalid severity:
76
+ // "no-alert: 2 no-console: 2" --> {"no-alert": "2 no-console: 2"}
77
+ // Should ignore that case as well.
78
+ if (ConfigOps.isEverySeverityValid(items)) {
79
+ return {
80
+ success: true,
81
+ config: items
82
+ };
83
+ }
84
+ } catch (ex) {
85
+
86
+ debug("Levn parsing failed; falling back to manual parsing.");
87
+
88
+ // ignore to parse the string by a fallback.
89
+ }
90
+
91
+ /*
92
+ * Optionator cannot parse commaless notations.
93
+ * But we are supporting that. So this is a fallback for that.
94
+ */
95
+ items = {};
96
+ const normalizedString = string.replace(/([a-zA-Z0-9\-/]+):/g, "\"$1\":").replace(/(]|[0-9])\s+(?=")/, "$1,");
97
+
98
+ try {
99
+ items = JSON.parse(`{${normalizedString}}`);
100
+ } catch (ex) {
101
+ debug("Manual parsing failed.");
102
+
103
+ return {
104
+ success: false,
105
+ error: {
106
+ ruleId: null,
107
+ fatal: true,
108
+ severity: 2,
109
+ message: `Failed to parse JSON from '${normalizedString}': ${ex.message}`,
110
+ line: location.start.line,
111
+ column: location.start.column + 1
112
+ }
113
+ };
114
+
115
+ }
116
+
117
+ return {
118
+ success: true,
119
+ config: items
120
+ };
121
+ }
122
+
123
+ /**
124
+ * Parses a config of values separated by comma.
125
+ * @param {string} string The string to parse.
126
+ * @returns {Object} Result map of values and true values
127
+ */
128
+ parseListConfig(string) {
129
+ debug("Parsing list config");
130
+
131
+ const items = {};
132
+
133
+ // Collapse whitespace around commas
134
+ string.replace(/\s*,\s*/g, ",").split(/,+/).forEach(name => {
135
+ const trimmedName = name.trim();
136
+
137
+ if (trimmedName) {
138
+ items[trimmedName] = true;
139
+ }
140
+ });
141
+ return items;
142
+ }
143
+
144
+ };
@@ -14,7 +14,7 @@ const lodash = require("lodash"),
14
14
  GlobSync = require("./glob"),
15
15
 
16
16
  pathUtils = require("./path-utils"),
17
- IgnoredPaths = require("../ignored-paths");
17
+ IgnoredPaths = require("./ignored-paths");
18
18
 
19
19
  const debug = require("debug")("eslint:glob-utils");
20
20
 
@@ -12,7 +12,7 @@
12
12
  const fs = require("fs"),
13
13
  path = require("path"),
14
14
  ignore = require("ignore"),
15
- pathUtils = require("./util/path-utils");
15
+ pathUtils = require("./path-utils");
16
16
 
17
17
  const debug = require("debug")("eslint:ignored-paths");
18
18
 
@@ -296,7 +296,7 @@ class IgnoredPaths {
296
296
  /**
297
297
  * read ignore filepath
298
298
  * @param {string} filePath, file to add to ig
299
- * @returns {array} raw ignore rules
299
+ * @returns {Array} raw ignore rules
300
300
  */
301
301
  readIgnoreFile(filePath) {
302
302
  if (typeof this.cache[filePath] === "undefined") {
@@ -307,8 +307,8 @@ class IgnoredPaths {
307
307
 
308
308
  /**
309
309
  * add ignore file to node-ignore instance
310
- * @param {Object} ig, instance of node-ignore
311
- * @param {string} filePath, file to add to ig
310
+ * @param {Object} ig instance of node-ignore
311
+ * @param {string} filePath file to add to ig
312
312
  * @returns {void}
313
313
  */
314
314
  addIgnoreFile(ig, filePath) {
@@ -10,8 +10,8 @@
10
10
  //------------------------------------------------------------------------------
11
11
 
12
12
  const assert = require("assert");
13
- const ruleFixer = require("./util/rule-fixer");
14
- const interpolate = require("./util/interpolate");
13
+ const ruleFixer = require("./rule-fixer");
14
+ const interpolate = require("./interpolate");
15
15
 
16
16
  //------------------------------------------------------------------------------
17
17
  // Typedefs
@@ -87,7 +87,7 @@ class SourceCode extends TokenStore {
87
87
  * @param {string|Object} textOrConfig - The source code text or config object.
88
88
  * @param {string} textOrConfig.text - The source code text.
89
89
  * @param {ASTNode} textOrConfig.ast - The Program node of the AST representing the code. This AST should be created from the text that BOM was stripped.
90
- * @param {Object|null} textOrConfig.parserServices - The parser srevices.
90
+ * @param {Object|null} textOrConfig.parserServices - The parser services.
91
91
  * @param {ScopeManager|null} textOrConfig.scopeManager - The scope of this source code.
92
92
  * @param {Object|null} textOrConfig.visitorKeys - The visitor keys to traverse AST.
93
93
  * @param {ASTNode} [astIfNoConfig] - The Program node of the AST representing the code. This AST should be created from the text that BOM was stripped.
@@ -316,6 +316,7 @@ class SourceCode extends TokenStore {
316
316
  * @returns {Token|null} The Block comment token containing the JSDoc comment
317
317
  * for the given node or null if not found.
318
318
  * @public
319
+ * @deprecated
319
320
  */
320
321
  getJSDocComment(node) {
321
322
 
@@ -1,4 +1,4 @@
1
- All of the files matching the glob pattern "<%= pattern %>" are ignored.
1
+ You are linting "<%= pattern %>", but all of the files matching the glob pattern "<%= pattern %>" are ignored.
2
2
 
3
3
  If you don't want to lint these files, remove the pattern "<%= pattern %>" from the list of arguments passed to ESLint.
4
4
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "eslint",
3
- "version": "5.9.0",
3
+ "version": "5.12.0",
4
4
  "author": "Nicholas C. Zakas <nicholas+npm@nczconsulting.com>",
5
5
  "description": "An AST-based pattern checker for JavaScript.",
6
6
  "bin": {
@@ -44,7 +44,7 @@
44
44
  "eslint-scope": "^4.0.0",
45
45
  "eslint-utils": "^1.3.1",
46
46
  "eslint-visitor-keys": "^1.0.0",
47
- "espree": "^4.0.0",
47
+ "espree": "^5.0.0",
48
48
  "esquery": "^1.0.1",
49
49
  "esutils": "^2.0.2",
50
50
  "file-entry-cache": "^2.0.0",
@@ -52,9 +52,9 @@
52
52
  "glob": "^7.1.2",
53
53
  "globals": "^11.7.0",
54
54
  "ignore": "^4.0.6",
55
+ "import-fresh": "^3.0.0",
55
56
  "imurmurhash": "^0.1.4",
56
57
  "inquirer": "^6.1.0",
57
- "is-resolvable": "^1.1.0",
58
58
  "js-yaml": "^3.12.0",
59
59
  "json-stable-stringify-without-jsonify": "^1.0.1",
60
60
  "levn": "^0.3.0",
@@ -67,7 +67,6 @@
67
67
  "pluralize": "^7.0.0",
68
68
  "progress": "^2.0.0",
69
69
  "regexpp": "^2.0.1",
70
- "require-uncached": "^1.0.3",
71
70
  "semver": "^5.5.1",
72
71
  "strip-ansi": "^4.0.0",
73
72
  "strip-json-comments": "^2.0.1",
@@ -87,10 +86,10 @@
87
86
  "coveralls": "^3.0.1",
88
87
  "dateformat": "^3.0.3",
89
88
  "ejs": "^2.6.1",
90
- "eslint-plugin-eslint-plugin": "^1.4.1",
89
+ "eslint-plugin-eslint-plugin": "^2.0.1",
91
90
  "eslint-plugin-node": "^8.0.0",
92
91
  "eslint-plugin-rulesdir": "^0.1.0",
93
- "eslint-release": "^1.0.0",
92
+ "eslint-release": "^1.2.0",
94
93
  "eslint-rule-composer": "^0.3.0",
95
94
  "eslump": "^1.6.2",
96
95
  "esprima": "^4.0.1",
@@ -98,17 +97,17 @@
98
97
  "jsdoc": "^3.5.5",
99
98
  "karma": "^3.0.0",
100
99
  "karma-babel-preprocessor": "^7.0.0",
100
+ "karma-chrome-launcher": "^2.2.0",
101
101
  "karma-mocha": "^1.3.0",
102
102
  "karma-mocha-reporter": "^2.2.3",
103
- "karma-phantomjs-launcher": "^1.0.4",
104
103
  "leche": "^2.2.3",
105
104
  "load-perf": "^0.2.0",
106
105
  "markdownlint": "^0.11.0",
107
106
  "mocha": "^5.0.5",
108
107
  "mock-fs": "^4.6.0",
109
108
  "npm-license": "^0.3.3",
110
- "phantomjs-prebuilt": "^2.1.16",
111
109
  "proxyquire": "^2.0.1",
110
+ "puppeteer": "^1.9.0",
112
111
  "shelljs": "^0.8.2",
113
112
  "sinon": "^3.3.0",
114
113
  "temp": "^0.8.3",