eslint 0.24.0 → 0.24.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/lib/eslint.js CHANGED
@@ -240,7 +240,7 @@ function enableReporting(reportingConfig, start, rulesToEnable) {
240
240
  * @param {Object} config The existing configuration data.
241
241
  * @param {Object[]} reportingConfig The existing reporting configuration data.
242
242
  * @param {Object[]} messages The messages queue.
243
- * @returns {void}
243
+ * @returns {object} Modified config object
244
244
  */
245
245
  function modifyConfigsFromComments(filename, ast, config, reportingConfig, messages) {
246
246
 
@@ -302,12 +302,12 @@ function modifyConfigsFromComments(filename, ast, config, reportingConfig, messa
302
302
  // apply environment configs
303
303
  Object.keys(commentConfig.env).forEach(function (name) {
304
304
  if (environments[name]) {
305
- util.mergeConfigs(commentConfig, environments[name]);
305
+ commentConfig = util.mergeConfigs(commentConfig, environments[name]);
306
306
  }
307
307
  });
308
308
  assign(commentConfig.rules, commentRules);
309
309
 
310
- util.mergeConfigs(config, commentConfig);
310
+ return util.mergeConfigs(config, commentConfig);
311
311
  }
312
312
 
313
313
  /**
@@ -611,7 +611,7 @@ module.exports = (function() {
611
611
  currentAST = ast;
612
612
 
613
613
  // parse global comments and modify config
614
- modifyConfigsFromComments(filename, ast, config, reportingConfig, messages);
614
+ config = modifyConfigsFromComments(filename, ast, config, reportingConfig, messages);
615
615
 
616
616
  // enable appropriate rules
617
617
  Object.keys(config.rules).filter(function(key) {
@@ -908,7 +908,7 @@ module.exports = (function() {
908
908
  case "ArrowFunctionExpression":
909
909
  case "FunctionExpression":
910
910
 
911
- if (parent.type !== "CallExpression" || parent.callee !== node) {
911
+ if (parent.type !== "CallExpression") {
912
912
  while (parent && !parent.leadingComments && !/Function/.test(parent.type)) {
913
913
  parent = parent.parent;
914
914
  }
@@ -1,6 +1,7 @@
1
1
  /**
2
2
  * @fileoverview Rule to check for "block scoped" variables by binding context
3
3
  * @author Matt DuVall <http://www.mattduvall.com>
4
+ * @copyright 2015 Mathieu M-Gosselin. All rights reserved.
4
5
  */
5
6
  "use strict";
6
7
 
@@ -101,6 +102,22 @@ module.exports = function(context) {
101
102
  }
102
103
  }
103
104
 
105
+ /**
106
+ * Declares all relevant identifiers for module exports.
107
+ * @param {ASTNode} node The AST node representing an export.
108
+ * @returns {void}
109
+ * @private
110
+ */
111
+ function declareExports(node) {
112
+ if (node.exported && node.exported.name) {
113
+ declare([node.exported.name]);
114
+
115
+ if (node.local) {
116
+ declare([node.local.name]);
117
+ }
118
+ }
119
+ }
120
+
104
121
  /**
105
122
  * Declares all relevant identifiers for classes.
106
123
  * @param {ASTNode} node The AST node representing a class.
@@ -241,6 +258,8 @@ module.exports = function(context) {
241
258
  "ImportDefaultSpecifier": declareImports,
242
259
  "ImportNamespaceSpecifier": declareImports,
243
260
 
261
+ "ExportSpecifier": declareExports,
262
+
244
263
  "BlockStatement": function(node) {
245
264
  var statements = node.body;
246
265
  pushScope();
@@ -54,7 +54,9 @@ module.exports = function (context) {
54
54
 
55
55
  return {
56
56
  "ObjectExpression": checkForTrailingComma,
57
- "ArrayExpression": checkForTrailingComma
57
+ "ObjectPattern": checkForTrailingComma,
58
+ "ArrayExpression": checkForTrailingComma,
59
+ "ArrayPattern": checkForTrailingComma
58
60
  };
59
61
  };
60
62
 
@@ -1,7 +1,9 @@
1
1
  /**
2
2
  * @fileoverview Enforces empty lines around comments.
3
3
  * @author Jamund Ferguson
4
+ * @copyright 2015 Mathieu M-Gosselin. All rights reserved.
4
5
  * @copyright 2015 Jamund Ferguson. All rights reserved.
6
+ * @copyright 2015 Gyandeep Singh. All rights reserved.
5
7
  */
6
8
  "use strict";
7
9
 
@@ -97,7 +99,8 @@ module.exports = function(context) {
97
99
  if (ancestors.length) {
98
100
  parent = ancestors.pop();
99
101
  }
100
- return parent && (parent.type === "BlockStatement" || parent.body.type === "BlockStatement") &&
102
+
103
+ return parent && (parent.type === "ClassBody" || parent.type === "BlockStatement" || (parent.body && parent.body.type === "BlockStatement")) &&
101
104
  node.loc.start.line - parent.loc.start.line === 1;
102
105
  }
103
106
 
@@ -113,7 +116,8 @@ module.exports = function(context) {
113
116
  if (ancestors.length) {
114
117
  parent = ancestors.pop();
115
118
  }
116
- return parent && (parent.type === "BlockStatement" || parent.body.type === "BlockStatement") &&
119
+
120
+ return parent && (parent.type === "ClassBody" || parent.type === "BlockStatement" || (parent.body && parent.body.type === "BlockStatement")) &&
117
121
  parent.loc.end.line - node.loc.end.line === 1;
118
122
  }
119
123
 
@@ -48,7 +48,7 @@ module.exports = function(context) {
48
48
  // Iterate
49
49
  lines.forEach(function(line, i) {
50
50
  if (line.replace(/\t/g, tabString).length > maxLength) {
51
- context.report(node, { line: i + 1, col: 1 }, "Line " + (i + 1) + " exceeds the maximum line length of " + maxLength + ".");
51
+ context.report(node, { line: i + 1, column: 0 }, "Line " + (i + 1) + " exceeds the maximum line length of " + maxLength + ".");
52
52
  }
53
53
  });
54
54
  }
@@ -12,7 +12,7 @@
12
12
  //------------------------------------------------------------------------------
13
13
 
14
14
  module.exports = function(context) {
15
- var IMPLIED_EVAL = /set(?:Timeout|Interval)/;
15
+ var IMPLIED_EVAL = /set(?:Timeout|Interval)|execScript/;
16
16
 
17
17
  //--------------------------------------------------------------------------
18
18
  // Helpers
@@ -44,7 +44,7 @@ module.exports = function(context) {
44
44
  findVariablesInScope(scope);
45
45
 
46
46
  // globalReturn means one extra scope to check
47
- if (node.type === "Program" && context.ecmaFeatures.globalReturn) {
47
+ if (node.type === "Program" && (context.ecmaFeatures.globalReturn || context.ecmaFeatures.modules)) {
48
48
  findVariablesInScope(scope.childScopes[0]);
49
49
  }
50
50
  }
@@ -44,7 +44,8 @@ module.exports = function(context) {
44
44
  return;
45
45
  }
46
46
 
47
- if (node.kind === "get" || node.kind === "set") {
47
+ // getters, setters and computed properties are ignored
48
+ if (node.kind === "get" || node.kind === "set" || node.computed) {
48
49
  return;
49
50
  }
50
51
 
package/lib/rules/yoda.js CHANGED
@@ -197,6 +197,7 @@ module.exports = function (context) {
197
197
  // Comparisons must always be yoda-style: if ("blue" === color)
198
198
  if (
199
199
  (node.right.type === "Literal" || looksLikeLiteral(node.right)) &&
200
+ !(node.left.type === "Literal" || looksLikeLiteral(node.left)) &&
200
201
  !(!isEqualityOperator(node.operator) && onlyEquality) &&
201
202
  isComparisonOperator(node.operator) &&
202
203
  !(exceptRange && isRangeTest(context.getAncestors().pop()))
@@ -209,6 +210,7 @@ module.exports = function (context) {
209
210
  // Comparisons must never be yoda-style (default)
210
211
  if (
211
212
  (node.left.type === "Literal" || looksLikeLiteral(node.left)) &&
213
+ !(node.right.type === "Literal" || looksLikeLiteral(node.right)) &&
212
214
  !(!isEqualityOperator(node.operator) && onlyEquality) &&
213
215
  isComparisonOperator(node.operator) &&
214
216
  !(exceptRange && isRangeTest(context.getAncestors().pop()))
package/lib/util.js CHANGED
@@ -16,44 +16,84 @@ var PLUGIN_NAME_PREFIX = "eslint-plugin-",
16
16
 
17
17
  /**
18
18
  * Merges two config objects. This will not only add missing keys, but will also modify values to match.
19
- * @param {Object} base config object
20
- * @param {Object} custom config object. Overrides in this config object will take priority over base.
19
+ * @param {Object} target config object
20
+ * @param {Object} src config object. Overrides in this config object will take priority over base.
21
+ * @param {boolean} [combine] Whether to combine arrays or not
21
22
  * @returns {Object} merged config object.
22
23
  */
23
- exports.mergeConfigs = function mergeConfigs(base, custom) {
24
+ exports.mergeConfigs = function deepmerge(target, src, combine) {
25
+ /*
26
+ The MIT License (MIT)
24
27
 
25
- Object.keys(custom).forEach(function (key) {
26
- var property = custom[key];
28
+ Copyright (c) 2012 Nicholas Fisher
27
29
 
28
- if (key === "plugins") {
29
- if (!base[key]) {
30
- base[key] = [];
31
- }
30
+ Permission is hereby granted, free of charge, to any person obtaining a copy
31
+ of this software and associated documentation files (the "Software"), to deal
32
+ in the Software without restriction, including without limitation the rights
33
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
34
+ copies of the Software, and to permit persons to whom the Software is
35
+ furnished to do so, subject to the following conditions:
32
36
 
33
- property.forEach(function (plugin) {
34
- // skip duplicates
35
- if (base[key].indexOf(plugin) === -1) {
36
- base[key].push(plugin);
37
- }
38
- });
39
- return;
40
- }
37
+ The above copyright notice and this permission notice shall be included in
38
+ all copies or substantial portions of the Software.
41
39
 
42
- if (Array.isArray(base[key]) && !Array.isArray(property) && typeof property === "number") {
43
- // assume that we are just overriding first attribute
44
- base[key][0] = custom[key];
45
- return;
46
- }
40
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
41
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
42
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
43
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
44
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
45
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
46
+ THE SOFTWARE.
47
+ */
48
+ // This code is taken from deepmerge repo (https://github.com/KyleAMathews/deepmerge) and modified to meet our needs.
49
+ var array = Array.isArray(src) || Array.isArray(target);
50
+ var dst = array && [] || {};
47
51
 
48
- if (typeof property === "object" && !Array.isArray(property) && property !== null) {
49
- // base[key] might not exist, so be careful with recursion here
50
- base[key] = mergeConfigs(base[key] || {}, custom[key]);
51
- } else {
52
- base[key] = custom[key];
52
+ combine = !!combine;
53
+ if (array) {
54
+ target = target || [];
55
+ dst = dst.concat(target);
56
+ if (typeof src !== "object" && !Array.isArray(src)) {
57
+ src = [src];
53
58
  }
54
- });
59
+ Object.keys(src).forEach(function(e, i) {
60
+ e = src[i];
61
+ if (typeof dst[i] === "undefined") {
62
+ dst[i] = e;
63
+ } else if (typeof e === "object") {
64
+ dst[i] = deepmerge(target[i], e);
65
+ } else {
66
+ if (!combine) {
67
+ dst[i] = e;
68
+ } else {
69
+ if (dst.indexOf(e) === -1) {
70
+ dst.push(e);
71
+ }
72
+ }
73
+ }
74
+ });
75
+ } else {
76
+ if (target && typeof target === "object") {
77
+ Object.keys(target).forEach(function (key) {
78
+ dst[key] = target[key];
79
+ });
80
+ }
81
+ Object.keys(src).forEach(function (key) {
82
+ if (Array.isArray(src[key]) || Array.isArray(target[key])) {
83
+ dst[key] = deepmerge(target[key], src[key], key === "plugins");
84
+ } else if (typeof src[key] !== "object" || !src[key]) {
85
+ dst[key] = src[key];
86
+ } else {
87
+ if (!target[key]) {
88
+ dst[key] = src[key];
89
+ } else {
90
+ dst[key] = deepmerge(target[key], src[key]);
91
+ }
92
+ }
93
+ });
94
+ }
55
95
 
56
- return base;
96
+ return dst;
57
97
  };
58
98
 
59
99
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "eslint",
3
- "version": "0.24.0",
3
+ "version": "0.24.1",
4
4
  "author": "Nicholas C. Zakas <nicholas+npm@nczconsulting.com>",
5
5
  "description": "An AST-based pattern checker for JavaScript.",
6
6
  "bin": {