eslint 6.5.0 → 6.7.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/CHANGELOG.md +115 -0
- package/README.md +10 -9
- package/conf/config-schema.js +1 -0
- package/conf/default-cli-options.js +1 -1
- package/lib/cli-engine/cascading-config-array-factory.js +40 -14
- package/lib/cli-engine/cli-engine.js +49 -21
- package/lib/cli-engine/config-array/config-array.js +13 -4
- package/lib/cli-engine/config-array/config-dependency.js +2 -0
- package/lib/cli-engine/config-array/extracted-config.js +27 -0
- package/lib/cli-engine/config-array/ignore-pattern.js +231 -0
- package/lib/cli-engine/config-array/index.js +2 -0
- package/lib/cli-engine/config-array/override-tester.js +2 -0
- package/lib/cli-engine/config-array-factory.js +120 -2
- package/lib/cli-engine/file-enumerator.js +51 -30
- package/lib/cli-engine/formatters/html.js +1 -0
- package/lib/init/autoconfig.js +1 -11
- package/lib/init/config-file.js +0 -1
- package/lib/init/config-initializer.js +4 -4
- package/lib/init/config-rule.js +1 -5
- package/lib/init/npm-utils.js +0 -5
- package/lib/linter/code-path-analysis/code-path-analyzer.js +24 -38
- package/lib/linter/code-path-analysis/code-path-segment.js +17 -25
- package/lib/linter/code-path-analysis/code-path-state.js +40 -81
- package/lib/linter/code-path-analysis/code-path.js +10 -11
- package/lib/linter/code-path-analysis/debug-helpers.js +8 -12
- package/lib/linter/code-path-analysis/fork-context.js +23 -34
- package/lib/linter/code-path-analysis/id-generator.js +2 -2
- package/lib/linter/linter.js +121 -95
- package/lib/linter/node-event-generator.js +3 -2
- package/lib/linter/report-translator.js +73 -7
- package/lib/rule-tester/rule-tester.js +46 -14
- package/lib/rules/accessor-pairs.js +8 -8
- package/lib/rules/array-bracket-newline.js +12 -15
- package/lib/rules/array-bracket-spacing.js +12 -12
- package/lib/rules/array-callback-return.js +6 -11
- package/lib/rules/array-element-newline.js +5 -8
- package/lib/rules/arrow-parens.js +0 -1
- package/lib/rules/block-scoped-var.js +3 -3
- package/lib/rules/block-spacing.js +4 -4
- package/lib/rules/camelcase.js +19 -6
- package/lib/rules/capitalized-comments.js +0 -7
- package/lib/rules/class-methods-use-this.js +3 -3
- package/lib/rules/comma-dangle.js +20 -25
- package/lib/rules/comma-spacing.js +1 -1
- package/lib/rules/computed-property-spacing.js +14 -14
- package/lib/rules/consistent-return.js +4 -5
- package/lib/rules/consistent-this.js +5 -5
- package/lib/rules/constructor-super.js +14 -16
- package/lib/rules/curly.js +12 -9
- package/lib/rules/default-param-last.js +1 -0
- package/lib/rules/dot-location.js +11 -12
- package/lib/rules/func-names.js +6 -6
- package/lib/rules/function-call-argument-newline.js +8 -6
- package/lib/rules/generator-star-spacing.js +4 -9
- package/lib/rules/getter-return.js +4 -7
- package/lib/rules/grouped-accessor-pairs.js +224 -0
- package/lib/rules/indent.js +13 -2
- package/lib/rules/index.js +5 -0
- package/lib/rules/init-declarations.js +2 -2
- package/lib/rules/jsx-quotes.js +1 -1
- package/lib/rules/keyword-spacing.js +32 -56
- package/lib/rules/lines-around-directive.js +1 -1
- package/lib/rules/max-len.js +0 -5
- package/lib/rules/max-statements-per-line.js +3 -7
- package/lib/rules/multiline-comment-style.js +237 -106
- package/lib/rules/multiline-ternary.js +3 -3
- package/lib/rules/newline-after-var.js +6 -7
- package/lib/rules/newline-before-return.js +8 -9
- package/lib/rules/newline-per-chained-call.js +2 -4
- package/lib/rules/no-class-assign.js +2 -2
- package/lib/rules/no-compare-neg-zero.js +1 -2
- package/lib/rules/no-cond-assign.js +14 -4
- package/lib/rules/no-confusing-arrow.js +2 -2
- package/lib/rules/no-console.js +4 -8
- package/lib/rules/no-const-assign.js +1 -1
- package/lib/rules/no-constructor-return.js +62 -0
- package/lib/rules/no-dupe-args.js +1 -1
- package/lib/rules/no-dupe-class-members.js +3 -4
- package/lib/rules/no-dupe-else-if.js +122 -0
- package/lib/rules/no-dupe-keys.js +6 -5
- package/lib/rules/no-duplicate-imports.js +14 -18
- package/lib/rules/no-else-return.js +0 -8
- package/lib/rules/no-empty-function.js +2 -4
- package/lib/rules/no-eval.js +10 -18
- package/lib/rules/no-ex-assign.js +1 -1
- package/lib/rules/no-extra-bind.js +5 -12
- package/lib/rules/no-extra-boolean-cast.js +0 -2
- package/lib/rules/no-extra-label.js +4 -9
- package/lib/rules/no-extra-parens.js +17 -15
- package/lib/rules/no-extra-semi.js +5 -6
- package/lib/rules/no-fallthrough.js +6 -6
- package/lib/rules/no-func-assign.js +3 -3
- package/lib/rules/no-global-assign.js +4 -4
- package/lib/rules/no-implicit-coercion.js +10 -10
- package/lib/rules/no-implicit-globals.js +90 -8
- package/lib/rules/no-implied-eval.js +0 -1
- package/lib/rules/no-inline-comments.js +25 -11
- package/lib/rules/no-invalid-this.js +17 -5
- package/lib/rules/no-labels.js +3 -6
- package/lib/rules/no-lone-blocks.js +1 -1
- package/lib/rules/no-loop-func.js +6 -11
- package/lib/rules/no-magic-numbers.js +6 -6
- package/lib/rules/no-misleading-character-class.js +14 -7
- package/lib/rules/no-mixed-operators.js +13 -22
- package/lib/rules/no-mixed-requires.js +0 -1
- package/lib/rules/no-multi-spaces.js +1 -1
- package/lib/rules/no-native-reassign.js +4 -4
- package/lib/rules/no-octal-escape.js +1 -1
- package/lib/rules/no-param-reassign.js +28 -7
- package/lib/rules/no-redeclare.js +1 -1
- package/lib/rules/no-regex-spaces.js +0 -1
- package/lib/rules/no-restricted-imports.js +11 -11
- package/lib/rules/no-self-assign.js +12 -13
- package/lib/rules/no-sequences.js +3 -3
- package/lib/rules/no-setter-return.js +227 -0
- package/lib/rules/no-shadow.js +1 -4
- package/lib/rules/no-tabs.js +8 -2
- package/lib/rules/no-this-before-super.js +12 -13
- package/lib/rules/no-trailing-spaces.js +19 -7
- package/lib/rules/no-underscore-dangle.js +23 -4
- package/lib/rules/no-unmodified-loop-condition.js +16 -29
- package/lib/rules/no-unneeded-ternary.js +3 -3
- package/lib/rules/no-unreachable.js +7 -7
- package/lib/rules/no-unsafe-finally.js +4 -7
- package/lib/rules/no-unsafe-negation.js +32 -9
- package/lib/rules/no-unused-expressions.js +11 -7
- package/lib/rules/no-unused-labels.js +3 -6
- package/lib/rules/no-unused-vars.js +22 -29
- package/lib/rules/no-use-before-define.js +10 -15
- package/lib/rules/no-useless-call.js +4 -4
- package/lib/rules/no-useless-computed-key.js +60 -33
- package/lib/rules/no-useless-concat.js +4 -4
- package/lib/rules/no-useless-constructor.js +14 -22
- package/lib/rules/no-useless-escape.js +29 -8
- package/lib/rules/no-useless-rename.js +15 -7
- package/lib/rules/no-useless-return.js +8 -15
- package/lib/rules/no-var.js +12 -25
- package/lib/rules/no-warning-comments.js +0 -1
- package/lib/rules/no-whitespace-before-property.js +3 -3
- package/lib/rules/object-curly-newline.js +7 -10
- package/lib/rules/object-curly-spacing.js +21 -22
- package/lib/rules/object-shorthand.js +1 -1
- package/lib/rules/one-var-declaration-per-line.js +2 -2
- package/lib/rules/operator-assignment.js +33 -3
- package/lib/rules/padded-blocks.js +1 -1
- package/lib/rules/padding-line-between-statements.js +0 -16
- package/lib/rules/prefer-arrow-callback.js +6 -6
- package/lib/rules/prefer-const.js +27 -28
- package/lib/rules/prefer-destructuring.js +1 -7
- package/lib/rules/prefer-exponentiation-operator.js +189 -0
- package/lib/rules/prefer-named-capture-group.js +0 -1
- package/lib/rules/prefer-numeric-literals.js +32 -4
- package/lib/rules/prefer-object-spread.js +7 -7
- package/lib/rules/prefer-rest-params.js +3 -6
- package/lib/rules/prefer-spread.js +4 -4
- package/lib/rules/prefer-template.js +5 -6
- package/lib/rules/quote-props.js +1 -1
- package/lib/rules/quotes.js +5 -6
- package/lib/rules/radix.js +5 -10
- package/lib/rules/require-await.js +10 -5
- package/lib/rules/require-yield.js +2 -2
- package/lib/rules/rest-spread-spacing.js +1 -1
- package/lib/rules/semi.js +6 -3
- package/lib/rules/sort-imports.js +3 -4
- package/lib/rules/sort-keys.js +1 -3
- package/lib/rules/space-before-blocks.js +1 -2
- package/lib/rules/space-in-parens.js +4 -4
- package/lib/rules/space-infix-ops.js +6 -6
- package/lib/rules/spaced-comment.js +20 -22
- package/lib/rules/strict.js +2 -4
- package/lib/rules/symbol-description.js +1 -2
- package/lib/rules/template-curly-spacing.js +2 -2
- package/lib/rules/use-isnan.js +40 -3
- package/lib/rules/utils/ast-utils.js +84 -85
- package/lib/rules/utils/fix-tracker.js +0 -6
- package/lib/rules/utils/lazy-loading-rule-map.js +0 -1
- package/lib/rules/vars-on-top.js +11 -11
- package/lib/shared/config-ops.js +2 -2
- package/lib/shared/runtime-info.js +8 -8
- package/lib/shared/traverser.js +2 -0
- package/lib/shared/types.js +9 -0
- package/lib/source-code/source-code.js +62 -17
- package/lib/source-code/token-store/backward-token-comment-cursor.js +5 -5
- package/lib/source-code/token-store/backward-token-cursor.js +5 -5
- package/lib/source-code/token-store/cursors.js +17 -19
- package/lib/source-code/token-store/decorative-cursor.js +1 -1
- package/lib/source-code/token-store/filter-cursor.js +2 -2
- package/lib/source-code/token-store/forward-token-comment-cursor.js +5 -5
- package/lib/source-code/token-store/forward-token-cursor.js +5 -5
- package/lib/source-code/token-store/index.js +86 -92
- package/lib/source-code/token-store/limit-cursor.js +2 -2
- package/lib/source-code/token-store/padded-token-cursor.js +7 -7
- package/lib/source-code/token-store/skip-cursor.js +2 -2
- package/lib/source-code/token-store/utils.js +9 -13
- package/package.json +9 -7
- package/lib/cli-engine/ignored-paths.js +0 -362
@@ -1,362 +0,0 @@
|
|
1
|
-
/**
|
2
|
-
* @fileoverview Responsible for loading ignore config files and managing ignore patterns
|
3
|
-
* @author Jonathan Rajavuori
|
4
|
-
*/
|
5
|
-
|
6
|
-
"use strict";
|
7
|
-
|
8
|
-
//------------------------------------------------------------------------------
|
9
|
-
// Requirements
|
10
|
-
//------------------------------------------------------------------------------
|
11
|
-
|
12
|
-
const fs = require("fs"),
|
13
|
-
path = require("path"),
|
14
|
-
ignore = require("ignore");
|
15
|
-
|
16
|
-
const debug = require("debug")("eslint:ignored-paths");
|
17
|
-
|
18
|
-
//------------------------------------------------------------------------------
|
19
|
-
// Constants
|
20
|
-
//------------------------------------------------------------------------------
|
21
|
-
|
22
|
-
const ESLINT_IGNORE_FILENAME = ".eslintignore";
|
23
|
-
|
24
|
-
/**
|
25
|
-
* Adds `"*"` at the end of `"node_modules/"`,
|
26
|
-
* so that subtle directories could be re-included by .gitignore patterns
|
27
|
-
* such as `"!node_modules/should_not_ignored"`
|
28
|
-
*/
|
29
|
-
const DEFAULT_IGNORE_DIRS = [
|
30
|
-
"/node_modules/*",
|
31
|
-
"/bower_components/*"
|
32
|
-
];
|
33
|
-
const DEFAULT_OPTIONS = {
|
34
|
-
dotfiles: false,
|
35
|
-
cwd: process.cwd()
|
36
|
-
};
|
37
|
-
|
38
|
-
//------------------------------------------------------------------------------
|
39
|
-
// Helpers
|
40
|
-
//------------------------------------------------------------------------------
|
41
|
-
|
42
|
-
/**
|
43
|
-
* Find a file in the current directory.
|
44
|
-
* @param {string} cwd Current working directory
|
45
|
-
* @param {string} name File name
|
46
|
-
* @returns {string} Path of ignore file or an empty string.
|
47
|
-
*/
|
48
|
-
function findFile(cwd, name) {
|
49
|
-
const ignoreFilePath = path.resolve(cwd, name);
|
50
|
-
|
51
|
-
return fs.existsSync(ignoreFilePath) && fs.statSync(ignoreFilePath).isFile() ? ignoreFilePath : "";
|
52
|
-
}
|
53
|
-
|
54
|
-
/**
|
55
|
-
* Find an ignore file in the current directory.
|
56
|
-
* @param {string} cwd Current working directory
|
57
|
-
* @returns {string} Path of ignore file or an empty string.
|
58
|
-
*/
|
59
|
-
function findIgnoreFile(cwd) {
|
60
|
-
return findFile(cwd, ESLINT_IGNORE_FILENAME);
|
61
|
-
}
|
62
|
-
|
63
|
-
/**
|
64
|
-
* Find an package.json file in the current directory.
|
65
|
-
* @param {string} cwd Current working directory
|
66
|
-
* @returns {string} Path of package.json file or an empty string.
|
67
|
-
*/
|
68
|
-
function findPackageJSONFile(cwd) {
|
69
|
-
return findFile(cwd, "package.json");
|
70
|
-
}
|
71
|
-
|
72
|
-
/**
|
73
|
-
* Merge options with defaults
|
74
|
-
* @param {Object} options Options to merge with DEFAULT_OPTIONS constant
|
75
|
-
* @returns {Object} Merged options
|
76
|
-
*/
|
77
|
-
function mergeDefaultOptions(options) {
|
78
|
-
return Object.assign({}, DEFAULT_OPTIONS, options);
|
79
|
-
}
|
80
|
-
|
81
|
-
/* eslint-disable jsdoc/check-param-names, jsdoc/require-param */
|
82
|
-
/**
|
83
|
-
* Normalize the path separators in a given string.
|
84
|
-
* On Windows environment, this replaces `\` by `/`.
|
85
|
-
* Otherwrise, this does nothing.
|
86
|
-
* @param {string} str The path string to normalize.
|
87
|
-
* @returns {string} The normalized path.
|
88
|
-
*/
|
89
|
-
const normalizePathSeps = path.sep === "/"
|
90
|
-
? (str => str)
|
91
|
-
: ((seps, str) => str.replace(seps, "/")).bind(null, new RegExp(`\\${path.sep}`, "gu"));
|
92
|
-
/* eslint-enable jsdoc/check-param-names, jsdoc/require-param */
|
93
|
-
|
94
|
-
/**
|
95
|
-
* Converts a glob pattern to a new glob pattern relative to a different directory
|
96
|
-
* @param {string} globPattern The glob pattern, relative the the old base directory
|
97
|
-
* @param {string} relativePathToOldBaseDir A relative path from the new base directory to the old one
|
98
|
-
* @returns {string} A glob pattern relative to the new base directory
|
99
|
-
*/
|
100
|
-
function relativize(globPattern, relativePathToOldBaseDir) {
|
101
|
-
if (relativePathToOldBaseDir === "") {
|
102
|
-
return globPattern;
|
103
|
-
}
|
104
|
-
|
105
|
-
const prefix = globPattern.startsWith("!") ? "!" : "";
|
106
|
-
const globWithoutPrefix = globPattern.replace(/^!/u, "");
|
107
|
-
|
108
|
-
if (globWithoutPrefix.startsWith("/")) {
|
109
|
-
return `${prefix}/${normalizePathSeps(relativePathToOldBaseDir)}${globWithoutPrefix}`;
|
110
|
-
}
|
111
|
-
|
112
|
-
return globPattern;
|
113
|
-
}
|
114
|
-
|
115
|
-
//------------------------------------------------------------------------------
|
116
|
-
// Public Interface
|
117
|
-
//------------------------------------------------------------------------------
|
118
|
-
|
119
|
-
/**
|
120
|
-
* IgnoredPaths class
|
121
|
-
*/
|
122
|
-
class IgnoredPaths {
|
123
|
-
|
124
|
-
/**
|
125
|
-
* @param {Object} providedOptions object containing 'ignore', 'ignorePath' and 'patterns' properties
|
126
|
-
*/
|
127
|
-
constructor(providedOptions) {
|
128
|
-
const options = mergeDefaultOptions(providedOptions);
|
129
|
-
|
130
|
-
this.cache = {};
|
131
|
-
|
132
|
-
this.defaultPatterns = [].concat(DEFAULT_IGNORE_DIRS, options.patterns || []);
|
133
|
-
|
134
|
-
this.ignoreFileDir = options.ignore !== false && options.ignorePath
|
135
|
-
? path.dirname(path.resolve(options.cwd, options.ignorePath))
|
136
|
-
: options.cwd;
|
137
|
-
this.options = options;
|
138
|
-
this._baseDir = null;
|
139
|
-
|
140
|
-
this.ig = {
|
141
|
-
custom: ignore(),
|
142
|
-
default: ignore()
|
143
|
-
};
|
144
|
-
|
145
|
-
this.defaultPatterns.forEach(pattern => this.addPatternRelativeToCwd(this.ig.default, pattern));
|
146
|
-
if (options.dotfiles !== true) {
|
147
|
-
|
148
|
-
/*
|
149
|
-
* ignore files beginning with a dot, but not files in a parent or
|
150
|
-
* ancestor directory (which in relative format will begin with `../`).
|
151
|
-
*/
|
152
|
-
this.addPatternRelativeToCwd(this.ig.default, ".*");
|
153
|
-
this.addPatternRelativeToCwd(this.ig.default, "!../");
|
154
|
-
}
|
155
|
-
|
156
|
-
/*
|
157
|
-
* Add a way to keep track of ignored files. This was present in node-ignore
|
158
|
-
* 2.x, but dropped for now as of 3.0.10.
|
159
|
-
*/
|
160
|
-
this.ig.custom.ignoreFiles = [];
|
161
|
-
this.ig.default.ignoreFiles = [];
|
162
|
-
|
163
|
-
if (options.ignore !== false) {
|
164
|
-
let ignorePath;
|
165
|
-
|
166
|
-
if (options.ignorePath) {
|
167
|
-
debug("Using specific ignore file");
|
168
|
-
|
169
|
-
try {
|
170
|
-
const stat = fs.statSync(options.ignorePath);
|
171
|
-
|
172
|
-
if (!stat.isFile()) {
|
173
|
-
throw new Error(`${options.ignorePath} is not a file`);
|
174
|
-
}
|
175
|
-
ignorePath = options.ignorePath;
|
176
|
-
} catch (e) {
|
177
|
-
e.message = `Cannot read ignore file: ${options.ignorePath}\nError: ${e.message}`;
|
178
|
-
throw e;
|
179
|
-
}
|
180
|
-
} else {
|
181
|
-
debug(`Looking for ignore file in ${options.cwd}`);
|
182
|
-
ignorePath = findIgnoreFile(options.cwd);
|
183
|
-
|
184
|
-
try {
|
185
|
-
fs.statSync(ignorePath);
|
186
|
-
debug(`Loaded ignore file ${ignorePath}`);
|
187
|
-
} catch (e) {
|
188
|
-
debug("Could not find ignore file in cwd");
|
189
|
-
}
|
190
|
-
}
|
191
|
-
|
192
|
-
if (ignorePath) {
|
193
|
-
debug(`Adding ${ignorePath}`);
|
194
|
-
this.addIgnoreFile(this.ig.custom, ignorePath);
|
195
|
-
this.addIgnoreFile(this.ig.default, ignorePath);
|
196
|
-
} else {
|
197
|
-
try {
|
198
|
-
|
199
|
-
// if the ignoreFile does not exist, check package.json for eslintIgnore
|
200
|
-
const packageJSONPath = findPackageJSONFile(options.cwd);
|
201
|
-
|
202
|
-
if (packageJSONPath) {
|
203
|
-
let packageJSONOptions;
|
204
|
-
|
205
|
-
try {
|
206
|
-
packageJSONOptions = JSON.parse(fs.readFileSync(packageJSONPath, "utf8"));
|
207
|
-
} catch (e) {
|
208
|
-
debug("Could not read package.json file to check eslintIgnore property");
|
209
|
-
e.messageTemplate = "failed-to-read-json";
|
210
|
-
e.messageData = {
|
211
|
-
path: packageJSONPath,
|
212
|
-
message: e.message
|
213
|
-
};
|
214
|
-
throw e;
|
215
|
-
}
|
216
|
-
|
217
|
-
if (packageJSONOptions.eslintIgnore) {
|
218
|
-
if (Array.isArray(packageJSONOptions.eslintIgnore)) {
|
219
|
-
packageJSONOptions.eslintIgnore.forEach(pattern => {
|
220
|
-
this.addPatternRelativeToIgnoreFile(this.ig.custom, pattern);
|
221
|
-
this.addPatternRelativeToIgnoreFile(this.ig.default, pattern);
|
222
|
-
});
|
223
|
-
} else {
|
224
|
-
throw new TypeError("Package.json eslintIgnore property requires an array of paths");
|
225
|
-
}
|
226
|
-
}
|
227
|
-
}
|
228
|
-
} catch (e) {
|
229
|
-
debug("Could not find package.json to check eslintIgnore property");
|
230
|
-
throw e;
|
231
|
-
}
|
232
|
-
}
|
233
|
-
|
234
|
-
if (options.ignorePattern) {
|
235
|
-
this.addPatternRelativeToCwd(this.ig.custom, options.ignorePattern);
|
236
|
-
this.addPatternRelativeToCwd(this.ig.default, options.ignorePattern);
|
237
|
-
}
|
238
|
-
}
|
239
|
-
}
|
240
|
-
|
241
|
-
/*
|
242
|
-
* If `ignoreFileDir` is a subdirectory of `cwd`, all paths will be normalized to be relative to `cwd`.
|
243
|
-
* Otherwise, all paths will be normalized to be relative to `ignoreFileDir`.
|
244
|
-
* This ensures that the final normalized ignore rule will not contain `..`, which is forbidden in
|
245
|
-
* ignore rules.
|
246
|
-
*/
|
247
|
-
|
248
|
-
addPatternRelativeToCwd(ig, pattern) {
|
249
|
-
const baseDir = this.getBaseDir();
|
250
|
-
const cookedPattern = baseDir === this.options.cwd
|
251
|
-
? pattern
|
252
|
-
: relativize(pattern, path.relative(baseDir, this.options.cwd));
|
253
|
-
|
254
|
-
ig.addPattern(cookedPattern);
|
255
|
-
debug("addPatternRelativeToCwd:\n original = %j\n cooked = %j", pattern, cookedPattern);
|
256
|
-
}
|
257
|
-
|
258
|
-
addPatternRelativeToIgnoreFile(ig, pattern) {
|
259
|
-
const baseDir = this.getBaseDir();
|
260
|
-
const cookedPattern = baseDir === this.ignoreFileDir
|
261
|
-
? pattern
|
262
|
-
: relativize(pattern, path.relative(baseDir, this.ignoreFileDir));
|
263
|
-
|
264
|
-
ig.addPattern(cookedPattern);
|
265
|
-
debug("addPatternRelativeToIgnoreFile:\n original = %j\n cooked = %j", pattern, cookedPattern);
|
266
|
-
}
|
267
|
-
|
268
|
-
// Detect the common ancestor
|
269
|
-
getBaseDir() {
|
270
|
-
if (!this._baseDir) {
|
271
|
-
const a = path.resolve(this.options.cwd);
|
272
|
-
const b = path.resolve(this.ignoreFileDir);
|
273
|
-
let lastSepPos = 0;
|
274
|
-
|
275
|
-
// Set the shorter one (it's the common ancestor if one includes the other).
|
276
|
-
this._baseDir = a.length < b.length ? a : b;
|
277
|
-
|
278
|
-
// Set the common ancestor.
|
279
|
-
for (let i = 0; i < a.length && i < b.length; ++i) {
|
280
|
-
if (a[i] !== b[i]) {
|
281
|
-
this._baseDir = a.slice(0, lastSepPos);
|
282
|
-
break;
|
283
|
-
}
|
284
|
-
if (a[i] === path.sep) {
|
285
|
-
lastSepPos = i;
|
286
|
-
}
|
287
|
-
}
|
288
|
-
|
289
|
-
// If it's only Windows drive letter, it needs \
|
290
|
-
if (/^[A-Z]:$/u.test(this._baseDir)) {
|
291
|
-
this._baseDir += "\\";
|
292
|
-
}
|
293
|
-
|
294
|
-
debug("baseDir = %j", this._baseDir);
|
295
|
-
}
|
296
|
-
return this._baseDir;
|
297
|
-
}
|
298
|
-
|
299
|
-
/**
|
300
|
-
* read ignore filepath
|
301
|
-
* @param {string} filePath file to add to ig
|
302
|
-
* @returns {Array} raw ignore rules
|
303
|
-
*/
|
304
|
-
readIgnoreFile(filePath) {
|
305
|
-
if (typeof this.cache[filePath] === "undefined") {
|
306
|
-
this.cache[filePath] = fs.readFileSync(filePath, "utf8").split(/\r?\n/gu).filter(Boolean);
|
307
|
-
}
|
308
|
-
return this.cache[filePath];
|
309
|
-
}
|
310
|
-
|
311
|
-
/**
|
312
|
-
* add ignore file to node-ignore instance
|
313
|
-
* @param {Object} ig instance of node-ignore
|
314
|
-
* @param {string} filePath file to add to ig
|
315
|
-
* @returns {void}
|
316
|
-
*/
|
317
|
-
addIgnoreFile(ig, filePath) {
|
318
|
-
ig.ignoreFiles.push(filePath);
|
319
|
-
this
|
320
|
-
.readIgnoreFile(filePath)
|
321
|
-
.forEach(ignoreRule => this.addPatternRelativeToIgnoreFile(ig, ignoreRule));
|
322
|
-
}
|
323
|
-
|
324
|
-
/**
|
325
|
-
* Determine whether a file path is included in the default or custom ignore patterns
|
326
|
-
* @param {string} filepath Path to check
|
327
|
-
* @param {string} [category=undefined] check 'default', 'custom' or both (undefined)
|
328
|
-
* @returns {boolean} true if the file path matches one or more patterns, false otherwise
|
329
|
-
*/
|
330
|
-
contains(filepath, category) {
|
331
|
-
const isDir = filepath.endsWith(path.sep) ||
|
332
|
-
(path.sep === "\\" && filepath.endsWith("/"));
|
333
|
-
let result = false;
|
334
|
-
const basePath = this.getBaseDir();
|
335
|
-
const absolutePath = path.resolve(this.options.cwd, filepath);
|
336
|
-
let relativePath = path.relative(basePath, absolutePath);
|
337
|
-
|
338
|
-
if (relativePath) {
|
339
|
-
if (isDir) {
|
340
|
-
relativePath += path.sep;
|
341
|
-
}
|
342
|
-
if (typeof category === "undefined") {
|
343
|
-
result =
|
344
|
-
(this.ig.default.filter([relativePath]).length === 0) ||
|
345
|
-
(this.ig.custom.filter([relativePath]).length === 0);
|
346
|
-
} else {
|
347
|
-
result =
|
348
|
-
(this.ig[category].filter([relativePath]).length === 0);
|
349
|
-
}
|
350
|
-
}
|
351
|
-
debug("contains:");
|
352
|
-
debug(" target = %j", filepath);
|
353
|
-
debug(" base = %j", basePath);
|
354
|
-
debug(" relative = %j", relativePath);
|
355
|
-
debug(" result = %j", result);
|
356
|
-
|
357
|
-
return result;
|
358
|
-
|
359
|
-
}
|
360
|
-
}
|
361
|
-
|
362
|
-
module.exports = { IgnoredPaths };
|