eslint 1.4.1 → 1.5.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.
Files changed (38) hide show
  1. package/README.md +1 -1
  2. package/bin/eslint.js +32 -3
  3. package/lib/ast-utils.js +17 -11
  4. package/lib/cli-engine.js +72 -11
  5. package/lib/config.js +54 -55
  6. package/lib/eslint.js +7 -56
  7. package/lib/options.js +7 -0
  8. package/lib/rules/array-bracket-spacing.js +6 -5
  9. package/lib/rules/block-spacing.js +4 -3
  10. package/lib/rules/comma-dangle.js +25 -10
  11. package/lib/rules/comma-spacing.js +4 -29
  12. package/lib/rules/computed-property-spacing.js +5 -4
  13. package/lib/rules/eol-last.js +8 -1
  14. package/lib/rules/func-style.js +29 -9
  15. package/lib/rules/id-length.js +3 -3
  16. package/lib/rules/indent.js +100 -47
  17. package/lib/rules/jsx-quotes.js +1 -1
  18. package/lib/rules/key-spacing.js +7 -1
  19. package/lib/rules/no-dupe-args.js +30 -46
  20. package/lib/rules/no-extra-semi.js +7 -1
  21. package/lib/rules/no-inline-comments.js +3 -1
  22. package/lib/rules/no-spaced-func.js +18 -5
  23. package/lib/rules/no-trailing-spaces.js +34 -6
  24. package/lib/rules/no-unused-vars.js +4 -4
  25. package/lib/rules/no-warning-comments.js +7 -0
  26. package/lib/rules/object-curly-spacing.js +7 -9
  27. package/lib/rules/semi-spacing.js +29 -4
  28. package/lib/rules/space-after-keywords.js +27 -5
  29. package/lib/rules/space-before-blocks.js +64 -7
  30. package/lib/rules/space-before-function-paren.js +19 -13
  31. package/lib/rules/space-before-keywords.js +45 -17
  32. package/lib/rules/space-infix-ops.js +22 -1
  33. package/lib/rules/space-return-throw-case.js +7 -1
  34. package/lib/testers/event-generator-tester.js +63 -0
  35. package/lib/util/comment-event-generator.js +116 -0
  36. package/lib/util/node-event-generator.js +55 -0
  37. package/lib/util/source-code.js +14 -7
  38. package/package.json +2 -2
