eslint 4.10.0 → 4.11.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 (103) hide show
  1. package/CHANGELOG.md +36 -22
  2. package/conf/default-cli-options.js +5 -3
  3. package/lib/ast-utils.js +81 -41
  4. package/lib/cli-engine.js +27 -12
  5. package/lib/code-path-analysis/code-path-analyzer.js +8 -4
  6. package/lib/code-path-analysis/code-path-segment.js +4 -2
  7. package/lib/code-path-analysis/code-path-state.js +4 -2
  8. package/lib/config/autoconfig.js +14 -12
  9. package/lib/config/config-file.js +8 -51
  10. package/lib/config/config-initializer.js +10 -6
  11. package/lib/config/config-ops.js +21 -21
  12. package/lib/config/config-rule.js +24 -24
  13. package/lib/config/config-validator.js +38 -36
  14. package/lib/config/plugins.js +8 -35
  15. package/lib/config.js +12 -8
  16. package/lib/formatters/junit.js +21 -15
  17. package/lib/formatters/tap.js +5 -3
  18. package/lib/ignored-paths.js +4 -2
  19. package/lib/linter.js +16 -10
  20. package/lib/rules/.eslintrc.yml +2 -2
  21. package/lib/rules/array-bracket-newline.js +20 -20
  22. package/lib/rules/array-bracket-spacing.js +28 -28
  23. package/lib/rules/array-callback-return.js +13 -9
  24. package/lib/rules/array-element-newline.js +8 -8
  25. package/lib/rules/arrow-body-style.js +12 -6
  26. package/lib/rules/arrow-parens.js +4 -2
  27. package/lib/rules/brace-style.js +14 -14
  28. package/lib/rules/computed-property-spacing.js +22 -22
  29. package/lib/rules/consistent-return.js +4 -4
  30. package/lib/rules/consistent-this.js +4 -2
  31. package/lib/rules/curly.js +13 -9
  32. package/lib/rules/dot-notation.js +5 -5
  33. package/lib/rules/func-call-spacing.js +4 -2
  34. package/lib/rules/getter-return.js +2 -1
  35. package/lib/rules/indent-legacy.js +20 -12
  36. package/lib/rules/indent.js +77 -73
  37. package/lib/rules/key-spacing.js +5 -3
  38. package/lib/rules/lines-around-directive.js +16 -12
  39. package/lib/rules/max-statements-per-line.js +5 -3
  40. package/lib/rules/newline-after-var.js +8 -6
  41. package/lib/rules/newline-before-return.js +9 -7
  42. package/lib/rules/no-await-in-loop.js +17 -9
  43. package/lib/rules/no-bitwise.js +5 -3
  44. package/lib/rules/no-catch-shadow.js +4 -2
  45. package/lib/rules/no-console.js +2 -1
  46. package/lib/rules/no-else-return.js +17 -11
  47. package/lib/rules/no-empty-character-class.js +11 -11
  48. package/lib/rules/no-extra-parens.js +16 -8
  49. package/lib/rules/no-extra-semi.js +5 -3
  50. package/lib/rules/no-global-assign.js +4 -2
  51. package/lib/rules/no-implicit-coercion.js +6 -6
  52. package/lib/rules/no-implied-eval.js +2 -1
  53. package/lib/rules/no-label-var.js +4 -2
  54. package/lib/rules/no-lone-blocks.js +3 -3
  55. package/lib/rules/no-loop-func.js +8 -4
  56. package/lib/rules/no-native-reassign.js +4 -2
  57. package/lib/rules/no-param-reassign.js +4 -2
  58. package/lib/rules/no-regex-spaces.js +1 -1
  59. package/lib/rules/no-restricted-properties.js +10 -10
  60. package/lib/rules/no-return-await.js +6 -6
  61. package/lib/rules/no-self-assign.js +4 -2
  62. package/lib/rules/no-sequences.js +6 -4
  63. package/lib/rules/no-trailing-spaces.js +13 -7
  64. package/lib/rules/no-unreachable.js +4 -2
  65. package/lib/rules/no-use-before-define.js +13 -11
  66. package/lib/rules/no-useless-call.js +1 -25
  67. package/lib/rules/no-useless-escape.js +23 -22
  68. package/lib/rules/no-useless-return.js +14 -8
  69. package/lib/rules/no-whitespace-before-property.js +4 -2
  70. package/lib/rules/object-curly-newline.js +9 -2
  71. package/lib/rules/object-curly-spacing.js +20 -20
  72. package/lib/rules/object-shorthand.js +41 -33
  73. package/lib/rules/operator-assignment.js +9 -9
  74. package/lib/rules/operator-linebreak.js +12 -10
  75. package/lib/rules/padding-line-between-statements.js +4 -2
  76. package/lib/rules/prefer-arrow-callback.js +12 -10
  77. package/lib/rules/prefer-const.js +18 -10
  78. package/lib/rules/prefer-destructuring.js +4 -2
  79. package/lib/rules/prefer-numeric-literals.js +4 -2
  80. package/lib/rules/prefer-promise-reject-errors.js +16 -16
  81. package/lib/rules/prefer-rest-params.js +4 -2
  82. package/lib/rules/prefer-spread.js +1 -25
  83. package/lib/rules/prefer-template.js +33 -29
  84. package/lib/rules/quote-props.js +8 -8
  85. package/lib/rules/semi-style.js +44 -19
  86. package/lib/rules/semi.js +5 -3
  87. package/lib/rules/sort-imports.js +5 -3
  88. package/lib/rules/space-unary-ops.js +61 -61
  89. package/lib/rules/strict.js +8 -8
  90. package/lib/rules/valid-typeof.js +4 -4
  91. package/lib/rules/wrap-iife.js +4 -4
  92. package/lib/rules/yoda.js +9 -7
  93. package/lib/testers/rule-tester.js +43 -34
  94. package/lib/token-store/backward-token-cursor.js +5 -3
  95. package/lib/token-store/forward-token-cursor.js +5 -3
  96. package/lib/token-store/utils.js +8 -4
  97. package/lib/util/glob.js +1 -1
  98. package/lib/util/naming.js +112 -0
  99. package/lib/util/node-event-generator.js +10 -10
  100. package/lib/util/safe-emitter.js +1 -1
  101. package/lib/util/source-code-fixer.js +4 -2
  102. package/lib/util/source-code.js +2 -1
  103. package/package.json +6 -5
