editorconfig 2.0.0 → 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.
@@ -0,0 +1,13 @@
1
+ import base from '@cto.af/eslint-config';
2
+ import ts from '@cto.af/eslint-config/ts.js';
3
+
4
+ export default [
5
+ {
6
+ ignores: [
7
+ 'lib/**',
8
+ '**/*.d.ts',
9
+ ],
10
+ },
11
+ ...base,
12
+ ...ts,
13
+ ];
package/lib/cli.d.ts CHANGED
@@ -1,5 +1,5 @@
1
+ import * as editorconfig from './index.js';
1
2
  import { type OutputConfiguration } from 'commander';
2
- import * as editorconfig from './';
3
3
  /**
4
4
  * Command line interface for editorconfig. Pulled out into a separate module
5
5
  * to make it easier to test.
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 (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
- };
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,13 +64,12 @@ async function cli(args, testing) {
53
64
  let writeOut = writeStdOut;
54
65
  if (testing) {
55
66
  if (testing.writeOut) {
56
- // eslint-disable-next-line @typescript-eslint/unbound-method
57
- writeOut = testing.writeOut;
67
+ ({ writeOut } = testing);
58
68
  }
59
69
  program.configureOutput(testing);
60
70
  program.exitOverride();
61
71
  }
62
- program.version('EditorConfig Node.js Core Version ' + package_json_1.default.version, '-v, --version', 'Display version information')
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\'')
@@ -88,7 +98,7 @@ async function cli(args, testing) {
88
98
  }
89
99
  return p;
90
100
  }
91
- return await processAll().then((parsed) => {
101
+ return processAll().then(parsed => {
92
102
  const header = parsed.length > 1;
93
103
  parsed.forEach((props, i) => {
94
104
  if (header) {
@@ -108,4 +118,3 @@ async function cli(args, testing) {
108
118
  return parsed;
109
119
  });
110
120
  }
111
- exports.default = cli;
package/lib/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- /// <reference types="node" />
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';
@@ -63,36 +63,36 @@ export declare function parseBuffer(data: Buffer): ParseStringResult;
63
63
  * @deprecated Use {@link ParseBuffer} instead.
64
64
  */
65
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;
66
74
  /**
67
75
  * Low-level interface, which exists only for backward-compatibility.
68
76
  * Deprecated.
69
77
  *
70
78
  * @param filepath The name of the target file, relative to process.cwd().
71
- * @param files A promise for a list of objects describing the files.
79
+ * @param files A list of objects describing the files.
72
80
  * @param options All options
73
81
  * @returns The properties found for filepath
74
82
  * @deprecated
75
83
  */
76
- export declare function parseFromFiles(filepath: string, files: Promise<ECFile[]>, options?: ParseOptions): Promise<Props>;
84
+ export declare function parseFromFilesSync(filepath: string, files: ECFile[], options?: ParseOptions): Props;
77
85
  /**
78
86
  * Low-level interface, which exists only for backward-compatibility.
79
87
  * Deprecated.
80
88
  *
81
89
  * @param filepath The name of the target file, relative to process.cwd().
82
- * @param files A list of objects describing the files.
90
+ * @param files A promise for a list of objects describing the files.
83
91
  * @param options All options
84
92
  * @returns The properties found for filepath
85
93
  * @deprecated
86
94
  */
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;
95
+ export declare function parseFromFiles(filepath: string, files: Promise<ECFile[]>, options?: ParseOptions): Promise<Props>;
96
96
  /**
97
97
  * Find all of the properties from matching sections in config files in the
98
98
  * same directory or toward the root of the filesystem.
package/lib/index.js CHANGED
@@ -15,25 +15,41 @@ 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 (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
- };
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.matcher = exports.parseSync = exports.parse = exports.unset = exports.parseFromFilesSync = exports.parseFromFiles = exports.parseString = exports.parseBuffer = void 0;
30
- const fs = __importStar(require("fs"));
31
- const path = __importStar(require("path"));
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
- // @ts-ignore So we can set the rootDir to be 'lib', without processing
36
- // package.json
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
55
  const matchOptions = { matchBase: true, dot: true };
@@ -81,7 +97,6 @@ function parseBuffer(data) {
81
97
  }
82
98
  return res;
83
99
  }
84
- exports.parseBuffer = parseBuffer;
85
100
  /**
86
101
  * Parses a string. If possible, you should always use ParseBuffer instead,
87
102
  * since this function does a UTF16-to-UTF8 conversion first.
@@ -91,9 +106,8 @@ exports.parseBuffer = parseBuffer;
91
106
  * @deprecated Use {@link ParseBuffer} instead.
92
107
  */
93
108
  function parseString(data) {
94
- return parseBuffer(Buffer.from(data));
109
+ return parseBuffer(node_buffer_1.Buffer.from(data));
95
110
  }
