markdownlint-cli2 0.16.0 → 0.17.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.
@@ -1,38 +1,30 @@
1
- #!/usr/bin/env node
2
-
3
- // @ts-check
4
-
5
- "use strict";
6
-
7
1
  // @ts-ignore
8
- // eslint-disable-next-line camelcase, no-inline-comments, no-undef
9
- const dynamicRequire = (typeof __non_webpack_require__ === "undefined") ? require : /* c8 ignore next */ __non_webpack_require__;
10
- // Capture native require implementation for dynamic loading of modules
11
2
 
12
- // Requires
13
- const pathDefault = require("node:path");
3
+ // Imports
4
+ import fsNode from "node:fs";
5
+ import { createRequire } from "node:module";
6
+ const dynamicRequire = createRequire(import.meta.url);
7
+ import os from "node:os";
8
+ import pathDefault from "node:path";
14
9
  const pathPosix = pathDefault.posix;
15
- const { pathToFileURL } = require("node:url");
16
- const markdownlintLibrary = require("markdownlint");
17
- const {
18
- applyFixes,
19
- "getVersion": getLibraryVersion,
20
- "promises": markdownlintPromises
21
- } = markdownlintLibrary;
22
- const {
23
- markdownlint,
24
- "extendConfig": markdownlintExtendConfig,
25
- "readConfig": markdownlintReadConfig
26
- } = markdownlintPromises;
27
- const appendToArray = require("./append-to-array");
28
- const mergeOptions = require("./merge-options");
29
- const resolveAndRequire = require("./resolve-and-require");
10
+ import { pathToFileURL } from "node:url";
11
+ import { globby } from "globby";
12
+ import micromatch from "micromatch";
13
+ import { applyFixes, getVersion } from "markdownlint";
14
+ import { lint, extendConfig, readConfig } from "markdownlint/promise";
15
+ import { expandTildePath } from "markdownlint/helpers";
16
+ import appendToArray from "./append-to-array.mjs";
17
+ import mergeOptions from "./merge-options.mjs";
18
+ import resolveModule from "./resolve-module.mjs";
19
+ import parsers from "./parsers/parsers.mjs";
20
+ import jsoncParse from "./parsers/jsonc-parse.mjs";
21
+ import yamlParse from "./parsers/yaml-parse.mjs";
30
22
 
31
23
  // Variables
32
24
  const packageName = "markdownlint-cli2";
33
- const packageVersion = "0.16.0";
25
+ const packageVersion = "0.17.0";
34
26
  const libraryName = "markdownlint";
35
- const libraryVersion = getLibraryVersion();
27
+ const libraryVersion = getVersion();
36
28
  const bannerMessage = `${packageName} v${packageVersion} (${libraryName} v${libraryVersion})`;
37
29
  const dotOnlySubstitute = "*.{md,markdown}";
38
30
  const utf8 = "utf8";
@@ -40,15 +32,6 @@ const utf8 = "utf8";
40
32
  // No-op function
41
33
  const noop = () => null;
42
34
 
43
- // Gets a JSONC parser
44
- const getJsoncParse = () => require("./parsers/jsonc-parse.js");
45
-
46
- // Gets a YAML parser
47
- const getYamlParse = () => require("./parsers/yaml-parse.js");
48
-
49
- // Gets an ordered array of parsers
50
- const getParsers = () => require("./parsers/parsers.js");
51
-
52
35
  // Negates a glob
53
36
  const negateGlob = (glob) => `!${glob}`;
54
37
 