@@ -0,0 +1,112 @@
1
+ /**
2
+ * @fileoverview Common helpers for naming of plugins, formatters and configs
3
+ */
4
+ "use strict";
5
+
6
+ //------------------------------------------------------------------------------
7
+ // Requirements
8
+ //------------------------------------------------------------------------------
9
+
10
+ const pathUtil = require("../util/path-util");
11
+
12
+ //------------------------------------------------------------------------------
13
+ // Private
14
+ //------------------------------------------------------------------------------
15
+
16
+ const NAMESPACE_REGEX = /^@.*\//i;
17
+
18
+ /**
19
+ * Brings package name to correct format based on prefix
20
+ * @param {string} name The name of the package.
21
+ * @param {string} prefix Can be either "eslint-plugin", "eslint-config" or "eslint-formatter"
22
+ * @returns {string} Normalized name of the package
23
+ * @private
24
+ */
25
+ function normalizePackageName(name, prefix) {
26
+
27
+ /**
28
+ * On Windows, name can come in with Windows slashes instead of Unix slashes.
29
+ * Normalize to Unix first to avoid errors later on.
30
+ * https://github.com/eslint/eslint/issues/5644
31
+ */
32
+ if (name.indexOf("\\") > -1) {
33
+ name = pathUtil.convertPathToPosix(name);
34
+ }
35
+
36
+ if (name.charAt(0) === "@") {
37
+
38
+ /**
39
+ * it's a scoped package
40
+ * package name is the prefix, or just a username
41
+ */
42
+ const scopedPackageShortcutRegex = new RegExp(`^(@[^/]+)(?:/(?:${prefix})?)?$`),
43
+ scopedPackageNameRegex = new RegExp(`^${prefix}(-|$)`);
44
+
45
+ if (scopedPackageShortcutRegex.test(name)) {
46
+ name = name.replace(scopedPackageShortcutRegex, `$1/${prefix}`);
47
+ } else if (!scopedPackageNameRegex.test(name.split("/")[1])) {
48
+
49
+ /**
50
+ * for scoped packages, insert the prefix after the first / unless
51
+ * the path is already @scope/eslint or @scope/eslint-xxx-yyy
52
+ */
53
+ name = name.replace(/^@([^/]+)\/(.*)$/, `@$1/${prefix}-$2`);
54
+ }
55
+ } else if (name.indexOf(`${prefix}-`) !== 0) {
56
+ name = `${prefix}-${name}`;
57
+ }
58
+
59
+ return name;
60
+ }
61
+
62
+ /**
63
+ * Removes the prefix from a term.
64
+ * @param {string} prefix The prefix to remove.
65
+ * @param {string} term The term which may have the prefix.
66
+ * @returns {string} The term without prefix.
67
+ */
68
+ function removePrefixFromTerm(prefix, term) {
69
+ return term.startsWith(prefix) ? term.slice(prefix.length) : term;
70
+ }
71
+
72
+ /**
73
+ * Adds a prefix to a term.
74
+ * @param {string} prefix The prefix to add.
75
+ * @param {string} term The term which may not have the prefix.
76
+ * @returns {string} The term with prefix.
77
+ */
78
+ function addPrefixToTerm(prefix, term) {
79
+ return term.startsWith(prefix) ? term : `${prefix}${term}`;
80
+ }
81
+
82
+ /**
83
+ * Gets the scope (namespace) of a term.
84
+ * @param {string} term The term which may have the namespace.
85
+ * @returns {string} The namepace of the term if it has one.
86
+ */
87
+ function getNamespaceFromTerm(term) {
88
+ const match = term.match(NAMESPACE_REGEX);
89
+
90
+ return match ? match[0] : "";
91
+ }
92
+
93
+ /**
94
+ * Removes the namespace from a term.
95
+ * @param {string} term The term which may have the namespace.
96
+ * @returns {string} The name of the plugin without the namespace.
97
+ */
98
+ function removeNamespaceFromTerm(term) {
99
+ return term.replace(NAMESPACE_REGEX, "");
100
+ }
101
+
102
+ //------------------------------------------------------------------------------
103
+ // Public Interface
104
+ //------------------------------------------------------------------------------
105
+
106
+ module.exports = {
107
+ normalizePackageName,
108
+ removePrefixFromTerm,
109
+ addPrefixToTerm,
110
+ getNamespaceFromTerm,
111
+ removeNamespaceFromTerm
112
+ };
@@ -33,10 +33,10 @@ const lodash = require("lodash");
33
33
  //------------------------------------------------------------------------------
