eslint 3.13.1 → 3.16.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.
- package/CHANGELOG.md +81 -0
- package/README.md +1 -1
- package/conf/{eslint.json → eslint-recommended.js} +88 -71
- package/lib/ast-utils.js +247 -28
- package/lib/cli.js +2 -2
- package/lib/code-path-analysis/code-path-state.js +2 -2
- package/lib/config/autoconfig.js +24 -20
- package/lib/config/config-file.js +31 -24
- package/lib/config/config-initializer.js +2 -2
- package/lib/config/config-rule.js +15 -16
- package/lib/config/config-validator.js +6 -6
- package/lib/config.js +3 -2
- package/lib/eslint.js +18 -18
- package/lib/formatters/checkstyle.js +2 -2
- package/lib/formatters/codeframe.js +1 -1
- package/lib/formatters/compact.js +2 -2
- package/lib/formatters/junit.js +2 -2
- package/lib/formatters/tap.js +2 -2
- package/lib/formatters/unix.js +2 -2
- package/lib/formatters/visualstudio.js +2 -2
- package/lib/internal-rules/internal-consistent-docs-description.js +1 -1
- package/lib/rule-context.js +2 -2
- package/lib/rules/arrow-body-style.js +7 -4
- package/lib/rules/arrow-spacing.js +7 -6
- package/lib/rules/block-spacing.js +2 -2
- package/lib/rules/brace-style.js +93 -202
- package/lib/rules/capitalized-comments.js +6 -6
- package/lib/rules/comma-dangle.js +6 -6
- package/lib/rules/comma-spacing.js +16 -16
- package/lib/rules/comma-style.js +1 -1
- package/lib/rules/consistent-return.js +1 -1
- package/lib/rules/constructor-super.js +3 -3
- package/lib/rules/curly.js +11 -7
- package/lib/rules/default-case.js +3 -3
- package/lib/rules/eqeqeq.js +15 -6
- package/lib/rules/func-call-spacing.js +12 -15
- package/lib/rules/func-name-matching.js +1 -1
- package/lib/rules/generator-star-spacing.js +18 -19
- package/lib/rules/global-require.js +2 -2
- package/lib/rules/id-blacklist.js +2 -2
- package/lib/rules/id-length.js +3 -3
- package/lib/rules/id-match.js +2 -2
- package/lib/rules/indent.js +21 -20
- package/lib/rules/key-spacing.js +20 -23
- package/lib/rules/keyword-spacing.js +2 -13
- package/lib/rules/line-comment-position.js +1 -1
- package/lib/rules/linebreak-style.js +7 -1
- package/lib/rules/lines-around-comment.js +4 -4
- package/lib/rules/lines-around-directive.js +4 -4
- package/lib/rules/max-lines.js +3 -3
- package/lib/rules/max-statements-per-line.js +8 -7
- package/lib/rules/new-cap.js +2 -2
- package/lib/rules/newline-after-var.js +7 -2
- package/lib/rules/newline-before-return.js +2 -2
- package/lib/rules/newline-per-chained-call.js +3 -1
- package/lib/rules/no-await-in-loop.js +5 -5
- package/lib/rules/no-cond-assign.js +3 -3
- package/lib/rules/no-dupe-keys.js +1 -1
- package/lib/rules/no-else-return.js +88 -25
- package/lib/rules/no-extend-native.js +3 -3
- package/lib/rules/no-extra-bind.js +3 -4
- package/lib/rules/no-extra-boolean-cast.js +22 -1
- package/lib/rules/no-extra-parens.js +57 -9
- package/lib/rules/no-inner-declarations.js +4 -4
- package/lib/rules/no-irregular-whitespace.js +7 -1
- package/lib/rules/no-lone-blocks.js +10 -10
- package/lib/rules/no-mixed-operators.js +1 -7
- package/lib/rules/no-mixed-requires.js +4 -4
- package/lib/rules/no-multi-assign.js +41 -0
- package/lib/rules/no-multi-spaces.js +4 -1
- package/lib/rules/no-multi-str.js +7 -3
- package/lib/rules/no-redeclare.js +7 -7
- package/lib/rules/no-return-assign.js +7 -14
- package/lib/rules/no-return-await.js +2 -2
- package/lib/rules/no-sequences.js +7 -6
- package/lib/rules/no-throw-literal.js +2 -39
- package/lib/rules/no-trailing-spaces.js +8 -2
- package/lib/rules/no-undefined.js +45 -6
- package/lib/rules/no-unexpected-multiline.js +9 -8
- package/lib/rules/no-unneeded-ternary.js +5 -1
- package/lib/rules/no-unused-labels.js +17 -2
- package/lib/rules/no-unused-vars.js +34 -19
- package/lib/rules/no-use-before-define.js +33 -29
- package/lib/rules/no-useless-computed-key.js +9 -4
- package/lib/rules/no-useless-concat.js +10 -7
- package/lib/rules/no-useless-escape.js +1 -1
- package/lib/rules/no-useless-return.js +5 -11
- package/lib/rules/no-var.js +69 -3
- package/lib/rules/no-whitespace-before-property.js +5 -16
- package/lib/rules/object-curly-newline.js +2 -2
- package/lib/rules/object-curly-spacing.js +7 -25
- package/lib/rules/object-property-newline.js +3 -3
- package/lib/rules/object-shorthand.js +10 -10
- package/lib/rules/operator-assignment.js +2 -2
- package/lib/rules/operator-linebreak.js +8 -10
- package/lib/rules/padded-blocks.js +4 -4
- package/lib/rules/prefer-promise-reject-errors.js +124 -0
- package/lib/rules/prefer-spread.js +1 -1
- package/lib/rules/prefer-template.js +1 -1
- package/lib/rules/quotes.js +11 -7
- package/lib/rules/require-await.js +1 -1
- package/lib/rules/semi-spacing.js +4 -0
- package/lib/rules/sort-imports.js +4 -4
- package/lib/rules/sort-keys.js +2 -2
- package/lib/rules/sort-vars.js +2 -2
- package/lib/rules/space-before-function-paren.js +9 -6
- package/lib/rules/space-in-parens.js +8 -8
- package/lib/rules/spaced-comment.js +10 -10
- package/lib/rules/strict.js +2 -2
- package/lib/rules/template-tag-spacing.js +77 -0
- package/lib/rules/unicode-bom.js +1 -1
- package/lib/rules/wrap-iife.js +5 -5
- package/lib/rules/yoda.js +2 -7
- package/lib/rules.js +2 -2
- package/lib/testers/rule-tester.js +28 -21
- package/lib/token-store/backward-token-comment-cursor.js +57 -0
- package/lib/token-store/backward-token-cursor.js +56 -0
- package/lib/token-store/cursor.js +76 -0
- package/lib/token-store/cursors.js +92 -0
- package/lib/token-store/decorative-cursor.js +39 -0
- package/lib/token-store/filter-cursor.js +43 -0
- package/lib/token-store/forward-token-comment-cursor.js +57 -0
- package/lib/token-store/forward-token-cursor.js +61 -0
- package/lib/token-store/index.js +604 -0
- package/lib/token-store/limit-cursor.js +40 -0
- package/lib/token-store/padded-token-cursor.js +38 -0
- package/lib/token-store/skip-cursor.js +42 -0
- package/lib/token-store/utils.js +100 -0
- package/lib/util/comment-event-generator.js +17 -16
- package/lib/util/glob-util.js +1 -1
- package/lib/util/glob.js +1 -1
- package/lib/util/rule-fixer.js +3 -8
- package/lib/util/source-code-fixer.js +41 -45
- package/lib/util/source-code.js +35 -19
- package/messages/extend-config-missing.txt +3 -0
- package/package.json +3 -3
- package/lib/token-store.js +0 -203
@@ -0,0 +1,42 @@
|
|
1
|
+
/**
|
2
|
+
* @fileoverview Define the cursor which ignores the first few tokens.
|
3
|
+
* @author Toru Nagashima
|
4
|
+
*/
|
5
|
+
"use strict";
|
6
|
+
|
7
|
+
//------------------------------------------------------------------------------
|
8
|
+
// Requirements
|
9
|
+
//------------------------------------------------------------------------------
|
10
|
+
|
11
|
+
const DecorativeCursor = require("./decorative-cursor");
|
12
|
+
|
13
|
+
//------------------------------------------------------------------------------
|
14
|
+
// Exports
|
15
|
+
//------------------------------------------------------------------------------
|
16
|
+
|
17
|
+
/**
|
18
|
+
* The decorative cursor which ignores the first few tokens.
|
19
|
+
*/
|
20
|
+
module.exports = class SkipCursor extends DecorativeCursor {
|
21
|
+
|
22
|
+
/**
|
23
|
+
* Initializes this cursor.
|
24
|
+
* @param {Cursor} cursor - The cursor to be decorated.
|
25
|
+
* @param {number} count - The count of tokens this cursor skips.
|
26
|
+
*/
|
27
|
+
constructor(cursor, count) {
|
28
|
+
super(cursor);
|
29
|
+
this.count = count;
|
30
|
+
}
|
31
|
+
|
32
|
+
/** @inheritdoc */
|
33
|
+
moveNext() {
|
34
|
+
while (this.count > 0) {
|
35
|
+
this.count -= 1;
|
36
|
+
if (!super.moveNext()) {
|
37
|
+
return false;
|
38
|
+
}
|
39
|
+
}
|
40
|
+
return super.moveNext();
|
41
|
+
}
|
42
|
+
};
|
@@ -0,0 +1,100 @@
|
|
1
|
+
/**
|
2
|
+
* @fileoverview Define utilify functions for token store.
|
3
|
+
* @author Toru Nagashima
|
4
|
+
*/
|
5
|
+
"use strict";
|
6
|
+
|
7
|
+
//------------------------------------------------------------------------------
|
8
|
+
// Requirements
|
9
|
+
//------------------------------------------------------------------------------
|
10
|
+
|
11
|
+
const lodash = require("lodash");
|
12
|
+
|
13
|
+
//------------------------------------------------------------------------------
|
14
|
+
// Helpers
|
15
|
+
//------------------------------------------------------------------------------
|
16
|
+
|
17
|
+
/**
|
18
|
+
* Gets `token.range[0]` from the given token.
|
19
|
+
*
|
20
|
+
* @param {Node|Token|Comment} token - The token to get.
|
21
|
+
* @returns {number} The start location.
|
22
|
+
* @private
|
23
|
+
*/
|
24
|
+
function getStartLocation(token) {
|
25
|
+
return token.range[0];
|
26
|
+
}
|
27
|
+
|
28
|
+
//------------------------------------------------------------------------------
|
29
|
+
// Exports
|
30
|
+
//------------------------------------------------------------------------------
|
31
|
+
|
32
|
+
/**
|
33
|
+
* Binary-searches the index of the first token which is after the given location.
|
34
|
+
* If it was not found, this returns `tokens.length`.
|
35
|
+
*
|
36
|
+
* @param {(Token|Comment)[]} tokens - It searches the token in this list.
|
37
|
+
* @param {number} location - The location to search.
|
38
|
+
* @returns {number} The found index or `tokens.length`.
|
39
|
+
*/
|
40
|
+
exports.search = function search(tokens, location) {
|
41
|
+
return lodash.sortedIndexBy(
|
42
|
+
tokens,
|
43
|
+
{ range: [location] },
|
44
|
+
getStartLocation
|
45
|
+
);
|
46
|
+
};
|
47
|
+
|
48
|
+
/**
|
49
|
+
* Gets the index of the `startLoc` in `tokens`.
|
50
|
+
* `startLoc` can be the value of `node.range[1]`, so this checks about `startLoc - 1` as well.
|
51
|
+
*
|
52
|
+
* @param {(Token|Comment)[]} tokens - The tokens to find an index.
|
53
|
+
* @param {Object} indexMap - The map from locations to indices.
|
54
|
+
* @param {number} startLoc - The location to get an index.
|
55
|
+
* @returns {number} The index.
|
56
|
+
*/
|
57
|
+
exports.getFirstIndex = function getFirstIndex(tokens, indexMap, startLoc) {
|
58
|
+
if (startLoc in indexMap) {
|
59
|
+
return indexMap[startLoc];
|
60
|
+
}
|
61
|
+
if ((startLoc - 1) in indexMap) {
|
62
|
+
const index = indexMap[startLoc - 1];
|
63
|
+
const token = (index >= 0 && index < tokens.length) ? tokens[index] : null;
|
64
|
+
|
65
|
+
// For the map of "comment's location -> token's index", it points the next token of a comment.
|
66
|
+
// In that case, +1 is unnecessary.
|
67
|
+
if (token && token.range[0] >= startLoc) {
|
68
|
+
return index;
|
69
|
+
}
|
70
|
+
return index + 1;
|
71
|
+
}
|
72
|
+
return 0;
|
73
|
+
};
|
74
|
+
|
75
|
+
/**
|
76
|
+
* Gets the index of the `endLoc` in `tokens`.
|
77
|
+
* The information of end locations are recorded at `endLoc - 1` in `indexMap`, so this checks about `endLoc - 1` as well.
|
78
|
+
*
|
79
|
+
* @param {(Token|Comment)[]} tokens - The tokens to find an index.
|
80
|
+
* @param {Object} indexMap - The map from locations to indices.
|
81
|
+
* @param {number} endLoc - The location to get an index.
|
82
|
+
* @returns {number} The index.
|
83
|
+
*/
|
84
|
+
exports.getLastIndex = function getLastIndex(tokens, indexMap, endLoc) {
|
85
|
+
if (endLoc in indexMap) {
|
86
|
+
return indexMap[endLoc] - 1;
|
87
|
+
}
|
88
|
+
if ((endLoc - 1) in indexMap) {
|
89
|
+
const index = indexMap[endLoc - 1];
|
90
|
+
const token = (index >= 0 && index < tokens.length) ? tokens[index] : null;
|
91
|
+
|
92
|
+
// For the map of "comment's location -> token's index", it points the next token of a comment.
|
93
|
+
// In that case, -1 is necessary.
|
94
|
+
if (token && token.range[1] > endLoc) {
|
95
|
+
return index - 1;
|
96
|
+
}
|
97
|
+
return index;
|
98
|
+
}
|
99
|
+
return tokens.length - 1;
|
100
|
+
};
|
@@ -70,46 +70,47 @@ function emitCommentsExit(generator, comments) {
|
|
70
70
|
* This is the decorator pattern.
|
71
71
|
* This generates events of comments before/after events which are generated the original generator.
|
72
72
|
*
|
73
|
-
*
|
74
|
-
* @param {SourceCode} sourceCode - A source code which has comments.
|
75
|
-
* @returns {CommentEventGenerator} new instance.
|
73
|
+
* Comment event generator class
|
76
74
|
*/
|
77
|
-
|
78
|
-
this.original = originalEventGenerator;
|
79
|
-
this.emitter = originalEventGenerator.emitter;
|
80
|
-
this.sourceCode = sourceCode;
|
81
|
-
this.commentLocsEnter = [];
|
82
|
-
this.commentLocsExit = [];
|
83
|
-
}
|
75
|
+
class CommentEventGenerator {
|
84
76
|
|
85
|
-
|
86
|
-
|
77
|
+
/**
|
78
|
+
* @param {EventGenerator} originalEventGenerator - An event generator which is the decoration target.
|
79
|
+
* @param {SourceCode} sourceCode - A source code which has comments.
|
80
|
+
*/
|
81
|
+
constructor(originalEventGenerator, sourceCode) {
|
82
|
+
this.original = originalEventGenerator;
|
83
|
+
this.emitter = originalEventGenerator.emitter;
|
84
|
+
this.sourceCode = sourceCode;
|
85
|
+
this.commentLocsEnter = [];
|
86
|
+
this.commentLocsExit = [];
|
87
|
+
}
|
87
88
|
|
88
89
|
/**
|
89
90
|
* Emits an event of entering comments.
|
90
91
|
* @param {ASTNode} node - A node which was entered.
|
91
92
|
* @returns {void}
|
92
93
|
*/
|
93
|
-
enterNode
|
94
|
+
enterNode(node) {
|
94
95
|
const comments = this.sourceCode.getComments(node);
|
95
96
|
|
96
97
|
emitCommentsEnter(this, comments.leading);
|
97
98
|
this.original.enterNode(node);
|
98
99
|
emitCommentsEnter(this, comments.trailing);
|
99
|
-
}
|
100
|
+
}
|
100
101
|
|
101
102
|
/**
|
102
103
|
* Emits an event of leaving comments.
|
103
104
|
* @param {ASTNode} node - A node which was left.
|
104
105
|
* @returns {void}
|
105
106
|
*/
|
106
|
-
leaveNode
|
107
|
+
leaveNode(node) {
|
107
108
|
const comments = this.sourceCode.getComments(node);
|
108
109
|
|
109
110
|
emitCommentsExit(this, comments.trailing);
|
110
111
|
this.original.leaveNode(node);
|
111
112
|
emitCommentsExit(this, comments.leading);
|
112
113
|
}
|
113
|
-
}
|
114
|
+
}
|
114
115
|
|
115
116
|
module.exports = CommentEventGenerator;
|
package/lib/util/glob-util.js
CHANGED
package/lib/util/glob.js
CHANGED
@@ -15,7 +15,7 @@ const Sync = require("glob").GlobSync,
|
|
15
15
|
// Private
|
16
16
|
//------------------------------------------------------------------------------
|
17
17
|
|
18
|
-
const IGNORE =
|
18
|
+
const IGNORE = Symbol("ignore");
|
19
19
|
|
20
20
|
/**
|
21
21
|
* Subclass of `glob.GlobSync`
|
package/lib/util/rule-fixer.js
CHANGED
@@ -34,14 +34,9 @@ function insertTextAt(index, text) {
|
|
34
34
|
|
35
35
|
/**
|
36
36
|
* Creates code fixing commands for rules.
|
37
|
-
* @constructor
|
38
37
|
*/
|
39
|
-
function RuleFixer() {
|
40
|
-
Object.freeze(this);
|
41
|
-
}
|
42
38
|
|
43
|
-
|
44
|
-
constructor: RuleFixer,
|
39
|
+
const ruleFixer = Object.freeze({
|
45
40
|
|
46
41
|
/**
|
47
42
|
* Creates a fix command that inserts text after the given node or token.
|
@@ -139,7 +134,7 @@ RuleFixer.prototype = {
|
|
139
134
|
};
|
140
135
|
}
|
141
136
|
|
142
|
-
};
|
137
|
+
});
|
143
138
|
|
144
139
|
|
145
|
-
module.exports =
|
140
|
+
module.exports = ruleFixer;
|
@@ -16,6 +16,17 @@ const debug = require("debug")("eslint:text-fixer");
|
|
16
16
|
|
17
17
|
const BOM = "\uFEFF";
|
18
18
|
|
19
|
+
/**
|
20
|
+
* Compares items in a messages array by range.
|
21
|
+
* @param {Message} a The first message.
|
22
|
+
* @param {Message} b The second message.
|
23
|
+
* @returns {int} -1 if a comes before b, 1 if a comes after b, 0 if equal.
|
24
|
+
* @private
|
25
|
+
*/
|
26
|
+
function compareMessagesByFixRange(a, b) {
|
27
|
+
return a.fix.range[0] - b.fix.range[0] || a.fix.range[1] - b.fix.range[1];
|
28
|
+
}
|
29
|
+
|
19
30
|
/**
|
20
31
|
* Compares items in a messages array by line and column.
|
21
32
|
* @param {Message} a The first message.
|
@@ -24,13 +35,7 @@ const BOM = "\uFEFF";
|
|
24
35
|
* @private
|
25
36
|
*/
|
26
37
|
function compareMessagesByLocation(a, b) {
|
27
|
-
|
28
|
-
|
29
|
-
if (lineDiff === 0) {
|
30
|
-
return a.column - b.column;
|
31
|
-
} else {
|
32
|
-
return lineDiff;
|
33
|
-
}
|
38
|
+
return a.line - b.line || a.column - b.column;
|
34
39
|
}
|
35
40
|
|
36
41
|
//------------------------------------------------------------------------------
|
@@ -68,9 +73,10 @@ SourceCodeFixer.applyFixes = function(sourceCode, messages) {
|
|
68
73
|
// clone the array
|
69
74
|
const remainingMessages = [],
|
70
75
|
fixes = [],
|
76
|
+
bom = (sourceCode.hasBOM ? BOM : ""),
|
71
77
|
text = sourceCode.text;
|
72
|
-
let
|
73
|
-
|
78
|
+
let lastPos = Number.NEGATIVE_INFINITY,
|
79
|
+
output = bom;
|
74
80
|
|
75
81
|
messages.forEach(problem => {
|
76
82
|
if (problem.hasOwnProperty("fix")) {
|
@@ -83,53 +89,43 @@ SourceCodeFixer.applyFixes = function(sourceCode, messages) {
|
|
83
89
|
if (fixes.length) {
|
84
90
|
debug("Found fixes to apply");
|
85
91
|
|
86
|
-
|
87
|
-
fixes.sort((a, b) => b.fix.range[1] - a.fix.range[1] || b.fix.range[0] - a.fix.range[0]);
|
88
|
-
|
89
|
-
// split into array of characters for easier manipulation
|
90
|
-
const chars = text.split("");
|
91
|
-
|
92
|
-
fixes.forEach(problem => {
|
92
|
+
for (const problem of fixes.sort(compareMessagesByFixRange)) {
|
93
93
|
const fix = problem.fix;
|
94
|
-
|
94
|
+
const start = fix.range[0];
|
95
95
|
const end = fix.range[1];
|
96
|
-
let insertionText = fix.text;
|
97
|
-
|
98
|
-
if (end < lastFixPos) {
|
99
|
-
if (start < 0) {
|
100
96
|
|
101
|
-
|
102
|
-
|
103
|
-
start = 0;
|
104
|
-
}
|
105
|
-
|
106
|
-
if (start === 0 && insertionText[0] === BOM) {
|
107
|
-
|
108
|
-
// Set BOM.
|
109
|
-
prefix = BOM;
|
110
|
-
insertionText = insertionText.slice(1);
|
111
|
-
}
|
112
|
-
|
113
|
-
chars.splice(start, end - start, insertionText);
|
114
|
-
lastFixPos = start;
|
115
|
-
} else {
|
97
|
+
// Remain it as a problem if it's overlapped.
|
98
|
+
if (lastPos >= start) {
|
116
99
|
remainingMessages.push(problem);
|
100
|
+
continue;
|
117
101
|
}
|
118
|
-
|
102
|
+
|
103
|
+
// Remove BOM.
|
104
|
+
if ((start < 0 && end >= 0) || (start === 0 && fix.text.startsWith(BOM))) {
|
105
|
+
output = "";
|
106
|
+
}
|
107
|
+
|
108
|
+
// Make output to this fix.
|
109
|
+
output += text.slice(Math.max(0, lastPos), Math.max(0, start));
|
110
|
+
output += fix.text;
|
111
|
+
lastPos = end;
|
112
|
+
}
|
113
|
+
output += text.slice(Math.max(0, lastPos));
|
119
114
|
|
120
115
|
return {
|
121
116
|
fixed: true,
|
122
117
|
messages: remainingMessages.sort(compareMessagesByLocation),
|
123
|
-
output
|
124
|
-
};
|
125
|
-
} else {
|
126
|
-
debug("No fixes to apply");
|
127
|
-
return {
|
128
|
-
fixed: false,
|
129
|
-
messages,
|
130
|
-
output: prefix + text
|
118
|
+
output
|
131
119
|
};
|
132
120
|
}
|
121
|
+
|
122
|
+
debug("No fixes to apply");
|
123
|
+
return {
|
124
|
+
fixed: false,
|
125
|
+
messages,
|
126
|
+
output: bom + text
|
127
|
+
};
|
128
|
+
|
133
129
|
};
|
134
130
|
|
135
131
|
module.exports = SourceCodeFixer;
|
package/lib/util/source-code.js
CHANGED
@@ -8,8 +8,9 @@
|
|
8
8
|
// Requirements
|
9
9
|
//------------------------------------------------------------------------------
|
10
10
|
|
11
|
-
const
|
12
|
-
Traverser = require("./traverser")
|
11
|
+
const TokenStore = require("../token-store"),
|
12
|
+
Traverser = require("./traverser"),
|
13
|
+
astUtils = require("../ast-utils");
|
13
14
|
|
14
15
|
//------------------------------------------------------------------------------
|
15
16
|
// Private
|
@@ -56,9 +57,9 @@ function findJSDocComment(comments, line) {
|
|
56
57
|
|
57
58
|
if (line - comments[i].loc.end.line <= 1) {
|
58
59
|
return comments[i];
|
59
|
-
} else {
|
60
|
-
break;
|
61
60
|
}
|
61
|
+
break;
|
62
|
+
|
62
63
|
}
|
63
64
|
}
|
64
65
|
}
|
@@ -77,6 +78,28 @@ function looksLikeExport(astNode) {
|
|
77
78
|
astNode.type === "ExportAllDeclaration" || astNode.type === "ExportSpecifier";
|
78
79
|
}
|
79
80
|
|
81
|
+
/**
|
82
|
+
* Merges two sorted lists into a larger sorted list in O(n) time
|
83
|
+
* @param {Token[]} tokens The list of tokens
|
84
|
+
* @param {Token[]} comments The list of comments
|
85
|
+
* @returns {Token[]} A sorted list of tokens and comments
|
86
|
+
*/
|
87
|
+
function sortedMerge(tokens, comments) {
|
88
|
+
const result = [];
|
89
|
+
let tokenIndex = 0;
|
90
|
+
let commentIndex = 0;
|
91
|
+
|
92
|
+
while (tokenIndex < tokens.length || commentIndex < comments.length) {
|
93
|
+
if (commentIndex >= comments.length || tokenIndex < tokens.length && tokens[tokenIndex].range[0] < comments[commentIndex].range[0]) {
|
94
|
+
result.push(tokens[tokenIndex++]);
|
95
|
+
} else {
|
96
|
+
result.push(comments[commentIndex++]);
|
97
|
+
}
|
98
|
+
}
|
99
|
+
|
100
|
+
return result;
|
101
|
+
}
|
102
|
+
|
80
103
|
|
81
104
|
//------------------------------------------------------------------------------
|
82
105
|
// Public Interface
|
@@ -117,21 +140,14 @@ function SourceCode(text, ast) {
|
|
117
140
|
*/
|
118
141
|
this.lines = SourceCode.splitLines(this.text);
|
119
142
|
|
120
|
-
this.tokensAndComments = ast.tokens
|
121
|
-
.concat(ast.comments)
|
122
|
-
.sort((left, right) => left.range[0] - right.range[0]);
|
143
|
+
this.tokensAndComments = sortedMerge(ast.tokens, ast.comments);
|
123
144
|
|
124
145
|
// create token store methods
|
125
|
-
const tokenStore =
|
126
|
-
|
127
|
-
Object.keys(tokenStore).forEach(methodName => {
|
128
|
-
this[methodName] = tokenStore[methodName];
|
129
|
-
});
|
130
|
-
|
131
|
-
const tokensAndCommentsStore = createTokenStore(this.tokensAndComments);
|
146
|
+
const tokenStore = new TokenStore(ast.tokens, ast.comments);
|
132
147
|
|
133
|
-
|
134
|
-
|
148
|
+
for (const methodName of TokenStore.PUBLIC_METHODS) {
|
149
|
+
this[methodName] = tokenStore[methodName].bind(tokenStore);
|
150
|
+
}
|
135
151
|
|
136
152
|
// don't allow modification of this object
|
137
153
|
Object.freeze(this);
|
@@ -145,7 +161,7 @@ function SourceCode(text, ast) {
|
|
145
161
|
* @public
|
146
162
|
*/
|
147
163
|
SourceCode.splitLines = function(text) {
|
148
|
-
return text.split(
|
164
|
+
return text.split(astUtils.createGlobalLinebreakMatcher());
|
149
165
|
};
|
150
166
|
|
151
167
|
SourceCode.prototype = {
|
@@ -162,9 +178,9 @@ SourceCode.prototype = {
|
|
162
178
|
if (node) {
|
163
179
|
return this.text.slice(Math.max(node.range[0] - (beforeCount || 0), 0),
|
164
180
|
node.range[1] + (afterCount || 0));
|
165
|
-
} else {
|
166
|
-
return this.text;
|
167
181
|
}
|
182
|
+
return this.text;
|
183
|
+
|
168
184
|
|
169
185
|
},
|
170
186
|
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "eslint",
|
3
|
-
"version": "3.
|
3
|
+
"version": "3.16.0",
|
4
4
|
"author": "Nicholas C. Zakas <nicholas+npm@nczconsulting.com>",
|
5
5
|
"description": "An AST-based pattern checker for JavaScript.",
|
6
6
|
"bin": {
|
@@ -40,7 +40,7 @@
|
|
40
40
|
"debug": "^2.1.1",
|
41
41
|
"doctrine": "^1.2.2",
|
42
42
|
"escope": "^3.6.0",
|
43
|
-
"espree": "^3.
|
43
|
+
"espree": "^3.4.0",
|
44
44
|
"estraverse": "^4.2.0",
|
45
45
|
"esutils": "^2.0.2",
|
46
46
|
"file-entry-cache": "^2.0.0",
|
@@ -98,7 +98,7 @@
|
|
98
98
|
"load-perf": "^0.2.0",
|
99
99
|
"markdownlint": "^0.3.1",
|
100
100
|
"mocha": "^2.4.5",
|
101
|
-
"mock-fs": "^
|
101
|
+
"mock-fs": "^4.0.0",
|
102
102
|
"npm-license": "^0.3.2",
|
103
103
|
"phantomjs-prebuilt": "^2.1.7",
|
104
104
|
"proxyquire": "^1.7.10",
|