@@ -63,98 +46,84 @@ const throwForConfigurationFile = (file, error) => {
63
46
  // Return a posix path (even on Windows)
64
47
  const posixPath = (p) => p.split(pathDefault.sep).join(pathPosix.sep);
65
48
 
66
- // Expands a path with a tilde to an absolute path
67
- const expandTildePath = (id) => {
68
- const markdownlintRuleHelpers = require("markdownlint/helpers");
69
- return markdownlintRuleHelpers.expandTildePath(id, require("node:os"));
70
- };
71
-
72
49
  // Resolves module paths relative to the specified directory
73
50
  const resolveModulePaths = (dir, modulePaths) => (
74
- modulePaths.map((path) => pathDefault.resolve(dir, expandTildePath(path)))
51
+ modulePaths.map((path) => pathDefault.resolve(dir, expandTildePath(path, os)))
75
52
  );
76
53
 
77
54
  // Read a JSON(C) or YAML file and return the object
78
- const readConfig = (fs, dir, name, otherwise) => () => {
55
+ const readConfigFile = (fs, dir, name, otherwise) => () => {
79
56
  const file = pathPosix.join(dir, name);
80
57
  return fs.promises.access(file).
81
58
  then(
82
- () => markdownlintReadConfig(
59
+ () => readConfig(
83
60
  file,
84
- getParsers(),
61
+ parsers,
85
62
  fs
86
63
  ),
87
64
  otherwise
88
65
  );
89
66
  };
90
67
 
91
- // Import or resolve/require a module ID with a custom directory in the path
92
- const importOrRequireResolve = async (dirOrDirs, id, noRequire) => {
93
- if (typeof id === "string") {
94
- if (noRequire) {
95
- return null;
96
- }
97
- const dirs = Array.isArray(dirOrDirs) ? dirOrDirs : [ dirOrDirs ];
98
- const expandId = expandTildePath(id);
99
- const errors = [];
100
- // Try to load via require(...)
101
- try {
102
- const isModule = /\.mjs$/iu.test(expandId);
103
- if (!isModule) {
104
- // Try not to use require for modules due to breaking change in Node 22.12:
105
- // https://github.com/nodejs/node/releases/tag/v22.12.0
106
- return resolveAndRequire(dynamicRequire, expandId, dirs);
107
- }
108
- } catch (error) {
109
- errors.push(error);
110
- }
111
- // Try to load via import(...)
68
+ // Import a module ID with a custom directory in the path
69
+ const importModule = async (dirOrDirs, id, noImport) => {
70
+ if (typeof id !== "string") {
71
+ return id;
72
+ } else if (noImport) {
73
+ return null;
74
+ }
75
+ const dirs = Array.isArray(dirOrDirs) ? dirOrDirs : [ dirOrDirs ];
76
+ const expandId = expandTildePath(id, os);
77
+ const errors = [];
78
+ let moduleName = null;
79
+ try {
112
80
  try {
113
- // eslint-disable-next-line n/no-unsupported-features/node-builtins
114
- const isURL = !pathDefault.isAbsolute(expandId) && URL.canParse(expandId);
115
- const urlString = (
116
- isURL ? new URL(expandId) : pathToFileURL(pathDefault.resolve(dirs[0], expandId))
117
- ).toString();
118
- // eslint-disable-next-line no-inline-comments
119
- const module = await import(/* webpackIgnore: true */ urlString);
120
- return module.default;
81
+ moduleName = pathToFileURL(resolveModule(dynamicRequire, expandId, dirs));
121
82
  } catch (error) {
122
83
  errors.push(error);
84
+ moduleName =
85
+ // eslint-disable-next-line n/no-unsupported-features/node-builtins
86
+ (!pathDefault.isAbsolute(expandId) && URL.canParse(expandId))
87
+ ? new URL(expandId)
88
+ : pathToFileURL(pathDefault.resolve(dirs[0], expandId));
123
89
  }
124
- // Give up
90
+ // eslint-disable-next-line no-inline-comments
91
+ const module = await import(/* webpackIgnore: true */ moduleName);
92
+ return module.default;
93
+ } catch (error) {
94
+ errors.push(error);
125
95
  throw new AggregateError(
126
96
  errors,
127
- `Unable to require or import module '${id}'.`
97
+ `Unable to import module '${id}'.`
128
98
  );
129
99
  }
130
- return id;
131
100
  };
132
101
 
133
- // Import or require an array of modules by ID
134
- const importOrRequireIds = (dirs, ids, noRequire) => (
102
+ // Import an array of modules by ID
103
+ const importModuleIds = (dirs, ids, noImport) => (
135
104
  Promise.all(
136
105
  ids.map(
137
- (id) => importOrRequireResolve(dirs, id, noRequire)
106
+ (id) => importModule(dirs, id, noImport)
138
107
  )
139
108
  ).then((results) => results.filter(Boolean))
140
109
  );
141
110
 
142
- // Import or require an array of modules by ID (preserving parameters)
143
- const importOrRequireIdsAndParams = (dirs, idsAndParams, noRequire) => (
111
+ // Import an array of modules by ID (preserving parameters)
112
+ const importModuleIdsAndParams = (dirs, idsAndParams, noImport) => (
144
113
  Promise.all(
145
114
  idsAndParams.map(
146
- (idAndParams) => importOrRequireResolve(dirs, idAndParams[0], noRequire).
115
+ (idAndParams) => importModule(dirs, idAndParams[0], noImport).
147
116
  then((module) => module && [ module, ...idAndParams.slice(1) ])
148
117
  )
149
118
  ).then((results) => results.filter(Boolean))
150
119
  );
151
120
 
152
- // Import or require a JavaScript file and return the exported object
153
- const importOrRequireConfig = (fs, dir, name, noRequire, otherwise) => () => {
121
+ // Import a JavaScript file and return the exported object
122
+ const importConfig = (fs, dir, name, noImport, otherwise) => () => {
154
123
  const file = pathPosix.join(dir, name);
155
124
  return fs.promises.access(file).
156
125
  then(
157
- () => importOrRequireResolve(dir, name, noRequire),
126
+ () => importModule(dir, name, noImport),
158
127
  otherwise
159
128
  );
160
129
  };
@@ -162,10 +131,10 @@ const importOrRequireConfig = (fs, dir, name, noRequire, otherwise) => () => {
162
131
  // Extend a config object if it has 'extends' property
163
132
  const getExtendedConfig = (config, configPath, fs) => {
164
133
  if (config.extends) {
165
- return markdownlintExtendConfig(
134
+ return extendConfig(
166
135
  config,
167
136
  configPath,
168
- getParsers(),
137
+ parsers,
169
138
  fs
170
139
  );
171
140
  }
@@ -174,37 +143,38 @@ const getExtendedConfig = (config, configPath, fs) => {
174
143
  };
175
144
 
176
145
  // Read an options or config file in any format and return the object
177
- const readOptionsOrConfig = async (configPath, fs, noRequire) => {
146
+ const readOptionsOrConfig = async (configPath, fs, noImport) => {
178
147
  const basename = pathPosix.basename(configPath);
179
148
  const dirname = pathPosix.dirname(configPath);
180
149
  let options = null;
181
150
  let config = null;
182
151
  try {
183
152
  if (basename.endsWith(".markdownlint-cli2.jsonc")) {
184
- options = getJsoncParse()(await fs.promises.readFile(configPath, utf8));
153
+ options = jsoncParse(await fs.promises.readFile(configPath, utf8));
185
154
  } else if (basename.endsWith(".markdownlint-cli2.yaml")) {
186
- options = getYamlParse()(await fs.promises.readFile(configPath, utf8));
155
+ options = yamlParse(await fs.promises.readFile(configPath, utf8));
187
156
  } else if (
188
157
  basename.endsWith(".markdownlint-cli2.cjs") ||
189
158
  basename.endsWith(".markdownlint-cli2.mjs")
190
159
  ) {
191
- options = await importOrRequireResolve(dirname, basename, noRequire);
160
+ options = await importModule(dirname, basename, noImport);
192
161
  } else if (
193
162
  basename.endsWith(".markdownlint.jsonc") ||
194
163
  basename.endsWith(".markdownlint.json") ||
195
164
  basename.endsWith(".markdownlint.yaml") ||
196
165
  basename.endsWith(".markdownlint.yml")
197
166
  ) {
198
- config = await markdownlintReadConfig(configPath, getParsers(), fs);
167
+ config = await readConfig(configPath, parsers, fs);
199
168
  } else if (
200
169
  basename.endsWith(".markdownlint.cjs") ||
201
170
  basename.endsWith(".markdownlint.mjs")
202
171
  ) {
203
- config = await importOrRequireResolve(dirname, basename, noRequire);
172
+ config = await importModule(dirname, basename, noImport);
204
173
  } else {
205
174
  throw new Error(
206
- "File name should be (or end with) one of the supported types " +
207
- "(e.g., '.markdownlint.json' or 'example.markdownlint-cli2.jsonc')."
175
+ "Configuration file should be one of the supported names " +
176
+ "(e.g., '.markdownlint-cli2.jsonc') or a prefix with a supported name " +
177
+ "(e.g., 'example.markdownlint-cli2.jsonc')."
208
178
  );
209
179
  }
210
180
  } catch (error) {
@@ -221,13 +191,12 @@ const readOptionsOrConfig = async (configPath, fs, noRequire) => {
221
191
  };
222
192
 
223
193
  // Filter a list of files to ignore by glob
224
- const removeIgnoredFiles = (dir, files, ignores) => {
225
- const micromatch = require("micromatch");
226
- return micromatch(
194
+ const removeIgnoredFiles = (dir, files, ignores) => (
195
+ micromatch(
227
196
  files.map((file) => pathPosix.relative(dir, file)),
228
197
  ignores
229
- ).map((file) => pathPosix.join(dir, file));
230
- };
198
+ ).map((file) => pathPosix.join(dir, file))
199
+ );
231
200
 
232
201
  // Process/normalize command-line arguments and return glob patterns
233
202
  const processArgv = (argv) => {
@@ -312,7 +281,7 @@ const getAndProcessDirInfo = (
312
281
  dirToDirInfo,
313
282
  dir,
314
283
  relativeDir,
315
- noRequire,
284
+ noImport,
316
285
  allowPackageJson
317
286
  ) => {
318
287
  // Create dirInfo
@@ -340,16 +309,16 @@ const getAndProcessDirInfo = (
340
309
  tasks.push(
341
310
  fs.promises.access(captureFile(markdownlintCli2Jsonc)).
342
311
  then(
343
- () => fs.promises.readFile(file, utf8).then(getJsoncParse()),
312
+ () => fs.promises.readFile(file, utf8).then(jsoncParse),
344
313
  () => fs.promises.access(captureFile(markdownlintCli2Yaml)).
345
314
  then(
346
- () => fs.promises.readFile(file, utf8).then(getYamlParse()),
315
+ () => fs.promises.readFile(file, utf8).then(yamlParse),
347
316
  () => fs.promises.access(captureFile(markdownlintCli2Cjs)).
348
317
  then(
349
- () => importOrRequireResolve(dir, file, noRequire),
318
+ () => importModule(dir, file, noImport),
350
319
  () => fs.promises.access(captureFile(markdownlintCli2Mjs)).
351
320
  then(
352
- () => importOrRequireResolve(dir, file, noRequire),
321
+ () => importModule(dir, file, noImport),
353
322
  () => (allowPackageJson
354
323
  ? fs.promises.access(captureFile(packageJson))
355
324
  // eslint-disable-next-line prefer-promise-reject-errors
@@ -358,7 +327,7 @@ const getAndProcessDirInfo = (
358
327
  then(
359
328
  () => fs.promises.
360
329
  readFile(file, utf8).
361
- then(getJsoncParse()).
330
+ then(jsoncParse).
362
331
  then((obj) => obj[packageName]),
363
332
  noop
364
333
  )
@@ -387,32 +356,32 @@ const getAndProcessDirInfo = (
387
356
 
388
357
  // Load markdownlint object(s)
389
358
  const readConfigs =
390
- readConfig(
359
+ readConfigFile(
391
360
  fs,
392
361
  dir,
393
362
  ".markdownlint.jsonc",
394
- readConfig(
363
+ readConfigFile(
395
364
  fs,
396
365
  dir,
397
366
  ".markdownlint.json",
398
- readConfig(
367
+ readConfigFile(
399
368
  fs,
400
369
  dir,
401
370
  ".markdownlint.yaml",
402
- readConfig(
371
+ readConfigFile(
403
372
  fs,
404
373
  dir,
405
374
  ".markdownlint.yml",
406
- importOrRequireConfig(
375
+ importConfig(
407
376
  fs,
408
377
  dir,
409
378
  ".markdownlint.cjs",
410
- noRequire,
411
- importOrRequireConfig(
379
+ noImport,
380
+ importConfig(
412
381
  fs,
413
382
  dir,
414
383
  ".markdownlint.mjs",
415
- noRequire,
384
+ noImport,
416
385
  noop
417
386
  )
418
387
  )
@@ -441,7 +410,7 @@ const getBaseOptions = async (
441
410
  options,
442
411
  fixDefault,
443
412
  noGlobs,
444
- noRequire
413
+ noImport
445
414
  ) => {
446
415
  const tasks = [];
447
416
  const dirToDirInfo = {};
@@ -451,7 +420,7 @@ const getBaseOptions = async (
451
420
  dirToDirInfo,
452
421
  baseDir,
453
422
  relativeDir,
454
- noRequire,
423
+ noImport,
455
424
  true
456
425
  );
457
426
  await Promise.all(tasks);
@@ -492,7 +461,7 @@ const enumerateFiles = async (
492
461
  dirToDirInfo,
493
462
  gitignore,
494
463
  ignoreFiles,
495
- noRequire
464
+ noImport
496
465
  ) => {
497
466
  const tasks = [];
498
467
  /** @type {import("globby").Options} */
@@ -548,8 +517,6 @@ const enumerateFiles = async (
548
517
  })
549
518
  );
550
519
  // Process glob patterns
551
- // eslint-disable-next-line no-inline-comments
552
- const { globby } = await import(/* webpackMode: "eager" */ "globby");
553
520
  const files = [
554
521
  ...await globby(expandedDirectories, globbyOptions),
555
522
  ...filteredLiteralFiles
@@ -562,7 +529,7 @@ const enumerateFiles = async (
562
529
  dirToDirInfo,
563
530
  dir,
564
531
  null,
565
- noRequire,
532
+ noImport,
566
533
  false
567
534
  );
568
535
  dirInfo.files.push(file);
@@ -575,7 +542,7 @@ const enumerateParents = async (
575
542
  fs,
576
543
  baseDir,
577
544
  dirToDirInfo,
578
- noRequire
545
+ noImport
579
546
  ) => {
580
547
  const tasks = [];
581
548
 
@@ -604,7 +571,7 @@ const enumerateParents = async (
604
571
  dirToDirInfo,
605
572
  dir,
606
573
  null,
607
- noRequire,
574
+ noImport,
608
575
  false
609
576
  );
610
577
  lastDirInfo.parent = dirInfo;
@@ -629,7 +596,7 @@ const createDirInfos = async (
629
596
  optionsOverride,
630
597
  gitignore,
631
598
  ignoreFiles,
632
- noRequire
599
+ noImport
633
600
  ) => {
634
601
  await enumerateFiles(
635
602
  fs,
@@ -639,13 +606,13 @@ const createDirInfos = async (
639
606
  dirToDirInfo,
640
607
  gitignore,
641
608
  ignoreFiles,
642
- noRequire
609
+ noImport
643
610
  );
644
611
  await enumerateParents(
645
612
  fs,
646
613
  baseDir,
647
614
  dirToDirInfo,
648
- noRequire
615
+ noImport
649
616
  );
650
617
 
651
618
  // Merge file lists with identical configuration
@@ -676,10 +643,10 @@ const createDirInfos = async (
676
643
  );
677
644
  if (markdownlintOptions && markdownlintOptions.customRules) {
678
645
  tasks.push(
679
- importOrRequireIds(
646
+ importModuleIds(
680
647
  [ effectiveDir, ...effectiveModulePaths ],
681
648
  markdownlintOptions.customRules,
682
- noRequire
649
+ noImport
683
650
  ).then((customRules) => {
684
651
  // Expand nested arrays (for packages that export multiple rules)
685
652
  markdownlintOptions.customRules = customRules.flat();
@@ -688,10 +655,10 @@ const createDirInfos = async (
688
655
  }
689
656
  if (markdownlintOptions && markdownlintOptions.markdownItPlugins) {
690
657
  tasks.push(
691
- importOrRequireIdsAndParams(
658
+ importModuleIdsAndParams(
692
659
  [ effectiveDir, ...effectiveModulePaths ],
693
660
  markdownlintOptions.markdownItPlugins,
694
- noRequire
661
+ noImport
695
662
  ).then((markdownItPlugins) => {
696
663
  markdownlintOptions.markdownItPlugins = markdownItPlugins;
697
664
  })
@@ -797,7 +764,7 @@ const lintFiles = (fs, dirInfos, fileContents) => {
797
764
  "files": filteredFiles,
798
765
  "strings": filteredStrings,
799
766
  "config": markdownlintConfig || markdownlintOptions.config,
800
- "configParsers": getParsers(),
767
+ "configParsers": parsers,
801
768
  "customRules": markdownlintOptions.customRules,
802
769
  "frontMatter": markdownlintOptions.frontMatter
803
770
  ? new RegExp(markdownlintOptions.frontMatter, "u")
@@ -805,11 +772,10 @@ const lintFiles = (fs, dirInfos, fileContents) => {
805
772
  "handleRuleFailures": true,
806
773
  "markdownItPlugins": markdownlintOptions.markdownItPlugins,
807
774
  "noInlineConfig": Boolean(markdownlintOptions.noInlineConfig),
808
- "resultVersion": 3,
809
775
  fs
810
776
  };
811
777
  // Invoke markdownlint
812
- let task = markdownlint(options);
778
+ let task = lint(options);
813
779
  // For any fixable errors, read file, apply fixes, and write it back
814
780
  if (markdownlintOptions.fix) {
815
781
  task = task.then((results) => {
@@ -832,7 +798,7 @@ const lintFiles = (fs, dirInfos, fileContents) => {
832
798
  }
833
799
  }
834
800
  return Promise.all(subTasks).
835
- then(() => markdownlint(options)).
801
+ then(() => lint(options)).
836
802
  then((fixResults) => ({
837
803
  ...results,
838
804
  ...fixResults
@@ -885,7 +851,7 @@ const outputSummary = async (
885
851
  modulePaths,
886
852
  logMessage,
887
853
  logError,
888
- noRequire
854
+ noImport
889
855
  ) => {
890
856
  const errorsPresent = (summary.length > 0);
891
857
  if (errorsPresent || outputFormatters) {
@@ -898,8 +864,9 @@ const outputSummary = async (
898
864
  const dir = relativeDir || baseDir;
899
865
  const dirs = [ dir, ...modulePaths ];
900
866
  const formattersAndParams = outputFormatters
901
- ? await importOrRequireIdsAndParams(dirs, outputFormatters, noRequire)
902
- : [ [ require("markdownlint-cli2-formatter-default") ] ];
867
+ ? await importModuleIdsAndParams(dirs, outputFormatters, noImport)
868
+ // eslint-disable-next-line no-inline-comments, unicorn/no-await-expression-member
869
+ : [ [ (await import(/* webpackMode: "eager" */ "markdownlint-cli2-formatter-default")).default ] ];
903
870
  await Promise.all(formattersAndParams.map((formatterAndParams) => {
904
871
  const [ formatter, ...formatterParams ] = formatterAndParams;
905
872
  return formatter(formatterOptions, ...formatterParams);
@@ -909,7 +876,7 @@ const outputSummary = async (
909
876
  };
910
877
 
911
878
  // Main function
912
- const main = async (params) => {
879
+ export const main = async (params) => {
913
880
  // Capture parameters
914
881
  const {
915
882
  directory,
@@ -917,7 +884,7 @@ const main = async (params) => {
917
884
  optionsDefault,
918
885
  optionsOverride,
919
886
  fileContents,
920
- noRequire,
887
+ noImport,
921
888
  allowStdin
922
889
  } = params;
923
890
  let {
@@ -926,7 +893,7 @@ const main = async (params) => {
926
893
  } = params;
927
894
  const logMessage = params.logMessage || noop;
928
895
  const logError = params.logError || noop;
929
- const fs = params.fs || require("node:fs");
896
+ const fs = params.fs || fsNode;
930
897
  const baseDirSystem =
931
898
  (directory && pathDefault.resolve(directory)) ||
932
899
  process.cwd();
@@ -974,7 +941,7 @@ const main = async (params) => {
974
941
  const resolvedConfigPath =
975
942
  posixPath(pathDefault.resolve(baseDirSystem, configPath));
976
943
  optionsArgv =
977
- await readOptionsOrConfig(resolvedConfigPath, fs, noRequire);
944
+ await readOptionsOrConfig(resolvedConfigPath, fs, noImport);
978
945
  relativeDir = pathPosix.dirname(resolvedConfigPath);
979
946
  }
980
947
  // Process arguments and get base options
@@ -987,7 +954,7 @@ const main = async (params) => {
987
954
  optionsArgv || optionsDefault,
988
955
  fixDefault,
989
956
  noGlobs,
990
- noRequire
957
+ noImport
991
958
  );
992
959
  } finally {
993
960
  if (!baseOptions?.baseMarkdownlintOptions.noBanner) {
@@ -1003,7 +970,7 @@ const main = async (params) => {
1003
970
  // Add stdin as a non-file input if necessary
1004
971
  if (useStdin) {
1005
972
  const key = pathPosix.join(baseDir, "stdin");
1006
- const { text } = require("node:stream/consumers");
973
+ const { text } = await import("node:stream/consumers");
1007
974
  nonFileContents = {
1008
975
  ...nonFileContents,
1009
976
  [key]: await text(process.stdin)
@@ -1046,7 +1013,7 @@ const main = async (params) => {
1046
1013
  optionsOverride,
1047
1014
  gitignore,
1048
1015
  ignoreFiles,
1049
- noRequire
1016
+ noImport
1050
1017
  );
1051
1018
  // Output linting status
1052
1019
  if (showProgress) {
@@ -1084,32 +1051,8 @@ const main = async (params) => {
1084
1051
  modulePaths,
1085
1052
  logMessage,
1086
1053
  logError,
1087
- noRequire
1054
+ noImport
1088
1055
  );
1089
1056
  // Return result
1090
1057
  return errorsPresent ? 1 : 0;
1091
1058
  };
1092
-
1093
- // Export functions
1094
- module.exports = {
1095
- main
1096
- };
1097
-
1098
- // Run if invoked as a CLI
1099
- if (require.main === module) {
1100
- const params = {
1101
- "argv": process.argv.slice(2),
1102
- "logMessage": console.log,
1103
- "logError": console.error,
1104
- "allowStdin": true
1105
- };
1106
- main(params).
1107
- then((exitCode) => {
1108
- process.exitCode = exitCode;
1109
- }).
1110
- // eslint-disable-next-line unicorn/prefer-top-level-await
1111
- catch((error) => {
1112
- console.error(error);
1113
- process.exitCode = 2;
1114
- });
1115
- }
@@ -1,7 +1,5 @@
1
1
  // @ts-check
2
2
 
3
- "use strict";
4
-
5
3
  /**
6
4
  * Merges two options objects by combining config and replacing properties.
7
5
  * @param {object} first First options object.
@@ -24,4 +22,4 @@ const mergeOptions = (first, second) => {
24
22
  return merged;
25
23
  };
26
24
 
27
- module.exports = mergeOptions;
25
+ export default mergeOptions;