eslint 3.18.0 → 3.19.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 (38) hide show
  1. package/CHANGELOG.md +39 -0
  2. package/README.md +1 -0
  3. package/lib/config/config-rule.js +14 -10
  4. package/lib/config/plugins.js +19 -8
  5. package/lib/eslint.js +6 -5
  6. package/lib/formatters/codeframe.js +4 -9
  7. package/lib/rules/arrow-body-style.js +2 -2
  8. package/lib/rules/arrow-parens.js +9 -3
  9. package/lib/rules/comma-dangle.js +3 -2
  10. package/lib/rules/comma-spacing.js +4 -14
  11. package/lib/rules/comma-style.js +8 -14
  12. package/lib/rules/curly.js +2 -2
  13. package/lib/rules/dot-notation.js +12 -6
  14. package/lib/rules/lines-around-directive.js +1 -1
  15. package/lib/rules/new-parens.js +7 -21
  16. package/lib/rules/no-cond-assign.js +4 -17
  17. package/lib/rules/no-else-return.js +6 -3
  18. package/lib/rules/no-extra-parens.js +47 -103
  19. package/lib/rules/no-extra-semi.js +3 -2
  20. package/lib/rules/no-implicit-coercion.js +21 -8
  21. package/lib/rules/no-native-reassign.js +1 -1
  22. package/lib/rules/no-negated-in-lhs.js +1 -1
  23. package/lib/rules/no-param-reassign.js +8 -1
  24. package/lib/rules/no-restricted-syntax.js +33 -6
  25. package/lib/rules/no-sequences.js +2 -2
  26. package/lib/rules/no-unsafe-negation.js +1 -1
  27. package/lib/rules/no-useless-computed-key.js +12 -1
  28. package/lib/rules/object-curly-spacing.js +2 -2
  29. package/lib/rules/object-shorthand.js +8 -2
  30. package/lib/rules/operator-assignment.js +20 -3
  31. package/lib/rules/prefer-const.js +1 -1
  32. package/lib/rules/quotes.js +1 -0
  33. package/lib/rules/semi-spacing.js +2 -15
  34. package/lib/rules/semi.js +4 -12
  35. package/lib/rules/space-before-function-paren.js +53 -77
  36. package/lib/rules/space-in-parens.js +4 -8
  37. package/lib/util/glob-util.js +1 -1
  38. package/package.json +29 -29
@@ -51,31 +51,9 @@ module.exports = {
51
51
  },
52
52
 
