eslint 4.4.0 → 4.6.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.
@@ -53,37 +53,28 @@ function SourceCodeFixer() {
53
53
  /**
54
54
  * Applies the fixes specified by the messages to the given text. Tries to be
55
55
  * smart about the fixes and won't apply fixes over the same area in the text.
56
- * @param {SourceCode} sourceCode The source code to apply the changes to.
56
+ * @param {string} sourceText The text to apply the changes to.
57
57
  * @param {Message[]} messages The array of messages reported by ESLint.
58
58
  * @param {boolean|Function} [shouldFix=true] Determines whether each message should be fixed
59
59
  * @returns {Object} An object containing the fixed text and any unfixed messages.
60
60
  */
61
- SourceCodeFixer.applyFixes = function(sourceCode, messages, shouldFix) {
61
+ SourceCodeFixer.applyFixes = function(sourceText, messages, shouldFix) {
62
62
  debug("Applying fixes");
63
63
 
64
- if (!sourceCode) {
65
- debug("No source code to fix");
66
- return {
67
- fixed: false,
68
- messages,
69
- output: ""
70
- };
71
- }
72
-
73
64
  if (shouldFix === false) {
74
65
  debug("shouldFix parameter was false, not attempting fixes");
75
66
  return {
76
67
  fixed: false,
77
68
  messages,
78
- output: sourceCode.text
69
+ output: sourceText
79
70
  };
80
71
  }
81
72
 
82
73
  // clone the array
83
74
  const remainingMessages = [],
84
75
  fixes = [],
85
- bom = (sourceCode.hasBOM ? BOM : ""),
86
- text = sourceCode.text;
76
+ bom = sourceText.startsWith(BOM) ? BOM : "",
77
+ text = bom ? sourceText.slice(1) : sourceText;
87
78
  let lastPos = Number.NEGATIVE_INFINITY,
88
79
  output = bom;
89
80
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "eslint",
3
- "version": "4.4.0",
3
+ "version": "4.6.1",
4
4
  "author": "Nicholas C. Zakas <nicholas+npm@nczconsulting.com>",
5
5
  "description": "An AST-based pattern checker for JavaScript.",
6
6
  "bin": {
@@ -37,7 +37,7 @@
37
37
  "dependencies": {
38
38
  "ajv": "^5.2.0",
39
39
  "babel-code-frame": "^6.22.0",
40
- "chalk": "^1.1.3",
40
+ "chalk": "^2.1.0",
41
41
  "concat-stream": "^1.6.0",
42
42
  "cross-spawn": "^5.1.0",
43
43
  "debug": "^2.6.8",
@@ -68,6 +68,7 @@
68
68
  "progress": "^2.0.0",
69
69
  "require-uncached": "^1.0.3",
70
70
  "semver": "^5.3.0",
71
+ "strip-ansi": "^4.0.0",
71
72
  "strip-json-comments": "~2.0.1",
72
73
  "table": "^4.0.1",
73
74
  "text-table": "~0.2.0"
@@ -1,241 +0,0 @@
1
- /**
2
- * @fileoverview RuleContext utility for rules
3
- * @author Nicholas C. Zakas
4
- */
5
- "use strict";
6
-
7
- //------------------------------------------------------------------------------
8
- // Requirements
9
- //------------------------------------------------------------------------------
10
-
11
- const assert = require("assert");
12
- const ruleFixer = require("./util/rule-fixer");
13
-
14
- //------------------------------------------------------------------------------
15
- // Constants
16
- //------------------------------------------------------------------------------
17
-
18
- const PASSTHROUGHS = [
19
- "getAncestors",
20
- "getDeclaredVariables",
21
- "getFilename",
22
- "getScope",
23
- "getSourceCode",
24
- "markVariableAsUsed",
25
-
26
- // DEPRECATED
27
- "getAllComments",
28
- "getComments",
29
- "getFirstToken",
30
- "getFirstTokens",
31
- "getJSDocComment",
32
- "getLastToken",
33
- "getLastTokens",
34
- "getNodeByRangeIndex",
35
- "getSource",
36
- "getSourceLines",
37
- "getTokenAfter",
38
- "getTokenBefore",
39
- "getTokenByRangeStart",
40
- "getTokens",
41
- "getTokensAfter",
42
- "getTokensBefore",
43
- "getTokensBetween"
44
- ];
45
-
46
- //------------------------------------------------------------------------------
47
- // Typedefs
48
- //------------------------------------------------------------------------------
49
-
50
- /**
51
- * An error message description
52
- * @typedef {Object} MessageDescriptor
53
- * @property {string} nodeType The type of node.
54
- * @property {Location} loc The location of the problem.
55
- * @property {string} message The problem message.
56
- * @property {Object} [data] Optional data to use to fill in placeholders in the
57
- * message.
58
- * @property {Function} fix The function to call that creates a fix command.
59
- */
60
-
61
- //------------------------------------------------------------------------------
62
- // Module Definition
63
- //------------------------------------------------------------------------------
64
-
65
- /**
66
- * Compares items in a fixes array by range.
67
- * @param {Fix} a The first message.
68
- * @param {Fix} b The second message.
69
- * @returns {int} -1 if a comes before b, 1 if a comes after b, 0 if equal.
70
- * @private
71
- */
72
- function compareFixesByRange(a, b) {
73
- return a.range[0] - b.range[0] || a.range[1] - b.range[1];
74
- }
75
-
76
- /**
77
- * Merges the given fixes array into one.
78
- * @param {Fix[]} fixes The fixes to merge.
79
- * @param {SourceCode} sourceCode The source code object to get the text between fixes.
80
- * @returns {void}
81
- */
82
- function mergeFixes(fixes, sourceCode) {
83
- if (fixes.length === 0) {
84
- return null;
85
- }
86
- if (fixes.length === 1) {
87
- return fixes[0];
88
- }
89
-
90
- fixes.sort(compareFixesByRange);
91
-
92
- const originalText = sourceCode.text;
93
- const start = fixes[0].range[0];
94
- const end = fixes[fixes.length - 1].range[1];
95
- let text = "";
96
- let lastPos = Number.MIN_SAFE_INTEGER;
97
-
98
- for (const fix of fixes) {
99
- assert(fix.range[0] >= lastPos, "Fix objects must not be overlapped in a report.");
100
-
101
- if (fix.range[0] >= 0) {
102
- text += originalText.slice(Math.max(0, start, lastPos), fix.range[0]);
103
- }
104
- text += fix.text;
105
- lastPos = fix.range[1];
106
- }
107
- text += originalText.slice(Math.max(0, start, lastPos), end);
108
-
109
- return { range: [start, end], text };
110
- }
111
-
112
- /**
113
- * Gets one fix object from the given descriptor.
114
- * If the descriptor retrieves multiple fixes, this merges those to one.
115
- * @param {Object} descriptor The report descriptor.
116
- * @param {SourceCode} sourceCode The source code object to get text between fixes.
117
- * @returns {Fix} The got fix object.
118
- */
119
- function getFix(descriptor, sourceCode) {
120
- if (typeof descriptor.fix !== "function") {
121
- return null;
122
- }
123
-
124
- // @type {null | Fix | Fix[] | IterableIterator<Fix>}
125
- const fix = descriptor.fix(ruleFixer);
126
-
127
- // Merge to one.
128
- if (fix && Symbol.iterator in fix) {
129
- return mergeFixes(Array.from(fix), sourceCode);
130
- }
131
- return fix;
132
- }
133
-
134
- /**
135
- * Rule context class
136
- * Acts as an abstraction layer between rules and the main linter object.
137
- */
138
- class RuleContext {
139
-
140
- /**
141
- * @param {string} ruleId The ID of the rule using this object.
142
- * @param {Linter} linter The linter object.
143
- * @param {number} severity The configured severity level of the rule.
144
- * @param {Array} options The configuration information to be added to the rule.
145
- * @param {Object} settings The configuration settings passed from the config file.
146
- * @param {Object} parserOptions The parserOptions settings passed from the config file.
147
- * @param {Object} parserPath The parser setting passed from the config file.
148
- * @param {Object} meta The metadata of the rule
149
- * @param {Object} parserServices The parser services for the rule.
150
- */
151
- constructor(ruleId, linter, severity, options, settings, parserOptions, parserPath, meta, parserServices) {
152
-
153
- // public.
154
- this.id = ruleId;
155
- this.options = options;
156
- this.settings = settings;
157
- this.parserOptions = parserOptions;
158
- this.parserPath = parserPath;
159
- this.meta = meta;
160
-
161
- // create a separate copy and freeze it (it's not nice to freeze other people's objects)
162
- this.parserServices = Object.freeze(Object.assign({}, parserServices));
163
-
164
- // private.
165
- this._linter = linter;
166
- this._severity = severity;
167
-
168
- Object.freeze(this);
169
- }
170
-
171
- /**
172
- * Passthrough to Linter#report() that automatically assigns the rule ID and severity.
173
- * @param {ASTNode|MessageDescriptor} nodeOrDescriptor The AST node related to the message or a message
174
- * descriptor.
175
- * @param {Object=} location The location of the error.
176
- * @param {string} message The message to display to the user.
177
- * @param {Object} opts Optional template data which produces a formatted message
178
- * with symbols being replaced by this object's values.
179
- * @returns {void}
180
- */
181
- report(nodeOrDescriptor, location, message, opts) {
182
-
183
- // check to see if it's a new style call
184
- if (arguments.length === 1) {
185
- const descriptor = nodeOrDescriptor;
186
- const fix = getFix(descriptor, this.getSourceCode());
187
-
188
- if (descriptor.loc) {
189
- this._linter.report(
190
- this.id,
191
- this._severity,
192
- descriptor.node,
193
- descriptor.loc,
194
- descriptor.message,
195
- descriptor.data,
196
- fix,
197
- this.meta
198
- );
199
- } else {
200
- this._linter.report(
201
- this.id,
202
- this._severity,
203
- descriptor.node,
204
-
205
- /* loc not provided */
206
- descriptor.message,
207
- descriptor.data,
208
- fix,
209
- this.meta
210
- );
211
- }
212
-
213
- } else {
214
-
215
- // old style call
216
- this._linter.report(
217
- this.id,
218
- this._severity,
219
- nodeOrDescriptor,
220
- location,
221
- message,
222
- opts,
223
- this.meta
224
- );
225
- }
226
- }
227
- }
228
-
229
- // Copy over passthrough methods.
230
- PASSTHROUGHS.forEach(name => {
231
- Object.defineProperty(RuleContext.prototype, name, {
232
- value() {
233
- return this._linter[name].apply(this._linter, arguments);
234
- },
235
- configurable: true,
236
- writable: true,
237
- enumerable: false
238
- });
239
- });
240
-
241
- module.exports = RuleContext;
@@ -1,62 +0,0 @@
1
- /**
2
- * @fileoverview Helpers to test EventGenerator interface.
3
- * @author Toru Nagashima
4
- */
5
- "use strict";
6
-
7
- /* global describe, it */
8
-
9
- //------------------------------------------------------------------------------
10
- // Requirements
11
- //------------------------------------------------------------------------------
12
-
13
- const assert = require("assert");
14
-
15
- //------------------------------------------------------------------------------
16
- // Public Interface
17
- //------------------------------------------------------------------------------
18
-
19
- module.exports = {
20
-
21
- /**
22
- * Overrideable `describe` function to test.
23
- * @param {string} text - A description.
24
- * @param {Function} method - A test logic.
25
- * @returns {any} The returned value with the test logic.
26
- */
27
- describe: (typeof describe === "function") ? describe : /* istanbul ignore next */ function(text, method) {
28
- return method.apply(this);
29
- },
30
-
31
- /**
32
- * Overrideable `it` function to test.
33
- * @param {string} text - A description.
34
- * @param {Function} method - A test logic.
35
- * @returns {any} The returned value with the test logic.
36
- */
37
- it: (typeof it === "function") ? it : /* istanbul ignore next */ function(text, method) {
38
- return method.apply(this);
39
- },
40
-
41
- /**
42
- * Does some tests to check a given object implements the EventGenerator interface.
43
- * @param {Object} instance - An object to check.
44
- * @returns {void}
45
- */
46
- testEventGeneratorInterface(instance) {
47
- this.describe("should implement EventGenerator interface", () => {
48
- this.it("should have `emitter` property.", () => {
49
- assert.equal(typeof instance.emitter, "object");
50
- assert.equal(typeof instance.emitter.emit, "function");
51
- });
52
-
53
- this.it("should have `enterNode` property.", () => {
54
- assert.equal(typeof instance.enterNode, "function");
55
- });
56
-
57
- this.it("should have `leaveNode` property.", () => {
58
- assert.equal(typeof instance.leaveNode, "function");
59
- });
60
- });
61
- }
62
- };
@@ -1,48 +0,0 @@
1
- /**
2
- * @author Toru Nagashima <https://github.com/mysticatea>
3
- */
4
- "use strict";
5
-
6
- const espree = require("espree");
7
- const Traverser = require("../util/traverser");
8
-
9
- /**
10
- * Define `start`/`end` properties as throwing error.
11
- * @param {ASTNode} node The node to define.
12
- * @returns {void}
13
- */
14
- function defineStartEndAsError(node) {
15
- Object.defineProperty(node, "start", {
16
- get() {
17
- throw new Error("Use node.range[0] instead of node.start");
18
- },
19
- configurable: true,
20
- enumerable: false
21
- });
22
- Object.defineProperty(node, "end", {
23
- get() {
24
- throw new Error("Use node.range[1] instead of node.end");
25
- },
26
- configurable: true,
27
- enumerable: false
28
- });
29
- }
30
-
31
- /**
32
- * Define `start`/`end` properties of all nodes of the given AST as throwing error.
33
- * @param {ASTNode} ast The root node to errorize `start`/`end` properties.
34
- * @returns {void}
35
- */
36
- function defineStartEndAsErrorInTree(ast) {
37
- new Traverser().traverse(ast, { enter: defineStartEndAsError });
38
- ast.tokens.forEach(defineStartEndAsError);
39
- ast.comments.forEach(defineStartEndAsError);
40
- }
41
-
42
- module.exports.parse = (code, options) => {
43
- const ret = espree.parse(code, options);
44
-
45
- defineStartEndAsErrorInTree(ret.ast || ret);
46
-
47
- return ret;
48
- };