editorconfig 1.0.4 → 2.0.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/README.md +6 -0
- package/eslint.config.mjs +13 -0
- package/lib/cli.d.ts +1 -1
- package/lib/cli.js +24 -13
- package/lib/index.d.ts +28 -5
- package/lib/index.js +137 -82
- package/package.json +6 -35
package/README.md
CHANGED
|
@@ -35,6 +35,7 @@ Most of the API takes an `options` object, which has the following defaults:
|
|
|
35
35
|
root: '/',
|
|
36
36
|
files: undefined,
|
|
37
37
|
cache: undefined,
|
|
38
|
+
unset: false,
|
|
38
39
|
};
|
|
39
40
|
```
|
|
40
41
|
|
|
@@ -71,6 +72,11 @@ Most of the API takes an `options` object, which has the following defaults:
|
|
|
71
72
|
fully-qualified file name of the config file and a `root: boolean` property
|
|
72
73
|
that describes if the config file had a `root=true` at the top. Any other
|
|
73
74
|
properties in the objects should be treated as opaque.</dd>
|
|
75
|
+
|
|
76
|
+
<dt>unset</dt>
|
|
77
|
+
<dd>If true, after combining all properties, remove all properties whose value
|
|
78
|
+
remains as "unset". This is typically left for plugin authors to do, and
|
|
79
|
+
the conformance tests assume that this value is always false.</dd>
|
|
74
80
|
</dl>
|
|
75
81
|
|
|
76
82
|
### in Node.js:
|
package/lib/cli.d.ts
CHANGED
package/lib/cli.js
CHANGED
|
@@ -15,19 +15,30 @@ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (
|
|
|
15
15
|
}) : function(o, v) {
|
|
16
16
|
o["default"] = v;
|
|
17
17
|
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
};
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
25
35
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
26
36
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
37
|
};
|
|
28
38
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
+
exports.default = cli;
|
|
40
|
+
const editorconfig = __importStar(require("./index.js"));
|
|
29
41
|
const commander_1 = require("commander");
|
|
30
|
-
const editorconfig = __importStar(require("./"));
|
|
31
42
|
const package_json_1 = __importDefault(require("../package.json"));
|
|
32
43
|
/**
|
|
33
44
|
* Default output routine, goes to stdout.
|
|
@@ -53,18 +64,18 @@ async function cli(args, testing) {
|
|
|
53
64
|
let writeOut = writeStdOut;
|
|
54
65
|
if (testing) {
|
|
55
66
|
if (testing.writeOut) {
|
|
56
|
-
|
|
57
|
-
writeOut = testing.writeOut;
|
|
67
|
+
({ writeOut } = testing);
|
|
58
68
|
}
|
|
59
69
|
program.configureOutput(testing);
|
|
60
70
|
program.exitOverride();
|
|
61
71
|
}
|
|
62
|
-
program.version(
|
|
72
|
+
program.version(`EditorConfig Node.js Core Version ${package_json_1.default.version}`, '-v, --version', 'Display version information')
|
|
63
73
|
.showHelpAfterError()
|
|
64
74
|
.argument('<FILEPATH...>', 'Files to find configuration for. Can be a hyphen (-) if you want path(s) to be read from stdin.')
|
|
65
75
|
.option('-f <path>', 'Specify conf filename other than \'.editorconfig\'')
|
|
66
76
|
.option('-b <version>', 'Specify version (used by devs to test compatibility)')
|
|
67
77
|
.option('--files', 'Output file names that contributed to the configuration, rather than the configuation itself')
|
|
78
|
+
.option('--unset', 'Remove all properties whose final value is \'unset\'')
|
|
68
79
|
.parse(args);
|
|
69
80
|
const files = program.args;
|
|
70
81
|
const opts = program.opts();
|
|
@@ -82,11 +93,12 @@ async function cli(args, testing) {
|
|
|
82
93
|
version: opts.b,
|
|
83
94
|
files: visited ? visited[i++] : undefined,
|
|
84
95
|
cache,
|
|
96
|
+
unset: Boolean(opts.unset),
|
|
85
97
|
}));
|
|
86
98
|
}
|
|
87
99
|
return p;
|
|
88
100
|
}
|
|
89
|
-
return
|
|
101
|
+
return processAll().then(parsed => {
|
|
90
102
|
const header = parsed.length > 1;
|
|
91
103
|
parsed.forEach((props, i) => {
|
|
92
104
|
if (header) {
|
|
@@ -106,4 +118,3 @@ async function cli(args, testing) {
|
|
|
106
118
|
return parsed;
|
|
107
119
|
});
|
|
108
120
|
}
|
|
109
|
-
exports.default = cli;
|
package/lib/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
import { Buffer } from 'node:buffer';
|
|
2
2
|
import { Minimatch } from 'minimatch';
|
|
3
3
|
export interface KnownProps {
|
|
4
4
|
end_of_line?: 'lf' | 'crlf' | 'unset';
|
|
@@ -39,6 +39,7 @@ export interface ParseOptions {
|
|
|
39
39
|
root?: string;
|
|
40
40
|
files?: Visited[];
|
|
41
41
|
cache?: Cache;
|
|
42
|
+
unset?: boolean;
|
|
42
43
|
}
|
|
43
44
|
export type SectionName = string | null;
|
|
44
45
|
export interface SectionBody {
|
|
@@ -62,28 +63,36 @@ export declare function parseBuffer(data: Buffer): ParseStringResult;
|
|
|
62
63
|
* @deprecated Use {@link ParseBuffer} instead.
|
|
63
64
|
*/
|
|
64
65
|
export declare function parseString(data: string): ParseStringResult;
|
|
66
|
+
/**
|
|
67
|
+
* For any pair, a value of `unset` removes the effect of that pair, even if
|
|
68
|
+
* it has been set before. This method modifies the properties object in
|
|
69
|
+
* place to remove any property that has a value of `unset`.
|
|
70
|
+
*
|
|
71
|
+
* @param props Properties object to modify.
|
|
72
|
+
*/
|
|
73
|
+
export declare function unset(props: Props): void;
|
|
65
74
|
/**
|
|
66
75
|
* Low-level interface, which exists only for backward-compatibility.
|
|
67
76
|
* Deprecated.
|
|
68
77
|
*
|
|
69
78
|
* @param filepath The name of the target file, relative to process.cwd().
|
|
70
|
-
* @param files A
|
|
79
|
+
* @param files A list of objects describing the files.
|
|
71
80
|
* @param options All options
|
|
72
81
|
* @returns The properties found for filepath
|
|
73
82
|
* @deprecated
|
|
74
83
|
*/
|
|
75
|
-
export declare function
|
|
84
|
+
export declare function parseFromFilesSync(filepath: string, files: ECFile[], options?: ParseOptions): Props;
|
|
76
85
|
/**
|
|
77
86
|
* Low-level interface, which exists only for backward-compatibility.
|
|
78
87
|
* Deprecated.
|
|
79
88
|
*
|
|
80
89
|
* @param filepath The name of the target file, relative to process.cwd().
|
|
81
|
-
* @param files A list of objects describing the files.
|
|
90
|
+
* @param files A promise for a list of objects describing the files.
|
|
82
91
|
* @param options All options
|
|
83
92
|
* @returns The properties found for filepath
|
|
84
93
|
* @deprecated
|
|
85
94
|
*/
|
|
86
|
-
export declare function
|
|
95
|
+
export declare function parseFromFiles(filepath: string, files: Promise<ECFile[]>, options?: ParseOptions): Promise<Props>;
|
|
87
96
|
/**
|
|
88
97
|
* Find all of the properties from matching sections in config files in the
|
|
89
98
|
* same directory or toward the root of the filesystem.
|
|
@@ -102,4 +111,18 @@ export declare function parse(filepath: string, options?: ParseOptions): Promise
|
|
|
102
111
|
* @returns Combined properties for the target file
|
|
103
112
|
*/
|
|
104
113
|
export declare function parseSync(filepath: string, options?: ParseOptions): Props;
|
|
114
|
+
/**
|
|
115
|
+
* I think this may be of limited utility at the moment, but I need something
|
|
116
|
+
* like this for testing. As such, the interface of this may change without
|
|
117
|
+
* warning.
|
|
118
|
+
*
|
|
119
|
+
* Something this direction may be better for editors than the caching bits
|
|
120
|
+
* we've got today, but that will need some thought.
|
|
121
|
+
*
|
|
122
|
+
* @param options All options. root will be process.cwd if not specified.
|
|
123
|
+
* @param buffers 1 or more Buffers that have .editorconfig contents.
|
|
124
|
+
* @returns Function that can be called multiple times for different paths.
|
|
125
|
+
* @private
|
|
126
|
+
*/
|
|
127
|
+
export declare function matcher(options: ParseOptions, ...buffers: Buffer[]): (filepath: string) => Props;
|
|
105
128
|
export {};
|
package/lib/index.js
CHANGED
|
@@ -15,38 +15,53 @@ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (
|
|
|
15
15
|
}) : function(o, v) {
|
|
16
16
|
o["default"] = v;
|
|
17
17
|
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
};
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
25
35
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
26
36
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
37
|
};
|
|
28
38
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
-
exports.
|
|
30
|
-
|
|
31
|
-
|
|
39
|
+
exports.parseBuffer = parseBuffer;
|
|
40
|
+
exports.parseString = parseString;
|
|
41
|
+
exports.unset = unset;
|
|
42
|
+
exports.parseFromFilesSync = parseFromFilesSync;
|
|
43
|
+
exports.parseFromFiles = parseFromFiles;
|
|
44
|
+
exports.parse = parse;
|
|
45
|
+
exports.parseSync = parseSync;
|
|
46
|
+
exports.matcher = matcher;
|
|
47
|
+
const fs = __importStar(require("node:fs"));
|
|
48
|
+
const path = __importStar(require("node:path"));
|
|
32
49
|
const semver = __importStar(require("semver"));
|
|
33
|
-
const minimatch_1 = require("minimatch");
|
|
34
50
|
const wasm_1 = require("@one-ini/wasm");
|
|
35
|
-
|
|
36
|
-
|
|
51
|
+
const node_buffer_1 = require("node:buffer");
|
|
52
|
+
const minimatch_1 = require("minimatch");
|
|
37
53
|
const package_json_1 = __importDefault(require("../package.json"));
|
|
38
54
|
const escapedSep = new RegExp(path.sep.replace(/\\/g, '\\\\'), 'g');
|
|
39
|
-
const matchOptions = { matchBase: true, dot: true
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
};
|
|
55
|
+
const matchOptions = { matchBase: true, dot: true };
|
|
56
|
+
const knownPropNames = [
|
|
57
|
+
'end_of_line',
|
|
58
|
+
'indent_style',
|
|
59
|
+
'indent_size',
|
|
60
|
+
'insert_final_newline',
|
|
61
|
+
'trim_trailing_whitespace',
|
|
62
|
+
'charset',
|
|
63
|
+
];
|
|
64
|
+
const knownProps = new Set(knownPropNames);
|
|
50
65
|
/**
|
|
51
66
|
* Parse a buffer using the faster one-ini WASM approach into something
|
|
52
67
|
* relatively easy to deal with in JS.
|
|
@@ -82,7 +97,6 @@ function parseBuffer(data) {
|
|
|
82
97
|
}
|
|
83
98
|
return res;
|
|
84
99
|
}
|
|
85
|
-
exports.parseBuffer = parseBuffer;
|
|
86
100
|
/**
|
|
87
101
|
* Parses a string. If possible, you should always use ParseBuffer instead,
|
|
88
102
|
* since this function does a UTF16-to-UTF8 conversion first.
|
|
@@ -92,9 +106,8 @@ exports.parseBuffer = parseBuffer;
|
|
|
92
106
|
* @deprecated Use {@link ParseBuffer} instead.
|
|
93
107
|
*/
|
|
94
108
|
function parseString(data) {
|
|
95
|
-
return parseBuffer(Buffer.from(data));
|
|
109
|
+
return parseBuffer(node_buffer_1.Buffer.from(data));
|
|
96
110
|
}
|
|
97
|
-
exports.parseString = parseString;
|
|
98
111
|
/**
|
|
99
112
|
* Gets a list of *potential* filenames based on the path of the target
|
|
100
113
|
* filename.
|
|
@@ -122,23 +135,23 @@ function getConfigFileNames(filepath, options) {
|
|
|
122
135
|
function processMatches(matches, version) {
|
|
123
136
|
// Set indent_size to 'tab' if indent_size is unspecified and
|
|
124
137
|
// indent_style is set to 'tab'.
|
|
125
|
-
if ('indent_style' in matches
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
138
|
+
if ('indent_style' in matches &&
|
|
139
|
+
matches.indent_style === 'tab' &&
|
|
140
|
+
!('indent_size' in matches) &&
|
|
141
|
+
semver.gte(version, '0.10.0')) {
|
|
129
142
|
matches.indent_size = 'tab';
|
|
130
143
|
}
|
|
131
144
|
// Set tab_width to indent_size if indent_size is specified and
|
|
132
145
|
// tab_width is unspecified
|
|
133
|
-
if ('indent_size' in matches
|
|
134
|
-
|
|
135
|
-
|
|
146
|
+
if ('indent_size' in matches &&
|
|
147
|
+
!('tab_width' in matches) &&
|
|
148
|
+
matches.indent_size !== 'tab') {
|
|
136
149
|
matches.tab_width = matches.indent_size;
|
|
137
150
|
}
|
|
138
151
|
// Set indent_size to tab_width if indent_size is 'tab'
|
|
139
|
-
if ('indent_size' in matches
|
|
140
|
-
|
|
141
|
-
|
|
152
|
+
if ('indent_size' in matches &&
|
|
153
|
+
'tab_width' in matches &&
|
|
154
|
+
matches.indent_size === 'tab') {
|
|
142
155
|
matches.indent_size = matches.tab_width;
|
|
143
156
|
}
|
|
144
157
|
return matches;
|
|
@@ -146,7 +159,7 @@ function processMatches(matches, version) {
|
|
|
146
159
|
function buildFullGlob(pathPrefix, glob) {
|
|
147
160
|
switch (glob.indexOf('/')) {
|
|
148
161
|
case -1:
|
|
149
|
-
glob =
|
|
162
|
+
glob = `**/${glob}`;
|
|
150
163
|
break;
|
|
151
164
|
case 0:
|
|
152
165
|
glob = glob.substring(1);
|
|
@@ -154,9 +167,11 @@ function buildFullGlob(pathPrefix, glob) {
|
|
|
154
167
|
default:
|
|
155
168
|
break;
|
|
156
169
|
}
|
|
170
|
+
//
|
|
157
171
|
// braces_escaped_backslash2
|
|
158
172
|
// backslash_not_on_windows
|
|
159
173
|
glob = glob.replace(/\\\\/g, '\\\\\\\\');
|
|
174
|
+
//
|
|
160
175
|
// star_star_over_separator{1,3,5,6,9,15}
|
|
161
176
|
glob = glob.replace(/\*\*/g, '{*,**/**/**}');
|
|
162
177
|
// NOT path.join. Must stay in forward slashes.
|
|
@@ -173,25 +188,26 @@ function buildFullGlob(pathPrefix, glob) {
|
|
|
173
188
|
function normalizeProps(options) {
|
|
174
189
|
const props = {};
|
|
175
190
|
for (const key in options) {
|
|
176
|
-
if (
|
|
191
|
+
if (Object.prototype.hasOwnProperty.call(options, key)) {
|
|
177
192
|
const value = options[key];
|
|
178
193
|
const key2 = key.toLowerCase();
|
|
179
194
|
let value2 = value;
|
|
180
|
-
|
|
181
|
-
if (knownProps[key2]) {
|
|
195
|
+
if (knownProps.has(key2)) {
|
|
182
196
|
// All of the values for the known props are lowercase.
|
|
183
197
|
value2 = String(value).toLowerCase();
|
|
184
198
|
}
|
|
185
199
|
try {
|
|
186
200
|
value2 = JSON.parse(String(value));
|
|
187
201
|
}
|
|
188
|
-
catch (
|
|
202
|
+
catch (_e) {
|
|
203
|
+
// Ignored
|
|
204
|
+
}
|
|
189
205
|
if (typeof value2 === 'undefined' || value2 === null) {
|
|
206
|
+
//
|
|
190
207
|
// null and undefined are values specific to JSON (no special meaning
|
|
191
208
|
// in editorconfig) & should just be returned as regular strings.
|
|
192
209
|
value2 = String(value);
|
|
193
210
|
}
|
|
194
|
-
// @ts-ignore -- Fix types here
|
|
195
211
|
props[key2] = value2;
|
|
196
212
|
}
|
|
197
213
|
}
|
|
@@ -208,7 +224,8 @@ function normalizeProps(options) {
|
|
|
208
224
|
* @returns Processed file with globs pre-computed.
|
|
209
225
|
*/
|
|
210
226
|
function processFileContents(filepath, contents, options) {
|
|
211
|
-
let res;
|
|
227
|
+
let res = undefined;
|
|
228
|
+
// eslint-disable-next-line no-negated-condition
|
|
212
229
|
if (!contents) {
|
|
213
230
|
// Negative cache
|
|
214
231
|
res = {
|
|
@@ -239,7 +256,7 @@ function processFileContents(filepath, contents, options) {
|
|
|
239
256
|
name ? buildFullGlob(pathPrefix, name) : null,
|
|
240
257
|
]);
|
|
241
258
|
res = {
|
|
242
|
-
root:
|
|
259
|
+
root: Boolean(globbed[0][1].root), // Global section: globbed[0]
|
|
243
260
|
name: filepath,
|
|
244
261
|
config: globbed,
|
|
245
262
|
};
|
|
@@ -288,7 +305,7 @@ function getConfigSync(filepath, options) {
|
|
|
288
305
|
return cached;
|
|
289
306
|
}
|
|
290
307
|
}
|
|
291
|
-
let contents;
|
|
308
|
+
let contents = undefined;
|
|
292
309
|
try {
|
|
293
310
|
contents = fs.readFileSync(filepath);
|
|
294
311
|
}
|
|
@@ -357,23 +374,55 @@ function opts(filepath, options = {}) {
|
|
|
357
374
|
root: path.resolve(options.root || path.parse(resolvedFilePath).root),
|
|
358
375
|
files: options.files,
|
|
359
376
|
cache: options.cache,
|
|
377
|
+
unset: options.unset,
|
|
360
378
|
},
|
|
361
379
|
];
|
|
362
380
|
}
|
|
363
381
|
/**
|
|
364
|
-
*
|
|
365
|
-
*
|
|
382
|
+
* For any pair, a value of `unset` removes the effect of that pair, even if
|
|
383
|
+
* it has been set before. This method modifies the properties object in
|
|
384
|
+
* place to remove any property that has a value of `unset`.
|
|
366
385
|
*
|
|
367
|
-
* @param
|
|
368
|
-
* @param files A promise for a list of objects describing the files.
|
|
369
|
-
* @param options All options
|
|
370
|
-
* @returns The properties found for filepath
|
|
371
|
-
* @deprecated
|
|
386
|
+
* @param props Properties object to modify.
|
|
372
387
|
*/
|
|
373
|
-
|
|
374
|
-
|
|
388
|
+
function unset(props) {
|
|
389
|
+
const keys = Object.keys(props);
|
|
390
|
+
for (const k of keys) {
|
|
391
|
+
if (props[k] === 'unset') {
|
|
392
|
+
// eslint-disable-next-line @typescript-eslint/no-dynamic-delete
|
|
393
|
+
delete props[k];
|
|
394
|
+
}
|
|
395
|
+
}
|
|
396
|
+
}
|
|
397
|
+
/**
|
|
398
|
+
* Combine the pre-parsed results of all matching config file sections, in
|
|
399
|
+
* order.
|
|
400
|
+
*
|
|
401
|
+
* @param filepath The target file path
|
|
402
|
+
* @param configs All of the found config files, up to the root
|
|
403
|
+
* @param options Adds to `options.files` if it exists
|
|
404
|
+
* @returns Combined properties
|
|
405
|
+
*/
|
|
406
|
+
function combine(filepath, configs, options) {
|
|
407
|
+
const ret = configs.reverse().reduce((props, processed) => {
|
|
408
|
+
for (const [name, body, glob] of processed.config) {
|
|
409
|
+
if (glob === null || glob === void 0 ? void 0 : glob.match(filepath)) {
|
|
410
|
+
Object.assign(props, body);
|
|
411
|
+
if (options.files) {
|
|
412
|
+
options.files.push({
|
|
413
|
+
fileName: processed.name,
|
|
414
|
+
glob: name,
|
|
415
|
+
});
|
|
416
|
+
}
|
|
417
|
+
}
|
|
418
|
+
}
|
|
419
|
+
return props;
|
|
420
|
+
}, {});
|
|
421
|
+
if (options.unset) {
|
|
422
|
+
unset(ret);
|
|
423
|
+
}
|
|
424
|
+
return processMatches(ret, options.version);
|
|
375
425
|
}
|
|
376
|
-
exports.parseFromFiles = parseFromFiles;
|
|
377
426
|
/**
|
|
378
427
|
* Low-level interface, which exists only for backward-compatibility.
|
|
379
428
|
* Deprecated.
|
|
@@ -388,7 +437,7 @@ function parseFromFilesSync(filepath, files, options = {}) {
|
|
|
388
437
|
const [resolvedFilePath, processedOptions] = opts(filepath, options);
|
|
389
438
|
const configs = [];
|
|
390
439
|
for (const ecf of files) {
|
|
391
|
-
let cfg;
|
|
440
|
+
let cfg = undefined;
|
|
392
441
|
if (!options.cache || !(cfg = options.cache.get(ecf.name))) { // Single "="!
|
|
393
442
|
cfg = processFileContents(ecf.name, ecf.contents, processedOptions);
|
|
394
443
|
}
|
|
@@ -401,32 +450,19 @@ function parseFromFilesSync(filepath, files, options = {}) {
|
|
|
401
450
|
}
|
|
402
451
|
return combine(resolvedFilePath, configs, processedOptions);
|
|
403
452
|
}
|
|
404
|
-
exports.parseFromFilesSync = parseFromFilesSync;
|
|
405
453
|
/**
|
|
406
|
-
*
|
|
407
|
-
*
|
|
454
|
+
* Low-level interface, which exists only for backward-compatibility.
|
|
455
|
+
* Deprecated.
|
|
408
456
|
*
|
|
409
|
-
* @param filepath The target file
|
|
410
|
-
* @param
|
|
411
|
-
* @param options
|
|
412
|
-
* @returns
|
|
457
|
+
* @param filepath The name of the target file, relative to process.cwd().
|
|
458
|
+
* @param files A promise for a list of objects describing the files.
|
|
459
|
+
* @param options All options
|
|
460
|
+
* @returns The properties found for filepath
|
|
461
|
+
* @deprecated
|
|
413
462
|
*/
|
|
414
|
-
function
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
if (glob && glob.match(filepath)) {
|
|
418
|
-
Object.assign(props, body);
|
|
419
|
-
if (options.files) {
|
|
420
|
-
options.files.push({
|
|
421
|
-
fileName: processed.name,
|
|
422
|
-
glob: name,
|
|
423
|
-
});
|
|
424
|
-
}
|
|
425
|
-
}
|
|
426
|
-
}
|
|
427
|
-
return props;
|
|
428
|
-
}, {});
|
|
429
|
-
return processMatches(ret, options.version);
|
|
463
|
+
async function parseFromFiles(filepath, files, options = {}) {
|
|
464
|
+
// eslint-disable-next-line @typescript-eslint/no-deprecated
|
|
465
|
+
return parseFromFilesSync(filepath, await files, options);
|
|
430
466
|
}
|
|
431
467
|
/**
|
|
432
468
|
* Find all of the properties from matching sections in config files in the
|
|
@@ -442,7 +478,6 @@ async function parse(filepath, options = {}) {
|
|
|
442
478
|
const configs = await getAllConfigs(filepaths, processedOptions);
|
|
443
479
|
return combine(resolvedFilePath, configs, processedOptions);
|
|
444
480
|
}
|
|
445
|
-
exports.parse = parse;
|
|
446
481
|
/**
|
|
447
482
|
* Find all of the properties from matching sections in config files in the
|
|
448
483
|
* same directory or toward the root of the filesystem. Synchronous.
|
|
@@ -457,4 +492,24 @@ function parseSync(filepath, options = {}) {
|
|
|
457
492
|
const configs = getAllConfigsSync(filepaths, processedOptions);
|
|
458
493
|
return combine(resolvedFilePath, configs, processedOptions);
|
|
459
494
|
}
|
|
460
|
-
|
|
495
|
+
/**
|
|
496
|
+
* I think this may be of limited utility at the moment, but I need something
|
|
497
|
+
* like this for testing. As such, the interface of this may change without
|
|
498
|
+
* warning.
|
|
499
|
+
*
|
|
500
|
+
* Something this direction may be better for editors than the caching bits
|
|
501
|
+
* we've got today, but that will need some thought.
|
|
502
|
+
*
|
|
503
|
+
* @param options All options. root will be process.cwd if not specified.
|
|
504
|
+
* @param buffers 1 or more Buffers that have .editorconfig contents.
|
|
505
|
+
* @returns Function that can be called multiple times for different paths.
|
|
506
|
+
* @private
|
|
507
|
+
*/
|
|
508
|
+
function matcher(options, ...buffers) {
|
|
509
|
+
const [_fileName, processedOptions] = opts('', options);
|
|
510
|
+
const configs = buffers.map((buf, i) => processFileContents(path.join(processedOptions.root, `buffer-${i}`), buf, processedOptions));
|
|
511
|
+
return (filepath) => {
|
|
512
|
+
const resolvedFilePath = path.resolve(filepath);
|
|
513
|
+
return combine(resolvedFilePath, configs, processedOptions);
|
|
514
|
+
};
|
|
515
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "editorconfig",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.1",
|
|
4
4
|
"description": "EditorConfig File Locator and Interpreter for Node.js",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"editorconfig",
|
|
@@ -17,21 +17,6 @@
|
|
|
17
17
|
"bin": "./bin",
|
|
18
18
|
"lib": "./lib"
|
|
19
19
|
},
|
|
20
|
-
"scripts": {
|
|
21
|
-
"clean": "rimraf lib cmake_install.cmake CTestTestfile.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
20
|
"repository": {
|
|
36
21
|
"type": "git",
|
|
37
22
|
"url": "git://github.com/editorconfig/editorconfig-core-js.git"
|
|
@@ -40,26 +25,12 @@
|
|
|
40
25
|
"author": "EditorConfig Team",
|
|
41
26
|
"license": "MIT",
|
|
42
27
|
"dependencies": {
|
|
43
|
-
"@one-ini/wasm": "0.
|
|
44
|
-
"commander": "^
|
|
45
|
-
"minimatch": "
|
|
46
|
-
"semver": "^7.
|
|
47
|
-
},
|
|
48
|
-
"devDependencies": {
|
|
49
|
-
"@types/mocha": "^10.0.1",
|
|
50
|
-
"@types/node": "^20.3.1",
|
|
51
|
-
"@types/semver": "^7.5.0",
|
|
52
|
-
"@typescript-eslint/eslint-plugin": "5.60.0",
|
|
53
|
-
"@typescript-eslint/parser": "5.60.0",
|
|
54
|
-
"c8": "8.0.0",
|
|
55
|
-
"eslint": "8.43.0",
|
|
56
|
-
"eslint-plugin-jsdoc": "46.2.6",
|
|
57
|
-
"mocha": "^10.2.0",
|
|
58
|
-
"rimraf": "^5.0.1",
|
|
59
|
-
"should": "^13.2.3",
|
|
60
|
-
"typescript": "^5.1.3"
|
|
28
|
+
"@one-ini/wasm": "0.2.0",
|
|
29
|
+
"commander": "^13.1.0",
|
|
30
|
+
"minimatch": "10.0.1",
|
|
31
|
+
"semver": "^7.7.1"
|
|
61
32
|
},
|
|
62
33
|
"engines": {
|
|
63
|
-
"node": ">=
|
|
34
|
+
"node": ">=18"
|
|
64
35
|
}
|
|
65
36
|
}
|