immosquare-cleaner 0.1.46 → 0.1.47
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/immosquare-cleaner/version.rb +1 -1
- data/linters/rubocop-3.3.4.yml +2 -0
- data/linters/rubocop.yml +2 -0
- data/node_modules/@eslint/eslintrc/node_modules/ignore/LICENSE-MIT +21 -0
- data/node_modules/@eslint/eslintrc/node_modules/ignore/README.md +412 -0
- data/node_modules/@eslint/eslintrc/node_modules/ignore/index.d.ts +61 -0
- data/node_modules/@eslint/eslintrc/node_modules/ignore/index.js +618 -0
- data/node_modules/@eslint/eslintrc/node_modules/ignore/legacy.js +539 -0
- data/node_modules/@eslint/eslintrc/node_modules/ignore/package.json +73 -0
- data/node_modules/@eslint/js/package.json +1 -1
- data/node_modules/@eslint/plugin-kit/LICENSE +201 -0
- data/node_modules/@eslint/plugin-kit/README.md +224 -0
- data/node_modules/@eslint/plugin-kit/dist/cjs/index.cjs +555 -0
- data/node_modules/@eslint/plugin-kit/dist/cjs/index.d.cts +239 -0
- data/node_modules/@eslint/plugin-kit/dist/cjs/types.ts +7 -0
- data/node_modules/@eslint/plugin-kit/dist/esm/index.d.ts +239 -0
- data/node_modules/@eslint/plugin-kit/dist/esm/index.js +551 -0
- data/node_modules/@eslint/plugin-kit/dist/esm/types.d.ts +6 -0
- data/node_modules/@eslint/plugin-kit/dist/esm/types.ts +7 -0
- data/node_modules/@eslint/plugin-kit/package.json +62 -0
- data/node_modules/eslint/README.md +2 -2
- data/node_modules/eslint/lib/config/config.js +278 -0
- data/node_modules/eslint/lib/config/flat-config-array.js +3 -204
- data/node_modules/eslint/lib/languages/js/source-code/source-code.js +29 -94
- data/node_modules/eslint/lib/linter/apply-disable-directives.js +17 -28
- data/node_modules/eslint/lib/linter/file-context.js +134 -0
- data/node_modules/eslint/lib/linter/linter.js +37 -42
- data/node_modules/eslint/lib/rules/id-length.js +1 -0
- data/node_modules/eslint/lib/rules/no-invalid-regexp.js +34 -18
- data/node_modules/eslint/lib/rules/require-unicode-regexp.js +95 -14
- data/node_modules/eslint/lib/rules/utils/regular-expressions.js +11 -3
- data/node_modules/eslint/lib/types/index.d.ts +1635 -0
- data/node_modules/eslint/lib/types/rules/best-practices.d.ts +1075 -0
- data/node_modules/eslint/lib/types/rules/deprecated.d.ts +294 -0
- data/node_modules/eslint/lib/types/rules/ecmascript-6.d.ts +561 -0
- data/node_modules/eslint/lib/types/rules/index.d.ts +50 -0
- data/node_modules/eslint/lib/types/rules/node-commonjs.d.ts +160 -0
- data/node_modules/eslint/lib/types/rules/possible-errors.d.ts +598 -0
- data/node_modules/eslint/lib/types/rules/strict-mode.d.ts +38 -0
- data/node_modules/eslint/lib/types/rules/stylistic-issues.d.ts +1932 -0
- data/node_modules/eslint/lib/types/rules/variables.d.ts +221 -0
- data/node_modules/eslint/lib/types/use-at-your-own-risk.d.ts +85 -0
- data/node_modules/eslint/package.json +20 -8
- data/node_modules/ignore/index.d.ts +1 -1
- data/node_modules/ignore/index.js +25 -7
- data/node_modules/ignore/legacy.js +34 -14
- data/node_modules/ignore/package.json +12 -11
- data/node_modules/npm-check-updates/build/index.js +282 -282
- data/node_modules/npm-check-updates/build/index.js.map +1 -1
- data/node_modules/npm-check-updates/package.json +1 -1
- data/package.json +3 -3
- metadata +31 -4
- data/linters/rubocop-2.7.6.yml +0 -88
- data/node_modules/eslint/lib/linter/config-comment-parser.js +0 -169
@@ -0,0 +1,555 @@
|
|
1
|
+
'use strict';
|
2
|
+
|
3
|
+
var levn = require('levn');
|
4
|
+
|
5
|
+
/**
|
6
|
+
* @fileoverview Config Comment Parser
|
7
|
+
* @author Nicholas C. Zakas
|
8
|
+
*/
|
9
|
+
|
10
|
+
|
11
|
+
//-----------------------------------------------------------------------------
|
12
|
+
// Type Definitions
|
13
|
+
//-----------------------------------------------------------------------------
|
14
|
+
|
15
|
+
/** @typedef {import("@eslint/core").RuleConfig} RuleConfig */
|
16
|
+
/** @typedef {import("@eslint/core").RulesConfig} RulesConfig */
|
17
|
+
/** @typedef {import("./types.ts").StringConfig} StringConfig */
|
18
|
+
/** @typedef {import("./types.ts").BooleanConfig} BooleanConfig */
|
19
|
+
|
20
|
+
//-----------------------------------------------------------------------------
|
21
|
+
// Helpers
|
22
|
+
//-----------------------------------------------------------------------------
|
23
|
+
|
24
|
+
const directivesPattern = /^([a-z]+(?:-[a-z]+)*)(?:\s|$)/u;
|
25
|
+
const validSeverities = new Set([0, 1, 2, "off", "warn", "error"]);
|
26
|
+
|
27
|
+
/**
|
28
|
+
* Determines if the severity in the rule configuration is valid.
|
29
|
+
* @param {RuleConfig} ruleConfig A rule's configuration.
|
30
|
+
*/
|
31
|
+
function isSeverityValid(ruleConfig) {
|
32
|
+
const severity = Array.isArray(ruleConfig) ? ruleConfig[0] : ruleConfig;
|
33
|
+
return validSeverities.has(severity);
|
34
|
+
}
|
35
|
+
|
36
|
+
/**
|
37
|
+
* Determines if all severities in the rules configuration are valid.
|
38
|
+
* @param {RulesConfig} rulesConfig The rules configuration to check.
|
39
|
+
* @returns {boolean} `true` if all severities are valid, otherwise `false`.
|
40
|
+
*/
|
41
|
+
function isEverySeverityValid(rulesConfig) {
|
42
|
+
return Object.values(rulesConfig).every(isSeverityValid);
|
43
|
+
}
|
44
|
+
|
45
|
+
/**
|
46
|
+
* Represents a directive comment.
|
47
|
+
*/
|
48
|
+
class DirectiveComment {
|
49
|
+
/**
|
50
|
+
* The label of the directive, such as "eslint", "eslint-disable", etc.
|
51
|
+
* @type {string}
|
52
|
+
*/
|
53
|
+
label = "";
|
54
|
+
|
55
|
+
/**
|
56
|
+
* The value of the directive (the string after the label).
|
57
|
+
* @type {string}
|
58
|
+
*/
|
59
|
+
value = "";
|
60
|
+
|
61
|
+
/**
|
62
|
+
* The justification of the directive (the string after the --).
|
63
|
+
* @type {string}
|
64
|
+
*/
|
65
|
+
justification = "";
|
66
|
+
|
67
|
+
/**
|
68
|
+
* Creates a new directive comment.
|
69
|
+
* @param {string} label The label of the directive.
|
70
|
+
* @param {string} value The value of the directive.
|
71
|
+
* @param {string} justification The justification of the directive.
|
72
|
+
*/
|
73
|
+
constructor(label, value, justification) {
|
74
|
+
this.label = label;
|
75
|
+
this.value = value;
|
76
|
+
this.justification = justification;
|
77
|
+
}
|
78
|
+
}
|
79
|
+
|
80
|
+
//------------------------------------------------------------------------------
|
81
|
+
// Public Interface
|
82
|
+
//------------------------------------------------------------------------------
|
83
|
+
|
84
|
+
/**
|
85
|
+
* Object to parse ESLint configuration comments.
|
86
|
+
*/
|
87
|
+
class ConfigCommentParser {
|
88
|
+
/**
|
89
|
+
* Parses a list of "name:string_value" or/and "name" options divided by comma or
|
90
|
+
* whitespace. Used for "global" comments.
|
91
|
+
* @param {string} string The string to parse.
|
92
|
+
* @returns {StringConfig} Result map object of names and string values, or null values if no value was provided.
|
93
|
+
*/
|
94
|
+
parseStringConfig(string) {
|
95
|
+
const items = /** @type {StringConfig} */ ({});
|
96
|
+
|
97
|
+
// Collapse whitespace around `:` and `,` to make parsing easier
|
98
|
+
const trimmedString = string.replace(/\s*([:,])\s*/gu, "$1");
|
99
|
+
|
100
|
+
trimmedString.split(/\s|,+/u).forEach(name => {
|
101
|
+
if (!name) {
|
102
|
+
return;
|
103
|
+
}
|
104
|
+
|
105
|
+
// value defaults to null (if not provided), e.g: "foo" => ["foo", null]
|
106
|
+
const [key, value = null] = name.split(":");
|
107
|
+
|
108
|
+
items[key] = value;
|
109
|
+
});
|
110
|
+
|
111
|
+
return items;
|
112
|
+
}
|
113
|
+
|
114
|
+
/**
|
115
|
+
* Parses a JSON-like config.
|
116
|
+
* @param {string} string The string to parse.
|
117
|
+
* @returns {({ok: true, config: RulesConfig}|{ok: false, error: {message: string}})} Result map object
|
118
|
+
*/
|
119
|
+
parseJSONLikeConfig(string) {
|
120
|
+
// Parses a JSON-like comment by the same way as parsing CLI option.
|
121
|
+
try {
|
122
|
+
const items = levn.parse("Object", string) || {};
|
123
|
+
|
124
|
+
/*
|
125
|
+
* When the configuration has any invalid severities, it should be completely
|
126
|
+
* ignored. This is because the configuration is not valid and should not be
|
127
|
+
* applied.
|
128
|
+
*
|
129
|
+
* For example, the following configuration is invalid:
|
130
|
+
*
|
131
|
+
* "no-alert: 2 no-console: 2"
|
132
|
+
*
|
133
|
+
* This results in a configuration of { "no-alert": "2 no-console: 2" }, which is
|
134
|
+
* not valid. In this case, the configuration should be ignored.
|
135
|
+
*/
|
136
|
+
if (isEverySeverityValid(items)) {
|
137
|
+
return {
|
138
|
+
ok: true,
|
139
|
+
config: items,
|
140
|
+
};
|
141
|
+
}
|
142
|
+
} catch {
|
143
|
+
// levn parsing error: ignore to parse the string by a fallback.
|
144
|
+
}
|
145
|
+
|
146
|
+
/*
|
147
|
+
* Optionator cannot parse commaless notations.
|
148
|
+
* But we are supporting that. So this is a fallback for that.
|
149
|
+
*/
|
150
|
+
const normalizedString = string
|
151
|
+
.replace(/([-a-zA-Z0-9/]+):/gu, '"$1":')
|
152
|
+
.replace(/(\]|[0-9])\s+(?=")/u, "$1,");
|
153
|
+
|
154
|
+
try {
|
155
|
+
const items = JSON.parse(`{${normalizedString}}`);
|
156
|
+
|
157
|
+
return {
|
158
|
+
ok: true,
|
159
|
+
config: items,
|
160
|
+
};
|
161
|
+
} catch (ex) {
|
162
|
+
const errorMessage = ex instanceof Error ? ex.message : String(ex);
|
163
|
+
|
164
|
+
return {
|
165
|
+
ok: false,
|
166
|
+
error: {
|
167
|
+
message: `Failed to parse JSON from '${normalizedString}': ${errorMessage}`,
|
168
|
+
},
|
169
|
+
};
|
170
|
+
}
|
171
|
+
}
|
172
|
+
|
173
|
+
/**
|
174
|
+
* Parses a config of values separated by comma.
|
175
|
+
* @param {string} string The string to parse.
|
176
|
+
* @returns {BooleanConfig} Result map of values and true values
|
177
|
+
*/
|
178
|
+
parseListConfig(string) {
|
179
|
+
const items = /** @type {BooleanConfig} */ ({});
|
180
|
+
|
181
|
+
string.split(",").forEach(name => {
|
182
|
+
const trimmedName = name
|
183
|
+
.trim()
|
184
|
+
.replace(
|
185
|
+
/^(?<quote>['"]?)(?<ruleId>.*)\k<quote>$/su,
|
186
|
+
"$<ruleId>",
|
187
|
+
);
|
188
|
+
|
189
|
+
if (trimmedName) {
|
190
|
+
items[trimmedName] = true;
|
191
|
+
}
|
192
|
+
});
|
193
|
+
|
194
|
+
return items;
|
195
|
+
}
|
196
|
+
|
197
|
+
/**
|
198
|
+
* Extract the directive and the justification from a given directive comment and trim them.
|
199
|
+
* @param {string} value The comment text to extract.
|
200
|
+
* @returns {{directivePart: string, justificationPart: string}} The extracted directive and justification.
|
201
|
+
*/
|
202
|
+
#extractDirectiveComment(value) {
|
203
|
+
const match = /\s-{2,}\s/u.exec(value);
|
204
|
+
|
205
|
+
if (!match) {
|
206
|
+
return { directivePart: value.trim(), justificationPart: "" };
|
207
|
+
}
|
208
|
+
|
209
|
+
const directive = value.slice(0, match.index).trim();
|
210
|
+
const justification = value.slice(match.index + match[0].length).trim();
|
211
|
+
|
212
|
+
return { directivePart: directive, justificationPart: justification };
|
213
|
+
}
|
214
|
+
|
215
|
+
/**
|
216
|
+
* Parses a directive comment into directive text and value.
|
217
|
+
* @param {string} string The string with the directive to be parsed.
|
218
|
+
* @returns {DirectiveComment|undefined} The parsed directive or `undefined` if the directive is invalid.
|
219
|
+
*/
|
220
|
+
parseDirective(string) {
|
221
|
+
const { directivePart, justificationPart } =
|
222
|
+
this.#extractDirectiveComment(string);
|
223
|
+
const match = directivesPattern.exec(directivePart);
|
224
|
+
|
225
|
+
if (!match) {
|
226
|
+
return undefined;
|
227
|
+
}
|
228
|
+
|
229
|
+
const directiveText = match[1];
|
230
|
+
const directiveValue = directivePart.slice(
|
231
|
+
match.index + directiveText.length,
|
232
|
+
);
|
233
|
+
|
234
|
+
return new DirectiveComment(
|
235
|
+
directiveText,
|
236
|
+
directiveValue.trim(),
|
237
|
+
justificationPart,
|
238
|
+
);
|
239
|
+
}
|
240
|
+
}
|
241
|
+
|
242
|
+
/**
|
243
|
+
* @fileoverview A collection of helper classes for implementing `SourceCode`.
|
244
|
+
* @author Nicholas C. Zakas
|
245
|
+
*/
|
246
|
+
|
247
|
+
/* eslint class-methods-use-this: off -- Required to complete interface. */
|
248
|
+
|
249
|
+
//-----------------------------------------------------------------------------
|
250
|
+
// Type Definitions
|
251
|
+
//-----------------------------------------------------------------------------
|
252
|
+
|
253
|
+
/** @typedef {import("@eslint/core").VisitTraversalStep} VisitTraversalStep */
|
254
|
+
/** @typedef {import("@eslint/core").CallTraversalStep} CallTraversalStep */
|
255
|
+
/** @typedef {import("@eslint/core").TextSourceCode} TextSourceCode */
|
256
|
+
/** @typedef {import("@eslint/core").TraversalStep} TraversalStep */
|
257
|
+
/** @typedef {import("@eslint/core").SourceLocation} SourceLocation */
|
258
|
+
/** @typedef {import("@eslint/core").SourceLocationWithOffset} SourceLocationWithOffset */
|
259
|
+
/** @typedef {import("@eslint/core").SourceRange} SourceRange */
|
260
|
+
|
261
|
+
//-----------------------------------------------------------------------------
|
262
|
+
// Helpers
|
263
|
+
//-----------------------------------------------------------------------------
|
264
|
+
|
265
|
+
/**
|
266
|
+
* Determines if a node has ESTree-style loc information.
|
267
|
+
* @param {object} node The node to check.
|
268
|
+
* @returns {node is {loc:SourceLocation}} `true` if the node has ESTree-style loc information, `false` if not.
|
269
|
+
*/
|
270
|
+
function hasESTreeStyleLoc(node) {
|
271
|
+
return "loc" in node;
|
272
|
+
}
|
273
|
+
|
274
|
+
/**
|
275
|
+
* Determines if a node has position-style loc information.
|
276
|
+
* @param {object} node The node to check.
|
277
|
+
* @returns {node is {position:SourceLocation}} `true` if the node has position-style range information, `false` if not.
|
278
|
+
*/
|
279
|
+
function hasPosStyleLoc(node) {
|
280
|
+
return "position" in node;
|
281
|
+
}
|
282
|
+
|
283
|
+
/**
|
284
|
+
* Determines if a node has ESTree-style range information.
|
285
|
+
* @param {object} node The node to check.
|
286
|
+
* @returns {node is {range:SourceRange}} `true` if the node has ESTree-style range information, `false` if not.
|
287
|
+
*/
|
288
|
+
function hasESTreeStyleRange(node) {
|
289
|
+
return "range" in node;
|
290
|
+
}
|
291
|
+
|
292
|
+
/**
|
293
|
+
* Determines if a node has position-style range information.
|
294
|
+
* @param {object} node The node to check.
|
295
|
+
* @returns {node is {position:SourceLocationWithOffset}} `true` if the node has position-style range information, `false` if not.
|
296
|
+
*/
|
297
|
+
function hasPosStyleRange(node) {
|
298
|
+
return "position" in node;
|
299
|
+
}
|
300
|
+
|
301
|
+
//-----------------------------------------------------------------------------
|
302
|
+
// Exports
|
303
|
+
//-----------------------------------------------------------------------------
|
304
|
+
|
305
|
+
/**
|
306
|
+
* A class to represent a step in the traversal process where a node is visited.
|
307
|
+
* @implements {VisitTraversalStep}
|
308
|
+
*/
|
309
|
+
class VisitNodeStep {
|
310
|
+
/**
|
311
|
+
* The type of the step.
|
312
|
+
* @type {"visit"}
|
313
|
+
* @readonly
|
314
|
+
*/
|
315
|
+
type = "visit";
|
316
|
+
|
317
|
+
/**
|
318
|
+
* The kind of the step. Represents the same data as the `type` property
|
319
|
+
* but it's a number for performance.
|
320
|
+
* @type {1}
|
321
|
+
* @readonly
|
322
|
+
*/
|
323
|
+
kind = 1;
|
324
|
+
|
325
|
+
/**
|
326
|
+
* The target of the step.
|
327
|
+
* @type {object}
|
328
|
+
*/
|
329
|
+
target;
|
330
|
+
|
331
|
+
/**
|
332
|
+
* The phase of the step.
|
333
|
+
* @type {1|2}
|
334
|
+
*/
|
335
|
+
phase;
|
336
|
+
|
337
|
+
/**
|
338
|
+
* The arguments of the step.
|
339
|
+
* @type {Array<any>}
|
340
|
+
*/
|
341
|
+
args;
|
342
|
+
|
343
|
+
/**
|
344
|
+
* Creates a new instance.
|
345
|
+
* @param {Object} options The options for the step.
|
346
|
+
* @param {object} options.target The target of the step.
|
347
|
+
* @param {1|2} options.phase The phase of the step.
|
348
|
+
* @param {Array<any>} options.args The arguments of the step.
|
349
|
+
*/
|
350
|
+
constructor({ target, phase, args }) {
|
351
|
+
this.target = target;
|
352
|
+
this.phase = phase;
|
353
|
+
this.args = args;
|
354
|
+
}
|
355
|
+
}
|
356
|
+
|
357
|
+
/**
|
358
|
+
* A class to represent a step in the traversal process where a
|
359
|
+
* method is called.
|
360
|
+
* @implements {CallTraversalStep}
|
361
|
+
*/
|
362
|
+
class CallMethodStep {
|
363
|
+
/**
|
364
|
+
* The type of the step.
|
365
|
+
* @type {"call"}
|
366
|
+
* @readonly
|
367
|
+
*/
|
368
|
+
type = "call";
|
369
|
+
|
370
|
+
/**
|
371
|
+
* The kind of the step. Represents the same data as the `type` property
|
372
|
+
* but it's a number for performance.
|
373
|
+
* @type {2}
|
374
|
+
* @readonly
|
375
|
+
*/
|
376
|
+
kind = 2;
|
377
|
+
|
378
|
+
/**
|
379
|
+
* The name of the method to call.
|
380
|
+
* @type {string}
|
381
|
+
*/
|
382
|
+
target;
|
383
|
+
|
384
|
+
/**
|
385
|
+
* The arguments to pass to the method.
|
386
|
+
* @type {Array<any>}
|
387
|
+
*/
|
388
|
+
args;
|
389
|
+
|
390
|
+
/**
|
391
|
+
* Creates a new instance.
|
392
|
+
* @param {Object} options The options for the step.
|
393
|
+
* @param {string} options.target The target of the step.
|
394
|
+
* @param {Array<any>} options.args The arguments of the step.
|
395
|
+
*/
|
396
|
+
constructor({ target, args }) {
|
397
|
+
this.target = target;
|
398
|
+
this.args = args;
|
399
|
+
}
|
400
|
+
}
|
401
|
+
|
402
|
+
/**
|
403
|
+
* Source Code Base Object
|
404
|
+
* @implements {TextSourceCode}
|
405
|
+
*/
|
406
|
+
class TextSourceCodeBase {
|
407
|
+
/**
|
408
|
+
* The lines of text in the source code.
|
409
|
+
* @type {Array<string>}
|
410
|
+
*/
|
411
|
+
#lines;
|
412
|
+
|
413
|
+
/**
|
414
|
+
* The AST of the source code.
|
415
|
+
* @type {object}
|
416
|
+
*/
|
417
|
+
ast;
|
418
|
+
|
419
|
+
/**
|
420
|
+
* The text of the source code.
|
421
|
+
* @type {string}
|
422
|
+
*/
|
423
|
+
text;
|
424
|
+
|
425
|
+
/**
|
426
|
+
* Creates a new instance.
|
427
|
+
* @param {Object} options The options for the instance.
|
428
|
+
* @param {string} options.text The source code text.
|
429
|
+
* @param {object} options.ast The root AST node.
|
430
|
+
* @param {RegExp} [options.lineEndingPattern] The pattern to match lineEndings in the source code.
|
431
|
+
*/
|
432
|
+
constructor({ text, ast, lineEndingPattern = /\r?\n/u }) {
|
433
|
+
this.ast = ast;
|
434
|
+
this.text = text;
|
435
|
+
this.#lines = text.split(lineEndingPattern);
|
436
|
+
}
|
437
|
+
|
438
|
+
/**
|
439
|
+
* Returns the loc information for the given node or token.
|
440
|
+
* @param {object} nodeOrToken The node or token to get the loc information for.
|
441
|
+
* @returns {SourceLocation} The loc information for the node or token.
|
442
|
+
*/
|
443
|
+
getLoc(nodeOrToken) {
|
444
|
+
if (hasESTreeStyleLoc(nodeOrToken)) {
|
445
|
+
return nodeOrToken.loc;
|
446
|
+
}
|
447
|
+
|
448
|
+
if (hasPosStyleLoc(nodeOrToken)) {
|
449
|
+
return nodeOrToken.position;
|
450
|
+
}
|
451
|
+
|
452
|
+
throw new Error(
|
453
|
+
"Custom getLoc() method must be implemented in the subclass.",
|
454
|
+
);
|
455
|
+
}
|
456
|
+
|
457
|
+
/**
|
458
|
+
* Returns the range information for the given node or token.
|
459
|
+
* @param {object} nodeOrToken The node or token to get the range information for.
|
460
|
+
* @returns {SourceRange} The range information for the node or token.
|
461
|
+
*/
|
462
|
+
getRange(nodeOrToken) {
|
463
|
+
if (hasESTreeStyleRange(nodeOrToken)) {
|
464
|
+
return nodeOrToken.range;
|
465
|
+
}
|
466
|
+
|
467
|
+
if (hasPosStyleRange(nodeOrToken)) {
|
468
|
+
return [
|
469
|
+
nodeOrToken.position.start.offset,
|
470
|
+
nodeOrToken.position.end.offset,
|
471
|
+
];
|
472
|
+
}
|
473
|
+
|
474
|
+
throw new Error(
|
475
|
+
"Custom getRange() method must be implemented in the subclass.",
|
476
|
+
);
|
477
|
+
}
|
478
|
+
|
479
|
+
/* eslint-disable no-unused-vars -- Required to complete interface. */
|
480
|
+
/**
|
481
|
+
* Returns the parent of the given node.
|
482
|
+
* @param {object} node The node to get the parent of.
|
483
|
+
* @returns {object|undefined} The parent of the node.
|
484
|
+
*/
|
485
|
+
getParent(node) {
|
486
|
+
throw new Error("Not implemented.");
|
487
|
+
}
|
488
|
+
/* eslint-enable no-unused-vars -- Required to complete interface. */
|
489
|
+
|
490
|
+
/**
|
491
|
+
* Gets all the ancestors of a given node
|
492
|
+
* @param {object} node The node
|
493
|
+
* @returns {Array<object>} All the ancestor nodes in the AST, not including the provided node, starting
|
494
|
+
* from the root node at index 0 and going inwards to the parent node.
|
495
|
+
* @throws {TypeError} When `node` is missing.
|
496
|
+
*/
|
497
|
+
getAncestors(node) {
|
498
|
+
if (!node) {
|
499
|
+
throw new TypeError("Missing required argument: node.");
|
500
|
+
}
|
501
|
+
|
502
|
+
const ancestorsStartingAtParent = [];
|
503
|
+
|
504
|
+
for (
|
505
|
+
let ancestor = this.getParent(node);
|
506
|
+
ancestor;
|
507
|
+
ancestor = this.getParent(ancestor)
|
508
|
+
) {
|
509
|
+
ancestorsStartingAtParent.push(ancestor);
|
510
|
+
}
|
511
|
+
|
512
|
+
return ancestorsStartingAtParent.reverse();
|
513
|
+
}
|
514
|
+
|
515
|
+
/**
|
516
|
+
* Gets the source code for the given node.
|
517
|
+
* @param {object} [node] The AST node to get the text for.
|
518
|
+
* @param {number} [beforeCount] The number of characters before the node to retrieve.
|
519
|
+
* @param {number} [afterCount] The number of characters after the node to retrieve.
|
520
|
+
* @returns {string} The text representing the AST node.
|
521
|
+
* @public
|
522
|
+
*/
|
523
|
+
getText(node, beforeCount, afterCount) {
|
524
|
+
if (node) {
|
525
|
+
const range = this.getRange(node);
|
526
|
+
return this.text.slice(
|
527
|
+
Math.max(range[0] - (beforeCount || 0), 0),
|
528
|
+
range[1] + (afterCount || 0),
|
529
|
+
);
|
530
|
+
}
|
531
|
+
return this.text;
|
532
|
+
}
|
533
|
+
|
534
|
+
/**
|
535
|
+
* Gets the entire source text split into an array of lines.
|
536
|
+
* @returns {Array<string>} The source text as an array of lines.
|
537
|
+
* @public
|
538
|
+
*/
|
539
|
+
get lines() {
|
540
|
+
return this.#lines;
|
541
|
+
}
|
542
|
+
|
543
|
+
/**
|
544
|
+
* Traverse the source code and return the steps that were taken.
|
545
|
+
* @returns {Iterable<TraversalStep>} The steps that were taken while traversing the source code.
|
546
|
+
*/
|
547
|
+
traverse() {
|
548
|
+
throw new Error("Not implemented.");
|
549
|
+
}
|
550
|
+
}
|
551
|
+
|
552
|
+
exports.CallMethodStep = CallMethodStep;
|
553
|
+
exports.ConfigCommentParser = ConfigCommentParser;
|
554
|
+
exports.TextSourceCodeBase = TextSourceCodeBase;
|
555
|
+
exports.VisitNodeStep = VisitNodeStep;
|