53
53
  create(context) {
54
-
55
- const configuration = context.options[0],
56
- sourceCode = context.getSourceCode();
57
- let requireAnonymousFunctionSpacing = true,
58
- forbidAnonymousFunctionSpacing = false,
59
- requireNamedFunctionSpacing = true,
60
- forbidNamedFunctionSpacing = false,
61
- requireArrowFunctionSpacing = false,
62
- forbidArrowFunctionSpacing = false;
63
-
64
- if (typeof configuration === "object") {
65
- requireAnonymousFunctionSpacing = (
66
- !configuration.anonymous || configuration.anonymous === "always");
67
- forbidAnonymousFunctionSpacing = configuration.anonymous === "never";
68
- requireNamedFunctionSpacing = (
69
- !configuration.named || configuration.named === "always");
70
- forbidNamedFunctionSpacing = configuration.named === "never";
71
- requireArrowFunctionSpacing = configuration.asyncArrow === "always";
72
- forbidArrowFunctionSpacing = configuration.asyncArrow === "never";
73
- } else if (configuration === "never") {
74
- requireAnonymousFunctionSpacing = false;
75
- forbidAnonymousFunctionSpacing = true;
76
- requireNamedFunctionSpacing = false;
77
- forbidNamedFunctionSpacing = true;
78
- }
54
+ const sourceCode = context.getSourceCode();
55
+ const baseConfig = typeof context.options[0] === "string" ? context.options[0] : "always";
56
+ const overrideConfig = typeof context.options[0] === "object" ? context.options[0] : {};
79
57
 
80
58
  /**
81
59
  * Determines whether a function has a name.
@@ -100,69 +78,67 @@ module.exports = {
100
78
  }
101
79
 
102
80
  /**
103
- * Validates the spacing before function parentheses.
104
- * @param {ASTNode} node The node to be validated.
105
- * @returns {void}
81
+ * Gets the config for a given function
82
+ * @param {ASTNode} node The function node
83
+ * @returns {string} "always", "never", or "ignore"
106
84
  */
107
- function validateSpacingBeforeParentheses(node) {
108
- const isArrow = node.type === "ArrowFunctionExpression";
109
- const isNamed = !isArrow && isNamedFunction(node);
110
- const isAnonymousGenerator = node.generator && !isNamed;
111
- const isNormalArrow = isArrow && !node.async;
112
- const isArrowWithoutParens = isArrow && sourceCode.getFirstToken(node, 1).value !== "(";
113
- let forbidSpacing, requireSpacing;
114
-
115
- // isAnonymousGenerator → `generator-star-spacing` should warn it. E.g. `function* () {}`
116
- // isNormalArrow ignore always.
117
- // isArrowWithoutParens → ignore always. E.g. `async a => a`
118
- if (isAnonymousGenerator || isNormalArrow || isArrowWithoutParens) {
119
- return;
85
+ function getConfigForFunction(node) {
86
+ if (node.type === "ArrowFunctionExpression") {
87
+
88
+ // Always ignore non-async functions and arrow functions without parens, e.g. async foo => bar
89
+ if (node.async && astUtils.isOpeningParenToken(sourceCode.getFirstToken(node, { skip: 1 }))) {
90
+
91
+ // For backwards compatibility, the base config does not apply to async arrow functions.
92
+ return overrideConfig.asyncArrow || "ignore";
93
+ }
94
+ } else if (isNamedFunction(node)) {
95
+ return overrideConfig.named || baseConfig;
96
+
97
+ // `generator-star-spacing` should warn anonymous generators. E.g. `function* () {}`
98
+ } else if (!node.generator) {
99
+ return overrideConfig.anonymous || baseConfig;
120
100
  }
121
101
 
122
- if (isArrow) {
123
- forbidSpacing = forbidArrowFunctionSpacing;
124
- requireSpacing = requireArrowFunctionSpacing;
125
- } else if (isNamed) {
126
- forbidSpacing = forbidNamedFunctionSpacing;
127
- requireSpacing = requireNamedFunctionSpacing;
128
- } else {
129
- forbidSpacing = forbidAnonymousFunctionSpacing;
130
- requireSpacing = requireAnonymousFunctionSpacing;
102
+ return "ignore";
103
+ }
104
+
105
+ /**
106
+ * Checks the parens of a function node
107
+ * @param {ASTNode} node A function node
108
+ * @returns {void}
109
+ */
110
+ function checkFunction(node) {
111
+ const functionConfig = getConfigForFunction(node);
112
+
113
+ if (functionConfig === "ignore") {
114
+ return;
131
115
  }
132
116
 
133
117
  const rightToken = sourceCode.getFirstToken(node, astUtils.isOpeningParenToken);
134
118
  const leftToken = sourceCode.getTokenBefore(rightToken);
135
- const location = leftToken.loc.end;
136
-
137
- if (sourceCode.isSpaceBetweenTokens(leftToken, rightToken)) {
138
- if (forbidSpacing) {
139
- context.report({
140
- node,
141
- loc: location,
142
- message: "Unexpected space before function parentheses.",
143
- fix(fixer) {
144
- return fixer.removeRange([leftToken.range[1], rightToken.range[0]]);
145
- }
146
- });
147
- }
148
- } else {
149
- if (requireSpacing) {
150
- context.report({
151
- node,
152
- loc: location,
153
- message: "Missing space before function parentheses.",
154
- fix(fixer) {
155
- return fixer.insertTextAfter(leftToken, " ");
156
- }
157
- });
158
- }
119
+ const hasSpacing = sourceCode.isSpaceBetweenTokens(leftToken, rightToken);
120
+
121
+ if (hasSpacing && functionConfig === "never") {
122
+ context.report({
123
+ node,
124
+ loc: leftToken.loc.end,
125
+ message: "Unexpected space before function parentheses.",
126
+ fix: fixer => fixer.removeRange([leftToken.range[1], rightToken.range[0]])
127
+ });
128
+ } else if (!hasSpacing && functionConfig === "always") {
129
+ context.report({
130
+ node,
131
+ loc: leftToken.loc.end,
132
+ message: "Missing space before function parentheses.",
133
+ fix: fixer => fixer.insertTextAfter(leftToken, " ")
134
+ });
159
135
  }
160
136
  }
161
137
 
162
138
  return {
163
- FunctionDeclaration: validateSpacingBeforeParentheses,
164
- FunctionExpression: validateSpacingBeforeParentheses,
165
- ArrowFunctionExpression: validateSpacingBeforeParentheses
139
+ ArrowFunctionExpression: checkFunction,
140
+ FunctionDeclaration: checkFunction,
141
+ FunctionExpression: checkFunction
166
142
  };
167
143
  }
168
144
  };
@@ -128,7 +128,7 @@ module.exports = {
128
128
  }
129
129
 
130
130
  if (ALWAYS) {
131
- if (right.type === "Punctuator" && right.value === ")") {
131
+ if (astUtils.isClosingParenToken(right)) {
132
132
  return false;
133
133
  }
134
134
  return !isOpenerException(right);
@@ -144,7 +144,7 @@ module.exports = {
144
144
  * @returns {boolean} True if the paren should have a space
145
145
  */
146
146
  function shouldCloserHaveSpace(left, right) {
147
- if (left.type === "Punctuator" && left.value === "(") {
147
+ if (astUtils.isOpeningParenToken(left)) {
148
148
  return false;
149
149
  }
150
150
 
@@ -192,7 +192,7 @@ module.exports = {
192
192
  * @returns {boolean} True if the paren should reject the space
193
193
  */
194
194
  function shouldCloserRejectSpace(left, right) {
195
- if (left.type === "Punctuator" && left.value === "(") {
195
+ if (astUtils.isOpeningParenToken(left)) {
196
196
  return false;
197
197
  }
198
198
 
@@ -224,11 +224,7 @@ module.exports = {
224
224
  const prevToken = tokens[i - 1];
225
225
  const nextToken = tokens[i + 1];
226
226
 
227
- if (token.type !== "Punctuator") {
228
- return;
229
- }
230
-
231
- if (token.value !== "(" && token.value !== ")") {
227
+ if (!astUtils.isOpeningParenToken(token) && !astUtils.isClosingParenToken(token)) {
232
228
  return;
233
229
  }
234
230
 
@@ -86,7 +86,7 @@ function resolveFileGlobPatterns(patterns, options) {
86
86
 
87
87
  const processPathExtensions = processPath(options);
88
88
 
89
- return patterns.map(processPathExtensions);
89
+ return patterns.filter(p => p.length).map(processPathExtensions);
90
90
  }
91
91
 
92
92
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "eslint",
3
- "version": "3.18.0",
3
+ "version": "3.19.0",
4
4
  "author": "Nicholas C. Zakas <nicholas+npm@nczconsulting.com>",
5
5
  "description": "An AST-based pattern checker for JavaScript.",
6
6
  "bin": {
@@ -71,42 +71,42 @@
71
71
  "user-home": "^2.0.0"
72
72
  },
73
73
  "devDependencies": {
74
- "babel-polyfill": "^6.9.1",
75
- "babel-preset-es2015": "^6.9.0",
74
+ "babel-polyfill": "^6.23.0",
75
+ "babel-preset-es2015": "^6.24.0",
76
76
  "babelify": "^7.3.0",
77
- "beefy": "^2.0.0",
78
- "brfs": "0.0.9",
79
- "browserify": "^12.0.1",
77
+ "beefy": "^2.1.8",
78
+ "brfs": "1.4.3",
79
+ "browserify": "^14.1.0",
80
80
  "chai": "^3.5.0",
81
- "cheerio": "^0.19.0",
82
- "coveralls": "^2.11.16",
83
- "dateformat": "^1.0.8",
84
- "ejs": "^2.3.3",
81
+ "cheerio": "^0.22.0",
82
+ "coveralls": "^2.12.0",
83
+ "dateformat": "^2.0.0",
84
+ "ejs": "^2.5.6",
85
85
  "eslint-plugin-eslint-plugin": "^0.7.1",
86
- "eslint-plugin-node": "^4.1.0",
87
- "eslint-release": "^0.10.0",
88
- "esprima": "^2.4.1",
86
+ "eslint-plugin-node": "^4.2.1",
87
+ "eslint-release": "^0.10.1",
88
+ "esprima": "^3.1.3",
89
89
  "esprima-fb": "^15001.1001.0-dev-harmony-fb",
90
- "istanbul": "^0.4.0",
91
- "jsdoc": "^3.3.0-beta1",
92
- "karma": "^0.13.22",
90
+ "istanbul": "^0.4.5",
91
+ "jsdoc": "^3.4.3",
92
+ "karma": "^1.5.0",
93
93
  "karma-babel-preprocessor": "^6.0.1",
94
- "karma-mocha": "^1.0.1",
95
- "karma-mocha-reporter": "^2.0.3",
96
- "karma-phantomjs-launcher": "^1.0.0",
97
- "leche": "^2.1.1",
94
+ "karma-mocha": "^1.3.0",
95
+ "karma-mocha-reporter": "^2.2.2",
96
+ "karma-phantomjs-launcher": "^1.0.4",
97
+ "leche": "^2.1.2",
98
98
  "load-perf": "^0.2.0",
99
- "markdownlint": "^0.3.1",
100
- "mocha": "^2.4.5",
99
+ "markdownlint": "^0.4.0",
100
+ "mocha": "^3.2.0",
101
101
  "mock-fs": "^4.2.0",
102
- "npm-license": "^0.3.2",
103
- "phantomjs-prebuilt": "^2.1.7",
104
- "proxyquire": "^1.7.10",
105
- "semver": "^5.0.3",
106
- "shelljs-nodecli": "~0.1.0",
107
- "sinon": "^1.17.2",
102
+ "npm-license": "^0.3.3",
103
+ "phantomjs-prebuilt": "^2.1.14",
104
+ "proxyquire": "^1.7.11",
105
+ "semver": "^5.3.0",
106
+ "shelljs-nodecli": "~0.1.1",
107
+ "sinon": "^2.0.0",
108
108
  "temp": "^0.8.3",
109
- "through": "^2.3.6"
109
+ "through": "^2.3.8"
110
110
  },
111
111
  "keywords": [
112
112
  "ast",