96
- exports.parseString = parseString;
97
111
  /**
98
112
  * Gets a list of *potential* filenames based on the path of the target
99
113
  * filename.
@@ -121,23 +135,23 @@ function getConfigFileNames(filepath, options) {
121
135
  function processMatches(matches, version) {
122
136
  // Set indent_size to 'tab' if indent_size is unspecified and
123
137
  // indent_style is set to 'tab'.
124
- if ('indent_style' in matches
125
- && matches.indent_style === 'tab'
126
- && !('indent_size' in matches)
127
- && semver.gte(version, '0.10.0')) {
138
+ if ('indent_style' in matches &&
139
+ matches.indent_style === 'tab' &&
140
+ !('indent_size' in matches) &&
141
+ semver.gte(version, '0.10.0')) {
128
142
  matches.indent_size = 'tab';
129
143
  }
130
144
  // Set tab_width to indent_size if indent_size is specified and
131
145
  // tab_width is unspecified
132
- if ('indent_size' in matches
133
- && !('tab_width' in matches)
134
- && matches.indent_size !== 'tab') {
146
+ if ('indent_size' in matches &&
147
+ !('tab_width' in matches) &&
148
+ matches.indent_size !== 'tab') {
135
149
  matches.tab_width = matches.indent_size;
136
150
  }
137
151
  // Set indent_size to tab_width if indent_size is 'tab'
138
- if ('indent_size' in matches
139
- && 'tab_width' in matches
140
- && matches.indent_size === 'tab') {
152
+ if ('indent_size' in matches &&
153
+ 'tab_width' in matches &&
154
+ matches.indent_size === 'tab') {
141
155
  matches.indent_size = matches.tab_width;
142
156
  }
143
157
  return matches;
@@ -153,9 +167,11 @@ function buildFullGlob(pathPrefix, glob) {
153
167
  default:
154
168
  break;
155
169
  }
170
+ //
156
171
  // braces_escaped_backslash2
157
172
  // backslash_not_on_windows
158
173
  glob = glob.replace(/\\\\/g, '\\\\\\\\');
174
+ //
159
175
  // star_star_over_separator{1,3,5,6,9,15}
160
176
  glob = glob.replace(/\*\*/g, '{*,**/**/**}');
161
177
  // NOT path.join. Must stay in forward slashes.
