editorconfig 1.0.2 → 2.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 +6 -0
- package/lib/cli.js +2 -0
- package/lib/index.d.ts +23 -0
- package/lib/index.js +55 -14
- package/package.json +26 -15
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.js
CHANGED
|
@@ -65,6 +65,7 @@ async function cli(args, testing) {
|
|
|
65
65
|
.option('-f <path>', 'Specify conf filename other than \'.editorconfig\'')
|
|
66
66
|
.option('-b <version>', 'Specify version (used by devs to test compatibility)')
|
|
67
67
|
.option('--files', 'Output file names that contributed to the configuration, rather than the configuation itself')
|
|
68
|
+
.option('--unset', 'Remove all properties whose final value is \'unset\'')
|
|
68
69
|
.parse(args);
|
|
69
70
|
const files = program.args;
|
|
70
71
|
const opts = program.opts();
|
|
@@ -82,6 +83,7 @@ async function cli(args, testing) {
|
|
|
82
83
|
version: opts.b,
|
|
83
84
|
files: visited ? visited[i++] : undefined,
|
|
84
85
|
cache,
|
|
86
|
+
unset: Boolean(opts.unset),
|
|
85
87
|
}));
|
|
86
88
|
}
|
|
87
89
|
return p;
|
package/lib/index.d.ts
CHANGED
|
@@ -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 {
|
|
@@ -84,6 +85,14 @@ export declare function parseFromFiles(filepath: string, files: Promise<ECFile[]
|
|
|
84
85
|
* @deprecated
|
|
85
86
|
*/
|
|
86
87
|
export declare function parseFromFilesSync(filepath: string, files: ECFile[], options?: ParseOptions): Props;
|
|
88
|
+
/**
|
|
89
|
+
* For any pair, a value of `unset` removes the effect of that pair, even if
|
|
90
|
+
* it has been set before. This method modifies the properties object in
|
|
91
|
+
* place to remove any property that has a value of `unset`.
|
|
92
|
+
*
|
|
93
|
+
* @param props Properties object to modify.
|
|
94
|
+
*/
|
|
95
|
+
export declare function unset(props: Props): void;
|
|
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
|
@@ -26,7 +26,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
26
26
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
27
|
};
|
|
28
28
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
-
exports.parseSync = exports.parse = exports.parseFromFilesSync = exports.parseFromFiles = exports.parseString = exports.parseBuffer = void 0;
|
|
29
|
+
exports.matcher = exports.parseSync = exports.parse = exports.unset = exports.parseFromFilesSync = exports.parseFromFiles = exports.parseString = exports.parseBuffer = void 0;
|
|
30
30
|
const fs = __importStar(require("fs"));
|
|
31
31
|
const path = __importStar(require("path"));
|
|
32
32
|
const semver = __importStar(require("semver"));
|
|
@@ -36,17 +36,16 @@ const wasm_1 = require("@one-ini/wasm");
|
|
|
36
36
|
// package.json
|
|
37
37
|
const package_json_1 = __importDefault(require("../package.json"));
|
|
38
38
|
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
|
-
};
|
|
39
|
+
const matchOptions = { matchBase: true, dot: true };
|
|
40
|
+
const knownPropNames = [
|
|
41
|
+
'end_of_line',
|
|
42
|
+
'indent_style',
|
|
43
|
+
'indent_size',
|
|
44
|
+
'insert_final_newline',
|
|
45
|
+
'trim_trailing_whitespace',
|
|
46
|
+
'charset',
|
|
47
|
+
];
|
|
48
|
+
const knownProps = new Set(knownPropNames);
|
|
50
49
|
/**
|
|
51
50
|
* Parse a buffer using the faster one-ini WASM approach into something
|
|
52
51
|
* relatively easy to deal with in JS.
|
|
@@ -146,7 +145,7 @@ function processMatches(matches, version) {
|
|
|
146
145
|
function buildFullGlob(pathPrefix, glob) {
|
|
147
146
|
switch (glob.indexOf('/')) {
|
|
148
147
|
case -1:
|
|
149
|
-
glob =
|
|
148
|
+
glob = `**/${glob}`;
|
|
150
149
|
break;
|
|
151
150
|
case 0:
|
|
152
151
|
glob = glob.substring(1);
|
|
@@ -177,7 +176,7 @@ function normalizeProps(options) {
|
|
|
177
176
|
const value = options[key];
|
|
178
177
|
const key2 = key.toLowerCase();
|
|
179
178
|
let value2 = value;
|
|
180
|
-
if (knownProps
|
|
179
|
+
if (knownProps.has(key2)) {
|
|
181
180
|
// All of the values for the known props are lowercase.
|
|
182
181
|
value2 = String(value).toLowerCase();
|
|
183
182
|
}
|
|
@@ -355,6 +354,7 @@ function opts(filepath, options = {}) {
|
|
|
355
354
|
root: path.resolve(options.root || path.parse(resolvedFilePath).root),
|
|
356
355
|
files: options.files,
|
|
357
356
|
cache: options.cache,
|
|
357
|
+
unset: options.unset,
|
|
358
358
|
},
|
|
359
359
|
];
|
|
360
360
|
}
|
|
@@ -424,8 +424,27 @@ function combine(filepath, configs, options) {
|
|
|
424
424
|
}
|
|
425
425
|
return props;
|
|
426
426
|
}, {});
|
|
427
|
+
if (options.unset) {
|
|
428
|
+
unset(ret);
|
|
429
|
+
}
|
|
427
430
|
return processMatches(ret, options.version);
|
|
428
431
|
}
|
|
432
|
+
/**
|
|
433
|
+
* For any pair, a value of `unset` removes the effect of that pair, even if
|
|
434
|
+
* it has been set before. This method modifies the properties object in
|
|
435
|
+
* place to remove any property that has a value of `unset`.
|
|
436
|
+
*
|
|
437
|
+
* @param props Properties object to modify.
|
|
438
|
+
*/
|
|
439
|
+
function unset(props) {
|
|
440
|
+
const keys = Object.keys(props);
|
|
441
|
+
for (const k of keys) {
|
|
442
|
+
if (props[k] === 'unset') {
|
|
443
|
+
delete props[k];
|
|
444
|
+
}
|
|
445
|
+
}
|
|
446
|
+
}
|
|
447
|
+
exports.unset = unset;
|
|
429
448
|
/**
|
|
430
449
|
* Find all of the properties from matching sections in config files in the
|
|
431
450
|
* same directory or toward the root of the filesystem.
|
|
@@ -456,3 +475,25 @@ function parseSync(filepath, options = {}) {
|
|
|
456
475
|
return combine(resolvedFilePath, configs, processedOptions);
|
|
457
476
|
}
|
|
458
477
|
exports.parseSync = parseSync;
|
|
478
|
+
/**
|
|
479
|
+
* I think this may be of limited utility at the moment, but I need something
|
|
480
|
+
* like this for testing. As such, the interface of this may change without
|
|
481
|
+
* warning.
|
|
482
|
+
*
|
|
483
|
+
* Something this direction may be better for editors than the caching bits
|
|
484
|
+
* we've got today, but that will need some thought.
|
|
485
|
+
*
|
|
486
|
+
* @param options All options. root will be process.cwd if not specified.
|
|
487
|
+
* @param buffers 1 or more Buffers that have .editorconfig contents.
|
|
488
|
+
* @returns Function that can be called multiple times for different paths.
|
|
489
|
+
* @private
|
|
490
|
+
*/
|
|
491
|
+
function matcher(options, ...buffers) {
|
|
492
|
+
const processedOptions = opts('', options)[1];
|
|
493
|
+
const configs = buffers.map((buf, i) => processFileContents(path.join(processedOptions.root, `buffer-${i}`), buf, processedOptions));
|
|
494
|
+
return (filepath) => {
|
|
495
|
+
const resolvedFilePath = path.resolve(filepath);
|
|
496
|
+
return combine(resolvedFilePath, configs, processedOptions);
|
|
497
|
+
};
|
|
498
|
+
}
|
|
499
|
+
exports.matcher = matcher;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "editorconfig",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.0",
|
|
4
4
|
"description": "EditorConfig File Locator and Interpreter for Node.js",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"editorconfig",
|
|
@@ -41,25 +41,36 @@
|
|
|
41
41
|
"license": "MIT",
|
|
42
42
|
"dependencies": {
|
|
43
43
|
"@one-ini/wasm": "0.1.1",
|
|
44
|
-
"commander": "^
|
|
45
|
-
"minimatch": "
|
|
46
|
-
"semver": "^7.3
|
|
44
|
+
"commander": "^11.0.0",
|
|
45
|
+
"minimatch": "9.0.2",
|
|
46
|
+
"semver": "^7.5.3"
|
|
47
47
|
},
|
|
48
48
|
"devDependencies": {
|
|
49
|
+
"@types/chai": "4.3.5",
|
|
49
50
|
"@types/mocha": "^10.0.1",
|
|
50
|
-
"@types/node": "^
|
|
51
|
-
"@types/semver": "^7.
|
|
52
|
-
"@typescript-eslint/eslint-plugin": "5.
|
|
53
|
-
"@typescript-eslint/parser": "5.
|
|
54
|
-
"c8": "
|
|
55
|
-
"
|
|
56
|
-
"eslint
|
|
51
|
+
"@types/node": "^20.3.3",
|
|
52
|
+
"@types/semver": "^7.5.0",
|
|
53
|
+
"@typescript-eslint/eslint-plugin": "5.60.1",
|
|
54
|
+
"@typescript-eslint/parser": "5.60.1",
|
|
55
|
+
"c8": "8.0.0",
|
|
56
|
+
"chai": "4.3.7",
|
|
57
|
+
"eslint": "8.44.0",
|
|
58
|
+
"eslint-plugin-jsdoc": "46.4.3",
|
|
57
59
|
"mocha": "^10.2.0",
|
|
58
|
-
"rimraf": "^
|
|
59
|
-
"
|
|
60
|
-
|
|
60
|
+
"rimraf": "^5.0.1",
|
|
61
|
+
"typescript": "^5.1.6"
|
|
62
|
+
},
|
|
63
|
+
"pnpm": {
|
|
64
|
+
"overrides": {
|
|
65
|
+
"semver": ">=7.5.3",
|
|
66
|
+
"word-wrap": "npm:@aashutoshrathi/word-wrap"
|
|
67
|
+
}
|
|
68
|
+
},
|
|
69
|
+
"overrides": {
|
|
70
|
+
"semver": "$semver",
|
|
71
|
+
"word-wrap": "npm:@aashutoshrathi/word-wrap"
|
|
61
72
|
},
|
|
62
73
|
"engines": {
|
|
63
|
-
"node": ">=
|
|
74
|
+
"node": ">=16"
|
|
64
75
|
}
|
|
65
76
|
}
|