editorconfig 0.15.2 → 1.0.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/README.md +102 -53
- package/bin/editorconfig +5 -2
- package/lib/cli.d.ts +14 -0
- package/lib/cli.js +109 -0
- package/lib/index.d.ts +105 -0
- package/lib/index.js +458 -0
- package/package.json +66 -59
- package/CHANGELOG.md +0 -10
- package/src/cli.d.ts +0 -1
- package/src/cli.js +0 -53
- package/src/index.d.ts +0 -29
- package/src/index.js +0 -261
- package/src/lib/fnmatch.d.ts +0 -214
- package/src/lib/fnmatch.js +0 -1047
- package/src/lib/ini.d.ts +0 -14
- package/src/lib/ini.js +0 -106
package/lib/index.js
ADDED
|
@@ -0,0 +1,458 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
26
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
|
+
};
|
|
28
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
+
exports.parseSync = exports.parse = exports.parseFromFilesSync = exports.parseFromFiles = exports.parseString = exports.parseBuffer = void 0;
|
|
30
|
+
const fs = __importStar(require("fs"));
|
|
31
|
+
const path = __importStar(require("path"));
|
|
32
|
+
const semver = __importStar(require("semver"));
|
|
33
|
+
const minimatch_1 = __importDefault(require("minimatch"));
|
|
34
|
+
const wasm_1 = require("@one-ini/wasm");
|
|
35
|
+
// @ts-ignore So we can set the rootDir to be 'lib', without processing
|
|
36
|
+
// package.json
|
|
37
|
+
const package_json_1 = __importDefault(require("../package.json"));
|
|
38
|
+
const escapedSep = new RegExp(path.sep.replace(/\\/g, '\\\\'), 'g');
|
|
39
|
+
const matchOptions = { matchBase: true, dot: true, noext: true };
|
|
40
|
+
// These are specified by the editorconfig script
|
|
41
|
+
/* eslint-disable @typescript-eslint/naming-convention */
|
|
42
|
+
const knownProps = {
|
|
43
|
+
end_of_line: true,
|
|
44
|
+
indent_style: true,
|
|
45
|
+
indent_size: true,
|
|
46
|
+
insert_final_newline: true,
|
|
47
|
+
trim_trailing_whitespace: true,
|
|
48
|
+
charset: true,
|
|
49
|
+
};
|
|
50
|
+
/**
|
|
51
|
+
* Parse a buffer using the faster one-ini WASM approach into something
|
|
52
|
+
* relatively easy to deal with in JS.
|
|
53
|
+
*
|
|
54
|
+
* @param data UTF8-encoded bytes.
|
|
55
|
+
* @returns Parsed contents. Will be truncated if there was a parse error.
|
|
56
|
+
*/
|
|
57
|
+
function parseBuffer(data) {
|
|
58
|
+
const parsed = (0, wasm_1.parse_to_uint32array)(data);
|
|
59
|
+
let cur = {};
|
|
60
|
+
const res = [[null, cur]];
|
|
61
|
+
let key = null;
|
|
62
|
+
for (let i = 0; i < parsed.length; i += 3) {
|
|
63
|
+
switch (parsed[i]) {
|
|
64
|
+
case wasm_1.TokenTypes.Section: {
|
|
65
|
+
cur = {};
|
|
66
|
+
res.push([
|
|
67
|
+
data.toString('utf8', parsed[i + 1], parsed[i + 2]),
|
|
68
|
+
cur,
|
|
69
|
+
]);
|
|
70
|
+
break;
|
|
71
|
+
}
|
|
72
|
+
case wasm_1.TokenTypes.Key:
|
|
73
|
+
key = data.toString('utf8', parsed[i + 1], parsed[i + 2]);
|
|
74
|
+
break;
|
|
75
|
+
case wasm_1.TokenTypes.Value: {
|
|
76
|
+
cur[key] = data.toString('utf8', parsed[i + 1], parsed[i + 2]);
|
|
77
|
+
break;
|
|
78
|
+
}
|
|
79
|
+
default: // Comments, etc.
|
|
80
|
+
break;
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
return res;
|
|
84
|
+
}
|
|
85
|
+
exports.parseBuffer = parseBuffer;
|
|
86
|
+
/**
|
|
87
|
+
* Parses a string. If possible, you should always use ParseBuffer instead,
|
|
88
|
+
* since this function does a UTF16-to-UTF8 conversion first.
|
|
89
|
+
*
|
|
90
|
+
* @param data String to parse.
|
|
91
|
+
* @returns Parsed contents. Will be truncated if there was a parse error.
|
|
92
|
+
* @deprecated Use {@link ParseBuffer} instead.
|
|
93
|
+
*/
|
|
94
|
+
function parseString(data) {
|
|
95
|
+
return parseBuffer(Buffer.from(data));
|
|
96
|
+
}
|
|
97
|
+
exports.parseString = parseString;
|
|
98
|
+
/**
|
|
99
|
+
* Gets a list of *potential* filenames based on the path of the target
|
|
100
|
+
* filename.
|
|
101
|
+
*
|
|
102
|
+
* @param filepath File we are asking about.
|
|
103
|
+
* @param options Config file name and root directory
|
|
104
|
+
* @returns List of potential fully-qualified filenames that might have configs.
|
|
105
|
+
*/
|
|
106
|
+
function getConfigFileNames(filepath, options) {
|
|
107
|
+
const paths = [];
|
|
108
|
+
do {
|
|
109
|
+
filepath = path.dirname(filepath);
|
|
110
|
+
paths.push(path.join(filepath, options.config));
|
|
111
|
+
} while (filepath !== options.root);
|
|
112
|
+
return paths;
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* Take a combined config for the target file, and tweak it slightly based on
|
|
116
|
+
* which editorconfig version's rules we are using.
|
|
117
|
+
*
|
|
118
|
+
* @param matches Combined config.
|
|
119
|
+
* @param version Editorconfig version to enforce.
|
|
120
|
+
* @returns The passed-in matches object, modified in place.
|
|
121
|
+
*/
|
|
122
|
+
function processMatches(matches, version) {
|
|
123
|
+
// Set indent_size to 'tab' if indent_size is unspecified and
|
|
124
|
+
// indent_style is set to 'tab'.
|
|
125
|
+
if ('indent_style' in matches
|
|
126
|
+
&& matches.indent_style === 'tab'
|
|
127
|
+
&& !('indent_size' in matches)
|
|
128
|
+
&& semver.gte(version, '0.10.0')) {
|
|
129
|
+
matches.indent_size = 'tab';
|
|
130
|
+
}
|
|
131
|
+
// Set tab_width to indent_size if indent_size is specified and
|
|
132
|
+
// tab_width is unspecified
|
|
133
|
+
if ('indent_size' in matches
|
|
134
|
+
&& !('tab_width' in matches)
|
|
135
|
+
&& matches.indent_size !== 'tab') {
|
|
136
|
+
matches.tab_width = matches.indent_size;
|
|
137
|
+
}
|
|
138
|
+
// Set indent_size to tab_width if indent_size is 'tab'
|
|
139
|
+
if ('indent_size' in matches
|
|
140
|
+
&& 'tab_width' in matches
|
|
141
|
+
&& matches.indent_size === 'tab') {
|
|
142
|
+
matches.indent_size = matches.tab_width;
|
|
143
|
+
}
|
|
144
|
+
return matches;
|
|
145
|
+
}
|
|
146
|
+
function buildFullGlob(pathPrefix, glob) {
|
|
147
|
+
switch (glob.indexOf('/')) {
|
|
148
|
+
case -1:
|
|
149
|
+
glob = '**/' + glob;
|
|
150
|
+
break;
|
|
151
|
+
case 0:
|
|
152
|
+
glob = glob.substring(1);
|
|
153
|
+
break;
|
|
154
|
+
default:
|
|
155
|
+
break;
|
|
156
|
+
}
|
|
157
|
+
// braces_escaped_backslash2
|
|
158
|
+
// backslash_not_on_windows
|
|
159
|
+
glob = glob.replace(/\\\\/g, '\\\\\\\\');
|
|
160
|
+
// star_star_over_separator{1,3,5,6,9,15}
|
|
161
|
+
glob = glob.replace(/\*\*/g, '{*,**/**/**}');
|
|
162
|
+
// NOT path.join. Must stay in forward slashes.
|
|
163
|
+
return new minimatch_1.default.Minimatch(`${pathPrefix}/${glob}`, matchOptions);
|
|
164
|
+
}
|
|
165
|
+
/**
|
|
166
|
+
* Normalize the properties read from a config file so that their key names
|
|
167
|
+
* are lowercased for the known properties, and their values are parsed into
|
|
168
|
+
* the correct JS types if possible.
|
|
169
|
+
*
|
|
170
|
+
* @param options
|
|
171
|
+
* @returns
|
|
172
|
+
*/
|
|
173
|
+
function normalizeProps(options) {
|
|
174
|
+
const props = {};
|
|
175
|
+
for (const key in options) {
|
|
176
|
+
if (options.hasOwnProperty(key)) {
|
|
177
|
+
const value = options[key];
|
|
178
|
+
const key2 = key.toLowerCase();
|
|
179
|
+
let value2 = value;
|
|
180
|
+
if (knownProps[key2]) {
|
|
181
|
+
// All of the values for the known props are lowercase.
|
|
182
|
+
value2 = String(value).toLowerCase();
|
|
183
|
+
}
|
|
184
|
+
try {
|
|
185
|
+
value2 = JSON.parse(String(value));
|
|
186
|
+
}
|
|
187
|
+
catch (e) { }
|
|
188
|
+
if (typeof value2 === 'undefined' || value2 === null) {
|
|
189
|
+
// null and undefined are values specific to JSON (no special meaning
|
|
190
|
+
// in editorconfig) & should just be returned as regular strings.
|
|
191
|
+
value2 = String(value);
|
|
192
|
+
}
|
|
193
|
+
props[key2] = value2;
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
return props;
|
|
197
|
+
}
|
|
198
|
+
/**
|
|
199
|
+
* Take the contents of a config file, and prepare it for use. If a cache is
|
|
200
|
+
* provided, the result will be stored there. As such, all of the higher-CPU
|
|
201
|
+
* work that is per-file should be done here.
|
|
202
|
+
*
|
|
203
|
+
* @param filepath The fully-qualified path of the file.
|
|
204
|
+
* @param contents The contents as read from that file.
|
|
205
|
+
* @param options Access to the cache.
|
|
206
|
+
* @returns Processed file with globs pre-computed.
|
|
207
|
+
*/
|
|
208
|
+
function processFileContents(filepath, contents, options) {
|
|
209
|
+
let res;
|
|
210
|
+
if (!contents) {
|
|
211
|
+
// Negative cache
|
|
212
|
+
res = {
|
|
213
|
+
root: false,
|
|
214
|
+
notfound: true,
|
|
215
|
+
name: filepath,
|
|
216
|
+
config: [[null, {}, null]],
|
|
217
|
+
};
|
|
218
|
+
}
|
|
219
|
+
else {
|
|
220
|
+
let pathPrefix = path.dirname(filepath);
|
|
221
|
+
if (path.sep !== '/') {
|
|
222
|
+
// Windows-only
|
|
223
|
+
pathPrefix = pathPrefix.replace(escapedSep, '/');
|
|
224
|
+
}
|
|
225
|
+
// After Windows path backslash's are turned into slashes, so that
|
|
226
|
+
// the backslashes we add here aren't turned into forward slashes:
|
|
227
|
+
// All of these characters are special to minimatch, but can be
|
|
228
|
+
// forced into path names on many file systems. Escape them. Note
|
|
229
|
+
// that these are in the order of the case statement in minimatch.
|
|
230
|
+
pathPrefix = pathPrefix.replace(/[?*+@!()|[\]{}]/g, '\\$&');
|
|
231
|
+
// I can't think of a way for this to happen in the filesystems I've
|
|
232
|
+
// seen (because of the path.dirname above), but let's be thorough.
|
|
233
|
+
pathPrefix = pathPrefix.replace(/^#/, '\\#');
|
|
234
|
+
const globbed = parseBuffer(contents).map(([name, body]) => [
|
|
235
|
+
name,
|
|
236
|
+
normalizeProps(body),
|
|
237
|
+
name ? buildFullGlob(pathPrefix, name) : null,
|
|
238
|
+
]);
|
|
239
|
+
res = {
|
|
240
|
+
root: !!globbed[0][1].root,
|
|
241
|
+
name: filepath,
|
|
242
|
+
config: globbed,
|
|
243
|
+
};
|
|
244
|
+
}
|
|
245
|
+
if (options.cache) {
|
|
246
|
+
options.cache.set(filepath, res);
|
|
247
|
+
}
|
|
248
|
+
return res;
|
|
249
|
+
}
|
|
250
|
+
/**
|
|
251
|
+
* Get a file from the cache, or read its contents from disk, process, and
|
|
252
|
+
* insert into the cache (if configured).
|
|
253
|
+
*
|
|
254
|
+
* @param filepath The fully-qualified path of the config file.
|
|
255
|
+
* @param options Access to the cache, if configured.
|
|
256
|
+
* @returns The processed file, or undefined if there was an error reading it.
|
|
257
|
+
*/
|
|
258
|
+
async function getConfig(filepath, options) {
|
|
259
|
+
if (options.cache) {
|
|
260
|
+
const cached = options.cache.get(filepath);
|
|
261
|
+
if (cached) {
|
|
262
|
+
return cached;
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
const contents = await new Promise(resolve => {
|
|
266
|
+
fs.readFile(filepath, (_, buf) => {
|
|
267
|
+
// Ignore errors. contents will be undefined
|
|
268
|
+
// Perhaps only file-not-found should be ignored?
|
|
269
|
+
resolve(buf);
|
|
270
|
+
});
|
|
271
|
+
});
|
|
272
|
+
return processFileContents(filepath, contents, options);
|
|
273
|
+
}
|
|
274
|
+
/**
|
|
275
|
+
* Get a file from the cache, or read its contents from disk, process, and
|
|
276
|
+
* insert into the cache (if configured). Synchronous.
|
|
277
|
+
*
|
|
278
|
+
* @param filepath The fully-qualified path of the config file.
|
|
279
|
+
* @param options Access to the cache, if configured.
|
|
280
|
+
* @returns The processed file, or undefined if there was an error reading it.
|
|
281
|
+
*/
|
|
282
|
+
function getConfigSync(filepath, options) {
|
|
283
|
+
if (options.cache) {
|
|
284
|
+
const cached = options.cache.get(filepath);
|
|
285
|
+
if (cached) {
|
|
286
|
+
return cached;
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
let contents;
|
|
290
|
+
try {
|
|
291
|
+
contents = fs.readFileSync(filepath);
|
|
292
|
+
}
|
|
293
|
+
catch (_) {
|
|
294
|
+
// Ignore errors
|
|
295
|
+
// Perhaps only file-not-found should be ignored
|
|
296
|
+
}
|
|
297
|
+
return processFileContents(filepath, contents, options);
|
|
298
|
+
}
|
|
299
|
+
/**
|
|
300
|
+
* Get all of the possibly-existing config files, stopping when one is marked
|
|
301
|
+
* root=true.
|
|
302
|
+
*
|
|
303
|
+
* @param files List of potential files
|
|
304
|
+
* @param options Access to cache if configured
|
|
305
|
+
* @returns List of processed configs for existing files
|
|
306
|
+
*/
|
|
307
|
+
async function getAllConfigs(files, options) {
|
|
308
|
+
const configs = [];
|
|
309
|
+
for (const file of files) {
|
|
310
|
+
const config = await getConfig(file, options);
|
|
311
|
+
if (!config.notfound) {
|
|
312
|
+
configs.push(config);
|
|
313
|
+
if (config.root) {
|
|
314
|
+
break;
|
|
315
|
+
}
|
|
316
|
+
}
|
|
317
|
+
}
|
|
318
|
+
return configs;
|
|
319
|
+
}
|
|
320
|
+
/**
|
|
321
|
+
* Get all of the possibly-existing config files, stopping when one is marked
|
|
322
|
+
* root=true. Synchronous.
|
|
323
|
+
*
|
|
324
|
+
* @param files List of potential files
|
|
325
|
+
* @param options Access to cache if configured
|
|
326
|
+
* @returns List of processed configs for existing files
|
|
327
|
+
*/
|
|
328
|
+
function getAllConfigsSync(files, options) {
|
|
329
|
+
const configs = [];
|
|
330
|
+
for (const file of files) {
|
|
331
|
+
const config = getConfigSync(file, options);
|
|
332
|
+
if (!config.notfound) {
|
|
333
|
+
configs.push(config);
|
|
334
|
+
if (config.root) {
|
|
335
|
+
break;
|
|
336
|
+
}
|
|
337
|
+
}
|
|
338
|
+
}
|
|
339
|
+
return configs;
|
|
340
|
+
}
|
|
341
|
+
/**
|
|
342
|
+
* Normalize the options passed in to the publicly-visible functions.
|
|
343
|
+
*
|
|
344
|
+
* @param filepath The name of the target file, relative to process.cwd().
|
|
345
|
+
* @param options Potentially-incomplete options.
|
|
346
|
+
* @returns The fully-qualified target file name and the normalized options.
|
|
347
|
+
*/
|
|
348
|
+
function opts(filepath, options = {}) {
|
|
349
|
+
const resolvedFilePath = path.resolve(filepath);
|
|
350
|
+
return [
|
|
351
|
+
resolvedFilePath,
|
|
352
|
+
{
|
|
353
|
+
config: options.config || '.editorconfig',
|
|
354
|
+
version: options.version || package_json_1.default.version,
|
|
355
|
+
root: path.resolve(options.root || path.parse(resolvedFilePath).root),
|
|
356
|
+
files: options.files,
|
|
357
|
+
cache: options.cache,
|
|
358
|
+
},
|
|
359
|
+
];
|
|
360
|
+
}
|
|
361
|
+
/**
|
|
362
|
+
* Low-level interface, which exists only for backward-compatibility.
|
|
363
|
+
* Deprecated.
|
|
364
|
+
*
|
|
365
|
+
* @param filepath The name of the target file, relative to process.cwd().
|
|
366
|
+
* @param files A promise for a list of objects describing the files.
|
|
367
|
+
* @param options All options
|
|
368
|
+
* @returns The properties found for filepath
|
|
369
|
+
* @deprecated
|
|
370
|
+
*/
|
|
371
|
+
async function parseFromFiles(filepath, files, options = {}) {
|
|
372
|
+
return parseFromFilesSync(filepath, await files, options);
|
|
373
|
+
}
|
|
374
|
+
exports.parseFromFiles = parseFromFiles;
|
|
375
|
+
/**
|
|
376
|
+
* Low-level interface, which exists only for backward-compatibility.
|
|
377
|
+
* Deprecated.
|
|
378
|
+
*
|
|
379
|
+
* @param filepath The name of the target file, relative to process.cwd().
|
|
380
|
+
* @param files A list of objects describing the files.
|
|
381
|
+
* @param options All options
|
|
382
|
+
* @returns The properties found for filepath
|
|
383
|
+
* @deprecated
|
|
384
|
+
*/
|
|
385
|
+
function parseFromFilesSync(filepath, files, options = {}) {
|
|
386
|
+
const [resolvedFilePath, processedOptions] = opts(filepath, options);
|
|
387
|
+
const configs = [];
|
|
388
|
+
for (const ecf of files) {
|
|
389
|
+
let cfg;
|
|
390
|
+
if (!options.cache || !(cfg = options.cache.get(ecf.name))) { // Single "="!
|
|
391
|
+
cfg = processFileContents(ecf.name, ecf.contents, processedOptions);
|
|
392
|
+
}
|
|
393
|
+
if (!cfg.notfound) {
|
|
394
|
+
configs.push(cfg);
|
|
395
|
+
}
|
|
396
|
+
if (cfg.root) {
|
|
397
|
+
break;
|
|
398
|
+
}
|
|
399
|
+
}
|
|
400
|
+
return combine(resolvedFilePath, configs, processedOptions);
|
|
401
|
+
}
|
|
402
|
+
exports.parseFromFilesSync = parseFromFilesSync;
|
|
403
|
+
/**
|
|
404
|
+
* Combine the pre-parsed results of all matching config file sections, in
|
|
405
|
+
* order.
|
|
406
|
+
*
|
|
407
|
+
* @param filepath The target file path
|
|
408
|
+
* @param configs All of the found config files, up to the root
|
|
409
|
+
* @param options Adds to `options.files` if it exists
|
|
410
|
+
* @returns Combined properties
|
|
411
|
+
*/
|
|
412
|
+
function combine(filepath, configs, options) {
|
|
413
|
+
const ret = configs.reverse().reduce((props, processed) => {
|
|
414
|
+
for (const [name, body, glob] of processed.config) {
|
|
415
|
+
if (glob && glob.match(filepath)) {
|
|
416
|
+
Object.assign(props, body);
|
|
417
|
+
if (options.files) {
|
|
418
|
+
options.files.push({
|
|
419
|
+
fileName: processed.name,
|
|
420
|
+
glob: name,
|
|
421
|
+
});
|
|
422
|
+
}
|
|
423
|
+
}
|
|
424
|
+
}
|
|
425
|
+
return props;
|
|
426
|
+
}, {});
|
|
427
|
+
return processMatches(ret, options.version);
|
|
428
|
+
}
|
|
429
|
+
/**
|
|
430
|
+
* Find all of the properties from matching sections in config files in the
|
|
431
|
+
* same directory or toward the root of the filesystem.
|
|
432
|
+
*
|
|
433
|
+
* @param filepath The target file name, relative to process.cwd().
|
|
434
|
+
* @param options All options
|
|
435
|
+
* @returns Combined properties for the target file
|
|
436
|
+
*/
|
|
437
|
+
async function parse(filepath, options = {}) {
|
|
438
|
+
const [resolvedFilePath, processedOptions] = opts(filepath, options);
|
|
439
|
+
const filepaths = getConfigFileNames(resolvedFilePath, processedOptions);
|
|
440
|
+
const configs = await getAllConfigs(filepaths, processedOptions);
|
|
441
|
+
return combine(resolvedFilePath, configs, processedOptions);
|
|
442
|
+
}
|
|
443
|
+
exports.parse = parse;
|
|
444
|
+
/**
|
|
445
|
+
* Find all of the properties from matching sections in config files in the
|
|
446
|
+
* same directory or toward the root of the filesystem. Synchronous.
|
|
447
|
+
*
|
|
448
|
+
* @param filepath The target file name, relative to process.cwd().
|
|
449
|
+
* @param options All options
|
|
450
|
+
* @returns Combined properties for the target file
|
|
451
|
+
*/
|
|
452
|
+
function parseSync(filepath, options = {}) {
|
|
453
|
+
const [resolvedFilePath, processedOptions] = opts(filepath, options);
|
|
454
|
+
const filepaths = getConfigFileNames(resolvedFilePath, processedOptions);
|
|
455
|
+
const configs = getAllConfigsSync(filepaths, processedOptions);
|
|
456
|
+
return combine(resolvedFilePath, configs, processedOptions);
|
|
457
|
+
}
|
|
458
|
+
exports.parseSync = parseSync;
|
package/package.json
CHANGED
|
@@ -1,59 +1,66 @@
|
|
|
1
|
-
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
"
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
1
|
+
{
|
|
2
|
+
"name": "editorconfig",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "EditorConfig File Locator and Interpreter for Node.js",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"editorconfig",
|
|
7
|
+
"core"
|
|
8
|
+
],
|
|
9
|
+
"main": "./lib/index.js",
|
|
10
|
+
"contributors": [
|
|
11
|
+
"Hong Xu (topbug.net)",
|
|
12
|
+
"Jed Mao (https://github.com/jedmao/)",
|
|
13
|
+
"Trey Hunner (http://treyhunner.com)",
|
|
14
|
+
"Joe Hildebrand (https://github.com/hildjj/)"
|
|
15
|
+
],
|
|
16
|
+
"directories": {
|
|
17
|
+
"bin": "./bin",
|
|
18
|
+
"lib": "./lib"
|
|
19
|
+
},
|
|
20
|
+
"scripts": {
|
|
21
|
+
"clean": "rimraf lib *.cmake Makefile",
|
|
22
|
+
"prebuild": "npm run clean",
|
|
23
|
+
"build": "cmake . && tsc",
|
|
24
|
+
"pretest": "npm run build && npm run lint",
|
|
25
|
+
"test": "npm run test:all",
|
|
26
|
+
"test:all": "mocha && ctest . --preset Test",
|
|
27
|
+
"precoverage": "npm run build -- --inlineSourceMap",
|
|
28
|
+
"coverage": "c8 npm run test:all",
|
|
29
|
+
"postcoverage": "npm run build",
|
|
30
|
+
"ci": "npm run coverage -- -- -VV --output-on-failure",
|
|
31
|
+
"lint": "eslint . --ext ts",
|
|
32
|
+
"prepub": "npm run lint && npm run build",
|
|
33
|
+
"pub": "npm publish"
|
|
34
|
+
},
|
|
35
|
+
"repository": {
|
|
36
|
+
"type": "git",
|
|
37
|
+
"url": "git://github.com/editorconfig/editorconfig-core-js.git"
|
|
38
|
+
},
|
|
39
|
+
"bugs": "https://github.com/editorconfig/editorconfig-core-js/issues",
|
|
40
|
+
"author": "EditorConfig Team",
|
|
41
|
+
"license": "MIT",
|
|
42
|
+
"dependencies": {
|
|
43
|
+
"@one-ini/wasm": "0.1.0",
|
|
44
|
+
"commander": "^9.4.1",
|
|
45
|
+
"minimatch": "5.1.0",
|
|
46
|
+
"semver": "^7.3.8"
|
|
47
|
+
},
|
|
48
|
+
"devDependencies": {
|
|
49
|
+
"@types/minimatch": "5.1.2",
|
|
50
|
+
"@types/mocha": "^10.0.0",
|
|
51
|
+
"@types/node": "^18.11.0",
|
|
52
|
+
"@types/semver": "^7.3.12",
|
|
53
|
+
"@typescript-eslint/eslint-plugin": "5.40.1",
|
|
54
|
+
"@typescript-eslint/parser": "5.40.1",
|
|
55
|
+
"c8": "7.12.0",
|
|
56
|
+
"eslint": "8.25.0",
|
|
57
|
+
"eslint-plugin-jsdoc": "39.3.12",
|
|
58
|
+
"mocha": "^10.1.0",
|
|
59
|
+
"rimraf": "^3.0.2",
|
|
60
|
+
"should": "^13.2.3",
|
|
61
|
+
"typescript": "^4.8.4"
|
|
62
|
+
},
|
|
63
|
+
"engines": {
|
|
64
|
+
"node": ">=14"
|
|
65
|
+
}
|
|
66
|
+
}
|
package/CHANGELOG.md
DELETED
package/src/cli.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export default function cli(args: string[]): void;
|
package/src/cli.js
DELETED
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
6
|
-
if (mod && mod.__esModule) return mod;
|
|
7
|
-
var result = {};
|
|
8
|
-
if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
|
|
9
|
-
result["default"] = mod;
|
|
10
|
-
return result;
|
|
11
|
-
};
|
|
12
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
|
-
// tslint:disable:no-console
|
|
14
|
-
var commander_1 = __importDefault(require("commander"));
|
|
15
|
-
var editorconfig = __importStar(require("./"));
|
|
16
|
-
var package_json_1 = __importDefault(require("../package.json"));
|
|
17
|
-
function cli(args) {
|
|
18
|
-
commander_1.default.version('EditorConfig Node.js Core Version ' + package_json_1.default.version);
|
|
19
|
-
commander_1.default
|
|
20
|
-
.usage([
|
|
21
|
-
'[OPTIONS] FILEPATH1 [FILEPATH2 FILEPATH3 ...]',
|
|
22
|
-
commander_1.default._version,
|
|
23
|
-
'FILEPATH can be a hyphen (-) if you want path(s) to be read from stdin.',
|
|
24
|
-
].join('\n\n '))
|
|
25
|
-
.option('-f <path>', 'Specify conf filename other than \'.editorconfig\'')
|
|
26
|
-
.option('-b <version>', 'Specify version (used by devs to test compatibility)')
|
|
27
|
-
.option('-v, --version', 'Display version information')
|
|
28
|
-
.parse(args);
|
|
29
|
-
// Throw away the native -V flag in lieu of the one we've manually specified
|
|
30
|
-
// to adhere to testing requirements
|
|
31
|
-
commander_1.default.options.shift();
|
|
32
|
-
var files = commander_1.default.args;
|
|
33
|
-
if (!files.length) {
|
|
34
|
-
commander_1.default.help();
|
|
35
|
-
}
|
|
36
|
-
files
|
|
37
|
-
.map(function (filePath) { return editorconfig.parse(filePath, {
|
|
38
|
-
config: commander_1.default.F,
|
|
39
|
-
version: commander_1.default.B,
|
|
40
|
-
}); })
|
|
41
|
-
.forEach(function (parsing, i, _a) {
|
|
42
|
-
var length = _a.length;
|
|
43
|
-
parsing.then(function (parsed) {
|
|
44
|
-
if (length > 1) {
|
|
45
|
-
console.log("[" + files[i] + "]");
|
|
46
|
-
}
|
|
47
|
-
Object.keys(parsed).forEach(function (key) {
|
|
48
|
-
console.log(key + "=" + parsed[key]);
|
|
49
|
-
});
|
|
50
|
-
});
|
|
51
|
-
});
|
|
52
|
-
}
|
|
53
|
-
exports.default = cli;
|
package/src/index.d.ts
DELETED
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
/// <reference types="node" />
|
|
2
|
-
import { parseString, ParseStringResult } from './lib/ini';
|
|
3
|
-
export { parseString };
|
|
4
|
-
export interface KnownProps {
|
|
5
|
-
end_of_line?: 'lf' | 'crlf' | 'unset';
|
|
6
|
-
indent_style?: 'tab' | 'space' | 'unset';
|
|
7
|
-
indent_size?: number | 'tab' | 'unset';
|
|
8
|
-
insert_final_newline?: true | false | 'unset';
|
|
9
|
-
tab_width?: number | 'unset';
|
|
10
|
-
trim_trailing_whitespace?: true | false | 'unset';
|
|
11
|
-
charset?: string | 'unset';
|
|
12
|
-
}
|
|
13
|
-
export interface ECFile {
|
|
14
|
-
name: string;
|
|
15
|
-
contents: string | Buffer;
|
|
16
|
-
}
|
|
17
|
-
export interface FileConfig {
|
|
18
|
-
name: string;
|
|
19
|
-
contents: ParseStringResult;
|
|
20
|
-
}
|
|
21
|
-
export interface ParseOptions {
|
|
22
|
-
config?: string;
|
|
23
|
-
version?: string;
|
|
24
|
-
root?: string;
|
|
25
|
-
}
|
|
26
|
-
export declare function parseFromFiles(filepath: string, files: Promise<ECFile[]>, options?: ParseOptions): Promise<KnownProps>;
|
|
27
|
-
export declare function parseFromFilesSync(filepath: string, files: ECFile[], options?: ParseOptions): KnownProps;
|
|
28
|
-
export declare function parse(_filepath: string, _options?: ParseOptions): Promise<KnownProps>;
|
|
29
|
-
export declare function parseSync(_filepath: string, _options?: ParseOptions): KnownProps;
|