34
34
 
35
35
  /**
36
- * Gets the possible types of a selector
37
- * @param {Object} parsedSelector An object (from esquery) describing the matching behavior of the selector
38
- * @returns {string[]|null} The node types that could possibly trigger this selector, or `null` if all node types could trigger it
39
- */
36
+ * Gets the possible types of a selector
37
+ * @param {Object} parsedSelector An object (from esquery) describing the matching behavior of the selector
38
+ * @returns {string[]|null} The node types that could possibly trigger this selector, or `null` if all node types could trigger it
39
+ */
40
40
  function getPossibleTypes(parsedSelector) {
41
41
  switch (parsedSelector.type) {
42
42
  case "identifier":
@@ -203,12 +203,12 @@ const parseSelector = lodash.memoize(rawSelector => {
203
203
  class NodeEventGenerator {
204
204
 
205
205
  /**
206
- * @param {SafeEmitter} emitter
207
- * An SafeEmitter which is the destination of events. This emitter must already
208
- * have registered listeners for all of the events that it needs to listen for.
209
- * (See lib/util/safe-emitter.js for more details on `SafeEmitter`.)
210
- * @returns {NodeEventGenerator} new instance
211
- */
206
+ * @param {SafeEmitter} emitter
207
+ * An SafeEmitter which is the destination of events. This emitter must already
208
+ * have registered listeners for all of the events that it needs to listen for.
209
+ * (See lib/util/safe-emitter.js for more details on `SafeEmitter`.)
210
+ * @returns {NodeEventGenerator} new instance
211
+ */
212
212
  constructor(emitter) {
213
213
  this.emitter = emitter;
214
214
  this.currentAncestry = [];
@@ -10,7 +10,7 @@
10
10
  //------------------------------------------------------------------------------
11
11
 
12
12
  /**
13
- * An object describing an AST selector
13
+ * An event emitter
14
14
  * @typedef {Object} SafeEmitter
15
15
  * @property {function(eventName: string, listenerFunc: Function): void} on Adds a listener for a given event name
16
16
  * @property {function(eventName: string, arg1?: any, arg2?: any, arg3?: any)} emit Emits an event with a given name.
@@ -122,8 +122,10 @@ SourceCodeFixer.applyFixes = function(sourceText, messages, shouldFix) {
122
122
  if (typeof shouldFix !== "function" || shouldFix(problem)) {
123
123
  attemptFix(problem);
124
124
 
125
- // The only time attemptFix will fail is if a previous fix was
126
- // applied which conflicts with it. So we can mark this as true.
125
+ /*
126
+ * The only time attemptFix will fail is if a previous fix was
127
+ * applied which conflicts with it. So we can mark this as true.
128
+ */
127
129
  fixesWereApplied = true;
128
130
  } else {
129
131
  remainingMessages.push(problem);
@@ -227,7 +227,8 @@ class SourceCode extends TokenStore {
227
227
  }
228
228
  } else {
229
229
 
230
- /* Return comments as trailing comments of nodes that only contain
230
+ /*
231
+ * Return comments as trailing comments of nodes that only contain
231
232
  * comments (to mimic the comment attachment behavior present in Espree).
232
233
  */
233
234
  if ((node.type === "BlockStatement" || node.type === "ClassBody") && node.body.length === 0 ||
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "eslint",
3
- "version": "4.10.0",
3
+ "version": "4.11.0",
4
4
  "author": "Nicholas C. Zakas <nicholas+npm@nczconsulting.com>",
5
5
  "description": "An AST-based pattern checker for JavaScript.",
6
6
  "bin": {
@@ -34,7 +34,7 @@
34
34
  "homepage": "https://eslint.org",
35
35
  "bugs": "https://github.com/eslint/eslint/issues/",
36
36
  "dependencies": {
37
- "ajv": "^5.2.0",
37
+ "ajv": "^5.3.0",
38
38
  "babel-code-frame": "^6.22.0",
39
39
  "chalk": "^2.1.0",
40
40
  "concat-stream": "^1.6.0",
@@ -42,7 +42,7 @@
42
42
  "debug": "^3.0.1",
43
43
  "doctrine": "^2.0.0",
44
44
  "eslint-scope": "^3.7.1",
45
- "espree": "^3.5.1",
45
+ "espree": "^3.5.2",
46
46
  "esquery": "^1.0.0",
47
47
  "estraverse": "^4.2.0",
48
48
  "esutils": "^2.0.2",
@@ -55,7 +55,7 @@
55
55
  "inquirer": "^3.0.6",
56
56
  "is-resolvable": "^1.0.0",
57
57
  "js-yaml": "^3.9.1",
58
- "json-stable-stringify": "^1.0.1",
58
+ "json-stable-stringify-without-jsonify": "^1.0.1",
59
59
  "levn": "^0.3.0",
60
60
  "lodash": "^4.17.4",
61
61
  "minimatch": "^3.0.2",
@@ -86,7 +86,9 @@
86
86
  "ejs": "^2.5.6",
87
87
  "eslint-plugin-eslint-plugin": "^1.2.0",
88
88
  "eslint-plugin-node": "^5.1.0",
89
+ "eslint-plugin-rulesdir": "^0.1.0",
89
90
  "eslint-release": "^0.10.1",
91
+ "eslint-rule-composer": "^0.1.0",
90
92
  "eslump": "1.6.0",
91
93
  "esprima": "^4.0.0",
92
94
  "esprima-fb": "^15001.1001.0-dev-harmony-fb",
@@ -106,7 +108,6 @@
106
108
  "phantomjs-prebuilt": "^2.1.14",
107
109
  "proxyquire": "^1.8.0",
108
110
  "shelljs": "^0.7.7",
109
- "shelljs-nodecli": "~0.1.1",
110
111
  "sinon": "^3.2.1",
111
112
  "temp": "^0.8.3",
112
113
  "through": "^2.3.8"