@@ -172,7 +188,7 @@ function buildFullGlob(pathPrefix, glob) {
172
188
  function normalizeProps(options) {
173
189
  const props = {};
174
190
  for (const key in options) {
175
- if (options.hasOwnProperty(key)) {
191
+ if (Object.prototype.hasOwnProperty.call(options, key)) {
176
192
  const value = options[key];
177
193
  const key2 = key.toLowerCase();
178
194
  let value2 = value;
@@ -183,8 +199,11 @@ function normalizeProps(options) {
183
199
  try {
184
200
  value2 = JSON.parse(String(value));
185
201
  }
186
- catch (e) { }
202
+ catch (_e) {
203
+ // Ignored
204
+ }
187
205
  if (typeof value2 === 'undefined' || value2 === null) {
206
+ //
188
207
  // null and undefined are values specific to JSON (no special meaning
189
208
  // in editorconfig) & should just be returned as regular strings.
190
209
  value2 = String(value);
@@ -205,7 +224,8 @@ function normalizeProps(options) {
205
224
  * @returns Processed file with globs pre-computed.
206
225
  */
207
226
  function processFileContents(filepath, contents, options) {
208
- let res;
227
+ let res = undefined;
228
+ // eslint-disable-next-line no-negated-condition
209
229
  if (!contents) {
210
230
  // Negative cache
211
231
  res = {
@@ -236,7 +256,7 @@ function processFileContents(filepath, contents, options) {
236
256
  name ? buildFullGlob(pathPrefix, name) : null,
237
257
  ]);
238
258
  res = {
239
- root: !!globbed[0][1].root,
259
+ root: Boolean(globbed[0][1].root), // Global section: globbed[0]
240
260
  name: filepath,
241
261
  config: globbed,
242
262
  };
@@ -285,7 +305,7 @@ function getConfigSync(filepath, options) {
285
305
  return cached;
286
306
  }
287
307
  }
288
- let contents;
308
+ let contents = undefined;
289
309
  try {
290
310
  contents = fs.readFileSync(filepath);
291
311
  }
@@ -359,47 +379,21 @@ function opts(filepath, options = {}) {
359
379
  ];
360
380
  }
361
381
  /**
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.
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`.
378
385
  *
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
386
+ * @param props Properties object to modify.
384
387
  */
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;
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];
398
394
  }
399
395
  }
400
- return combine(resolvedFilePath, configs, processedOptions);
401
396
  }
402
- exports.parseFromFilesSync = parseFromFilesSync;
403
397
  /**
404
398
  * Combine the pre-parsed results of all matching config file sections, in
405
399
  * order.
@@ -412,7 +406,7 @@ exports.parseFromFilesSync = parseFromFilesSync;
412
406
  function combine(filepath, configs, options) {
413
407
  const ret = configs.reverse().reduce((props, processed) => {
414
408
  for (const [name, body, glob] of processed.config) {
415
- if (glob && glob.match(filepath)) {
409
+ if (glob === null || glob === void 0 ? void 0 : glob.match(filepath)) {
416
410
  Object.assign(props, body);
417
411
  if (options.files) {
418
412
  options.files.push({
@@ -430,21 +424,46 @@ function combine(filepath, configs, options) {
430
424
  return processMatches(ret, options.version);
431
425
  }
432
426
  /**
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`.
427
+ * Low-level interface, which exists only for backward-compatibility.
428
+ * Deprecated.
436
429
  *
437
- * @param props Properties object to modify.
430
+ * @param filepath The name of the target file, relative to process.cwd().
431
+ * @param files A list of objects describing the files.
432
+ * @param options All options
433
+ * @returns The properties found for filepath
434
+ * @deprecated
438
435
  */
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];
436
+ function parseFromFilesSync(filepath, files, options = {}) {
437
+ const [resolvedFilePath, processedOptions] = opts(filepath, options);
438
+ const configs = [];
439
+ for (const ecf of files) {
440
+ let cfg = undefined;
441
+ if (!options.cache || !(cfg = options.cache.get(ecf.name))) { // Single "="!
442
+ cfg = processFileContents(ecf.name, ecf.contents, processedOptions);
443
+ }
444
+ if (!cfg.notfound) {
445
+ configs.push(cfg);
446
+ }
447
+ if (cfg.root) {
448
+ break;
444
449
  }
445
450
  }
451
+ return combine(resolvedFilePath, configs, processedOptions);
452
+ }
453
+ /**
454
+ * Low-level interface, which exists only for backward-compatibility.
455
+ * Deprecated.
456
+ *
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
462
+ */
463
+ async function parseFromFiles(filepath, files, options = {}) {
464
+ // eslint-disable-next-line @typescript-eslint/no-deprecated
465
+ return parseFromFilesSync(filepath, await files, options);
446
466
  }
447
- exports.unset = unset;
448
467
  /**
449
468
  * Find all of the properties from matching sections in config files in the
450
469
  * same directory or toward the root of the filesystem.
@@ -459,7 +478,6 @@ async function parse(filepath, options = {}) {
459
478
  const configs = await getAllConfigs(filepaths, processedOptions);
460
479
  return combine(resolvedFilePath, configs, processedOptions);
461
480
  }
462
- exports.parse = parse;
463
481
  /**
464
482
  * Find all of the properties from matching sections in config files in the
465
483
  * same directory or toward the root of the filesystem. Synchronous.
@@ -474,7 +492,6 @@ function parseSync(filepath, options = {}) {
474
492
  const configs = getAllConfigsSync(filepaths, processedOptions);
475
493
  return combine(resolvedFilePath, configs, processedOptions);
476
494
  }
477
- exports.parseSync = parseSync;
478
495
  /**
479
496
  * I think this may be of limited utility at the moment, but I need something
480
497
  * like this for testing. As such, the interface of this may change without
@@ -489,11 +506,10 @@ exports.parseSync = parseSync;
489
506
  * @private
490
507
  */
491
508
  function matcher(options, ...buffers) {
492
- const processedOptions = opts('', options)[1];
509
+ const [_fileName, processedOptions] = opts('', options);
493
510
  const configs = buffers.map((buf, i) => processFileContents(path.join(processedOptions.root, `buffer-${i}`), buf, processedOptions));
494
511
  return (filepath) => {
495
512
  const resolvedFilePath = path.resolve(filepath);
496
513
  return combine(resolvedFilePath, configs, processedOptions);
497
514
  };
498
515
  }
499
- exports.matcher = matcher;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "editorconfig",
3
- "version": "2.0.0",
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,37 +25,12 @@
40
25
  "author": "EditorConfig Team",
41
26
  "license": "MIT",
42
27
  "dependencies": {
43
- "@one-ini/wasm": "0.1.1",
44
- "commander": "^11.0.0",
45
- "minimatch": "9.0.2",
46
- "semver": "^7.5.3"
47
- },
48
- "devDependencies": {
49
- "@types/chai": "4.3.5",
50
- "@types/mocha": "^10.0.1",
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",
59
- "mocha": "^10.2.0",
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"
28
+ "@one-ini/wasm": "0.2.0",
29
+ "commander": "^13.1.0",
30
+ "minimatch": "10.0.1",
31
+ "semver": "^7.7.1"
72
32
  },
73
33
  "engines": {
74
- "node": ">=16"
34
+ "node": ">=18"
75
35
  }
76
36
  }