@@ -0,0 +1,116 @@
1
+ /**
2
+ * @fileoverview The event generator for comments.
3
+ * @author Toru Nagashima
4
+ * @copyright 2015 Toru Nagashima. All rights reserved.
5
+ * See LICENSE file in root directory for full license.
6
+ */
7
+
8
+ "use strict";
9
+
10
+ //------------------------------------------------------------------------------
11
+ // Helpers
12
+ //------------------------------------------------------------------------------
13
+
14
+ /**
15
+ * Check collection of comments to prevent double event for comment as
16
+ * leading and trailing, then emit event if passing
17
+ * @param {ASTNode[]} comments - Collection of comment nodes
18
+ * @param {EventEmitter} emitter - The event emitter which is the destination of events.
19
+ * @param {Object[]} locs - List of locations of previous comment nodes
20
+ * @param {string} eventName - Event name postfix
21
+ * @returns {void}
22
+ */
23
+ function emitComments(comments, emitter, locs, eventName) {
24
+ if (comments.length > 0) {
25
+ comments.forEach(function(node) {
26
+ var index = locs.indexOf(node.loc);
27
+ if (index >= 0) {
28
+ locs.splice(index, 1);
29
+ } else {
30
+ locs.push(node.loc);
31
+ emitter.emit(node.type + eventName, node);
32
+ }
33
+ });
34
+ }
35
+ }
36
+
37
+ /**
38
+ * Shortcut to check and emit enter of comment nodes
39
+ * @param {CommentEventGenerator} generator - A generator to emit.
40
+ * @param {ASTNode[]} comments - Collection of comment nodes
41
+ * @returns {void}
42
+ */
43
+ function emitCommentsEnter(generator, comments) {
44
+ emitComments(
45
+ comments,
46
+ generator.emitter,
47
+ generator.commentLocsEnter,
48
+ "Comment");
49
+ }
50
+
51
+ /**
52
+ * Shortcut to check and emit exit of comment nodes
53
+ * @param {CommentEventGenerator} generator - A generator to emit.
54
+ * @param {ASTNode[]} comments Collection of comment nodes
55
+ * @returns {void}
56
+ */
57
+ function emitCommentsExit(generator, comments) {
58
+ emitComments(
59
+ comments,
60
+ generator.emitter,
61
+ generator.commentLocsExit,
62
+ "Comment:exit");
63
+ }
64
+
65
+ //------------------------------------------------------------------------------
66
+ // Public Interface
67
+ //------------------------------------------------------------------------------
68
+
69
+ /**
70
+ * The event generator for comments.
71
+ * This is the decorator pattern.
72
+ * This generates events of comments before/after events which are generated the original generator.
73
+ *
74
+ * @param {EventGenerator} originalEventGenerator - An event generator which is the decoration target.
75
+ * @param {SourceCode} sourceCode - A source code which has comments.
76
+ * @returns {CommentEventGenerator} new instance.
77
+ */
78
+ function CommentEventGenerator(originalEventGenerator, sourceCode) {
79
+ this.original = originalEventGenerator;
80
+ this.emitter = originalEventGenerator.emitter;
81
+ this.sourceCode = sourceCode;
82
+ this.commentLocsEnter = [];
83
+ this.commentLocsExit = [];
84
+ }
85
+
86
+ CommentEventGenerator.prototype = {
87
+ constructor: CommentEventGenerator,
88
+
89
+ /**
90
+ * Emits an event of entering comments.
91
+ * @param {ASTNode} node - A node which was entered.
92
+ * @returns {void}
93
+ */
94
+ enterNode: function enterNode(node) {
95
+ var comments = this.sourceCode.getComments(node);
96
+
97
+ emitCommentsEnter(this, comments.leading);
98
+ this.original.enterNode(node);
99
+ emitCommentsEnter(this, comments.trailing);
100
+ },
101
+
102
+ /**
103
+ * Emits an event of leaving comments.
104
+ * @param {ASTNode} node - A node which was left.
105
+ * @returns {void}
106
+ */
107
+ leaveNode: function leaveNode(node) {
108
+ var comments = this.sourceCode.getComments(node);
109
+
110
+ emitCommentsExit(this, comments.trailing);
111
+ this.original.leaveNode(node);
112
+ emitCommentsExit(this, comments.leading);
113
+ }
114
+ };
115
+
116
+ module.exports = CommentEventGenerator;
@@ -0,0 +1,55 @@
1
+ /**
2
+ * @fileoverview The event generator for AST nodes.
3
+ * @author Toru Nagashima
4
+ * @copyright 2015 Toru Nagashima. All rights reserved.
5
+ * See LICENSE file in root directory for full license.
6
+ */
7
+
8
+ "use strict";
9
+
10
+ //------------------------------------------------------------------------------
11
+ // Public Interface
12
+ //------------------------------------------------------------------------------
13
+
14
+ /**
15
+ * The event generator for AST nodes.
16
+ * This implements below interface.
17
+ *
18
+ * ```ts
19
+ * interface EventGenerator {
20
+ * emitter: EventEmitter;
21
+ * enterNode(node: ASTNode): void;
22
+ * leaveNode(node: ASTNode): void;
23
+ * }
24
+ * ```
25
+ *
26
+ * @param {EventEmitter} emitter - An event emitter which is the destination of events.
27
+ * @returns {NodeEventGenerator} new instance.
28
+ */
29
+ function NodeEventGenerator(emitter) {
30
+ this.emitter = emitter;
31
+ }
32
+
33
+ NodeEventGenerator.prototype = {
34
+ constructor: NodeEventGenerator,
35
+
36
+ /**
37
+ * Emits an event of entering AST node.
38
+ * @param {ASTNode} node - A node which was entered.
39
+ * @returns {void}
40
+ */
41
+ enterNode: function enterNode(node) {
42
+ this.emitter.emit(node.type, node);
43
+ },
44
+
45
+ /**
46
+ * Emits an event of leaving AST node.
47
+ * @param {ASTNode} node - A node which was left.
48
+ * @returns {void}
49
+ */
50
+ leaveNode: function leaveNode(node) {
51
+ this.emitter.emit(node.type + ":exit", node);
52
+ }
53
+ };
54
+
55
+ module.exports = NodeEventGenerator;
@@ -115,12 +115,6 @@ function SourceCode(text, ast) {
115
115
  */
116
116
  this.lines = text.split(/\r\n|\r|\n|\u2028|\u2029/g);
117
117
 
118
- /**
119
- * Fixes to be made later on.
120
- * @type Object[]
121
- */
122
- this._fixes = [];
123
-
124
118
  // create token store methods
125
119
  var tokenStore = createTokenStore(ast.tokens);
126
120
  Object.keys(tokenStore).forEach(function(methodName) {
@@ -259,8 +253,21 @@ SourceCode.prototype = {
259
253
  });
260
254
 
261
255
  return result;
262
- }
256
+ },
263
257
 
258
+ /**
259
+ * Determines if two tokens have at least one whitespace character
260
+ * between them. This completely disregards comments in making the
261
+ * determination, so comments count as zero-length substrings.
262
+ * @param {Token} first The token to check after.
263
+ * @param {Token} second The token to check before.
264
+ * @returns {boolean} True if there is only space between tokens, false
265
+ * if there is anything other than whitespace between tokens.
266
+ */
267
+ isSpaceBetweenTokens: function(first, second) {
268
+ var text = this.text.slice(first.range[1], second.range[0]);
269
+ return /\s/.test(text.replace(/\/\*.*?\*\//g, ""));
270
+ }
264
271
  };
265
272
 
266
273
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "eslint",
3
- "version": "1.4.1",
3
+ "version": "1.5.1",
4
4
  "author": "Nicholas C. Zakas <nicholas+npm@nczconsulting.com>",
5
5
  "description": "An AST-based pattern checker for JavaScript.",
6
6
  "bin": {
@@ -38,7 +38,7 @@
38
38
  "chalk": "^1.0.0",
39
39
  "concat-stream": "^1.4.6",
40
40
  "debug": "^2.1.1",
41
- "doctrine": "^0.6.2",
41
+ "doctrine": "^0.7.0",
42
42
  "escape-string-regexp": "^1.0.2",
43
43
  "escope": "^3.2.0",
44
44
  "espree": "^2.2.4",