wikilint 2.25.0 → 2.26.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.
Files changed (59) hide show
  1. package/README.md +16 -15
  2. package/config/default.json +3 -0
  3. package/config/enwiki.json +3 -0
  4. package/config/jawiki.json +3 -0
  5. package/config/minimum.json +1 -0
  6. package/config/moegirl.json +0 -20
  7. package/config/zhwiki.json +3 -0
  8. package/data/ext/math.json +41 -0
  9. package/dist/base.d.mts +17 -4
  10. package/dist/base.d.ts +17 -4
  11. package/dist/bin/cli.js +114 -51
  12. package/dist/bin/config.js +8 -2
  13. package/dist/index.d.ts +5 -3
  14. package/dist/index.js +68 -47
  15. package/dist/lib/element.js +11 -9
  16. package/dist/lib/lintConfig.d.ts +18 -7
  17. package/dist/lib/lintConfig.js +55 -12
  18. package/dist/lib/lsp.js +16 -8
  19. package/dist/lib/text.js +176 -171
  20. package/dist/mixin/hidden.js +1 -1
  21. package/dist/mixin/noEscape.js +9 -7
  22. package/dist/parser/links.js +10 -4
  23. package/dist/src/arg.d.ts +0 -2
  24. package/dist/src/arg.js +34 -34
  25. package/dist/src/attribute.js +58 -36
  26. package/dist/src/attributes.js +62 -51
  27. package/dist/src/commented.js +2 -1
  28. package/dist/src/converterFlags.js +22 -18
  29. package/dist/src/extLink.js +6 -4
  30. package/dist/src/gallery.js +40 -36
  31. package/dist/src/heading.js +71 -59
  32. package/dist/src/html.js +81 -70
  33. package/dist/src/imageParameter.js +21 -15
  34. package/dist/src/imagemap.js +22 -18
  35. package/dist/src/index.js +107 -97
  36. package/dist/src/link/base.js +38 -28
  37. package/dist/src/link/file.js +86 -73
  38. package/dist/src/link/galleryImage.js +10 -6
  39. package/dist/src/link/index.js +10 -6
  40. package/dist/src/link/redirectTarget.js +12 -8
  41. package/dist/src/magicLink.js +25 -20
  42. package/dist/src/nested.js +31 -27
  43. package/dist/src/nowiki/comment.js +13 -9
  44. package/dist/src/nowiki/index.js +11 -7
  45. package/dist/src/nowiki/quote.js +29 -23
  46. package/dist/src/paramTag/index.js +26 -22
  47. package/dist/src/parameter.js +20 -16
  48. package/dist/src/pre.js +1 -1
  49. package/dist/src/redirect.js +5 -3
  50. package/dist/src/syntax.js +1 -1
  51. package/dist/src/table/index.js +31 -29
  52. package/dist/src/table/td.js +20 -16
  53. package/dist/src/table/trBase.js +13 -11
  54. package/dist/src/tagPair/ext.js +13 -10
  55. package/dist/src/tagPair/include.js +17 -11
  56. package/dist/src/transclude.js +45 -37
  57. package/dist/util/constants.js +2 -1
  58. package/dist/util/lint.js +2 -1
  59. package/package.json +4 -4
package/README.md CHANGED
@@ -16,21 +16,22 @@ npx wikilint --config zhwiki --include --lang zh-hans *.wiki
16
16
 
17
17
  ## CLI Options
18
18
 
19
- | Option | Description | Default |
20
- | :----- | :---------- | :------ |
21
- | `-c`, `--config` \<path or preset config\> | Choose parser's configuration | `default` |
22
- | `--cache` | Enable caching | `false` |
23
- | `--cache-file` \<path\> | Specify cache file and enable caching | `.wikilintcache` |
24
- | `--ext` \<extension\> | Specify file extension<br>Can be used multiple times | all files |
25
- | `--fix` | Automatically fix problems | `false` |
26
- | `-h`, `--help` | Print available options | |
27
- | `-i`, `--include` | Parse for inclusion | `false` |
28
- | `--ignore` \<pattern\> | Ignore files matching the glob pattern<br>Can be used multiple times | |
29
- | `-l`, `--lang` \<path or preset language\> | Choose i18n language | English |
30
- | `-q`, `--quiet` | Report errors only | errors and warnings |
31
- | `-r`, `--recursive` | Recursively lint files | `false` |
32
- | `-s`, `--strict` | Exit when there is an error or warning<br>Override `-q` or `--quiet` | Exit `1` only where there is an error |
33
- | `-v`, `--version` | Print package version | |
19
+ | Option | Argument | Description | Default |
20
+ | :----- | :------- | :---------- | :------ |
21
+ | `-c`, `--config` | \<path or preset config\> | Choose parser's [configuration](https://github.com/bhsd-harry/wikiparser-node/wiki/Parser-%28EN%29#config) | `default` |
22
+ | `--cache` | | Enable caching | `false` |
23
+ | `--cache-file` | \<path\> | Specify cache file and enable caching | `.wikilintcache` |
24
+ | `--ext` | \<extension\> | Specify file extension<br>Can be used multiple times | all files |
25
+ | `--fix` | | Automatically fix problems | `false` |
26
+ | `-h`, `--help` | | Print available options | |
27
+ | `-i`, `--include` | | Parse for inclusion | `false` |
28
+ | `--ignore` | \<pattern\> | Ignore files matching the glob pattern<br>Can be used multiple times | |
29
+ | `-l`, `--lang` | \<path or preset language\> | Choose [i18n](https://github.com/bhsd-harry/wikiparser-node/wiki/Parser-%28EN%29#i18n) language | English |
30
+ | `--lc`, `--lint-config` | \<path\> | Specify [lint config](https://github.com/bhsd-harry/wikiparser-node/wiki/Rules#configuration) file | `.wikilintrc.json`<br>`.wikilintrc.js`<br>`.wikilintrc.cjs`<br>`.wikilintrc.mjs` |
31
+ | `-q`, `--quiet` | | Report errors only | errors and warnings |
32
+ | `-r`, `--recursive` | | Recursively lint files | `false` |
33
+ | `-s`, `--strict` | | Exit when there is an error or warning<br>Override `-q` or `--quiet` | Exit `1` only where there is an error |
34
+ | `-v`, `--version` | | Print package version | |
34
35
 
35
36
  ## Configuration
36
37
 
@@ -549,6 +549,7 @@
549
549
  "dir",
550
550
  "interwikilink",
551
551
  "interlanguagelink",
552
+ "contentmodel",
552
553
  "timef",
553
554
  "timefl",
554
555
  "pendingchangelevel",
@@ -654,6 +655,7 @@
654
655
  "numberofadmins",
655
656
  "cascadingsources",
656
657
  "bcp47",
658
+ "contentmodel",
657
659
  "dir",
658
660
  "language",
659
661
  "numberofwikis",
@@ -1343,6 +1345,7 @@
1343
1345
  "#dir": "dir",
1344
1346
  "#interwikilink": "interwikilink",
1345
1347
  "#interlanguagelink": "interlanguagelink",
1348
+ "#contentmodel": "contentmodel",
1346
1349
  "#timef": "timef",
1347
1350
  "#timefl": "timefl",
1348
1351
  "USERLANGUAGE": "userlanguage"
@@ -242,6 +242,7 @@
242
242
  "dir",
243
243
  "interwikilink",
244
244
  "interlanguagelink",
245
+ "contentmodel",
245
246
  "int",
246
247
  "special",
247
248
  "speciale",
@@ -363,6 +364,7 @@
363
364
  "numberofadmins",
364
365
  "cascadingsources",
365
366
  "bcp47",
367
+ "contentmodel",
366
368
  "dir",
367
369
  "language",
368
370
  "numberofwikis",
@@ -499,6 +501,7 @@
499
501
  "#dir": "dir",
500
502
  "#interwikilink": "interwikilink",
501
503
  "#interlanguagelink": "interlanguagelink",
504
+ "#contentmodel": "contentmodel",
502
505
  "DISPLAYTITLE": "displaytitle",
503
506
  "#timef": "timef",
504
507
  "#timefl": "timefl",
@@ -271,6 +271,7 @@
271
271
  "dir",
272
272
  "interwikilink",
273
273
  "interlanguagelink",
274
+ "contentmodel",
274
275
  "int",
275
276
  "special",
276
277
  "speciale",
@@ -389,6 +390,7 @@
389
390
  "numberofadmins",
390
391
  "cascadingsources",
391
392
  "bcp47",
393
+ "contentmodel",
392
394
  "dir",
393
395
  "language",
394
396
  "numberofwikis",
@@ -695,6 +697,7 @@
695
697
  "#dir": "dir",
696
698
  "#interwikilink": "interwikilink",
697
699
  "#interlanguagelink": "interlanguagelink",
700
+ "#contentmodel": "contentmodel",
698
701
  "表示タイトル": "displaytitle",
699
702
  "DISPLAYTITLE": "displaytitle",
700
703
  "#timef": "timef",
@@ -183,6 +183,7 @@
183
183
  "#dir": "dir",
184
184
  "#interwikilink": "interwikilink",
185
185
  "#interlanguagelink": "interlanguagelink",
186
+ "#contentmodel": "contentmodel",
186
187
  "#timef": "timef",
187
188
  "#timefl": "timefl"
188
189
  },
@@ -368,16 +368,6 @@
368
368
  "formatdate",
369
369
  "displaytitle",
370
370
  "choose",
371
- "var",
372
- "varexists",
373
- "var_final",
374
- "vardefine",
375
- "vardefineecho",
376
- "while",
377
- "dowhile",
378
- "loop",
379
- "forargs",
380
- "fornumargs",
381
371
  "widget",
382
372
  "avatar",
383
373
  "categorytree",
@@ -552,16 +542,6 @@
552
542
  "#格式化日期": "formatdate",
553
543
  "#日期格式化": "formatdate",
554
544
  "#choose": "choose",
555
- "#var": "var",
556
- "#varexists": "varexists",
557
- "#var_final": "var_final",
558
- "#vardefine": "vardefine",
559
- "#vardefineecho": "vardefineecho",
560
- "#while": "while",
561
- "#dowhile": "dowhile",
562
- "#loop": "loop",
563
- "#forargs": "forargs",
564
- "#fornumargs": "fornumargs",
565
545
  "#widget": "widget",
566
546
  "#微件": "widget",
567
547
  "#小部件": "widget",
@@ -383,6 +383,7 @@
383
383
  "dir",
384
384
  "interwikilink",
385
385
  "interlanguagelink",
386
+ "contentmodel",
386
387
  "int",
387
388
  "special",
388
389
  "speciale",
@@ -502,6 +503,7 @@
502
503
  "numberofadmins",
503
504
  "cascadingsources",
504
505
  "bcp47",
506
+ "contentmodel",
505
507
  "dir",
506
508
  "language",
507
509
  "numberofwikis",
@@ -790,6 +792,7 @@
790
792
  "#dir": "dir",
791
793
  "#interwikilink": "interwikilink",
792
794
  "#interlanguagelink": "interlanguagelink",
795
+ "#contentmodel": "contentmodel",
793
796
  "DISPLAYTITLE": "displaytitle",
794
797
  "显示标题": "displaytitle",
795
798
  "顯示標題": "displaytitle",
@@ -7,6 +7,7 @@
7
7
  "\\alpha",
8
8
  "\\Alpha",
9
9
  "\\amalg",
10
+ "\\and",
10
11
  "\\And",
11
12
  "\\angle",
12
13
  "\\approx",
@@ -28,13 +29,16 @@
28
29
  "\\backslash",
29
30
  "\\bar",
30
31
  "\\barwedge",
32
+ "\\Bbb",
31
33
  "\\Bbbk",
32
34
  "\\bcancel",
33
35
  "\\because",
36
+ "\\begin",
34
37
  "\\beta",
35
38
  "\\Beta",
36
39
  "\\beth",
37
40
  "\\between",
41
+ "\\bf",
38
42
  "\\big",
39
43
  "\\Big",
40
44
  "\\bigcap",
@@ -68,6 +72,7 @@
68
72
  "\\blacktriangleleft",
69
73
  "\\blacktriangleright",
70
74
  "\\bmod",
75
+ "\\bold",
71
76
  "\\boldsymbol",
72
77
  "\\bot",
73
78
  "\\bowtie",
@@ -81,6 +86,8 @@
81
86
  "\\bullet",
82
87
  "\\bumpeq",
83
88
  "\\Bumpeq",
89
+ "\\C",
90
+ "\\cal",
84
91
  "\\cancel",
85
92
  "\\cancelto",
86
93
  "\\cap",
@@ -178,6 +185,7 @@
178
185
  "\\emph",
179
186
  "\\empty",
180
187
  "\\emptyset",
188
+ "\\end",
181
189
  "\\epsilon",
182
190
  "\\Epsilon",
183
191
  "\\eqcirc",
@@ -226,17 +234,21 @@
226
234
  "\\gtrless",
227
235
  "\\gtrsim",
228
236
  "\\gvertneqq",
237
+ "\\H",
229
238
  "\\hAar",
230
239
  "\\harr",
240
+ "\\hArr",
231
241
  "\\Harr",
232
242
  "\\hat",
233
243
  "\\hbar",
244
+ "\\hbox",
234
245
  "\\hearts",
235
246
  "\\heartsuit",
236
247
  "\\hline",
237
248
  "\\hom",
238
249
  "\\hookleftarrow",
239
250
  "\\hookrightarrow",
251
+ "\\hphantom",
240
252
  "\\hslash",
241
253
  "\\iff",
242
254
  "\\iiiint",
@@ -252,10 +264,13 @@
252
264
  "\\infty",
253
265
  "\\injlim",
254
266
  "\\int",
267
+ "\\intbar",
268
+ "\\intBar",
255
269
  "\\intercal",
256
270
  "\\iota",
257
271
  "\\Iota",
258
272
  "\\isin",
273
+ "\\it",
259
274
  "\\jmath",
260
275
  "\\kappa",
261
276
  "\\Kappa",
@@ -275,6 +290,7 @@
275
290
  "\\lceil",
276
291
  "\\ldots",
277
292
  "\\le",
293
+ "\\left",
278
294
  "\\leftarrow",
279
295
  "\\Leftarrow",
280
296
  "\\leftarrowtail",
@@ -349,6 +365,7 @@
349
365
  "\\mathsf",
350
366
  "\\mathtt",
351
367
  "\\max",
368
+ "\\mbox",
352
369
  "\\measuredangle",
353
370
  "\\mho",
354
371
  "\\mid",
@@ -414,7 +431,10 @@
414
431
  "\\O",
415
432
  "\\odot",
416
433
  "\\officialeuro",
434
+ "\\oiiint",
435
+ "\\oiint",
417
436
  "\\oint",
437
+ "\\ointctrclockwise",
418
438
  "\\omega",
419
439
  "\\Omega",
420
440
  "\\omicron",
@@ -422,9 +442,11 @@
422
442
  "\\ominus",
423
443
  "\\operatorname",
424
444
  "\\oplus",
445
+ "\\or",
425
446
  "\\oslash",
426
447
  "\\otimes",
427
448
  "\\over",
449
+ "\\overarc",
428
450
  "\\overbrace",
429
451
  "\\overleftarrow",
430
452
  "\\overleftrightarrow",
@@ -432,9 +454,12 @@
432
454
  "\\overrightarrow",
433
455
  "\\overset",
434
456
  "\\P",
457
+ "\\pagecolor",
435
458
  "\\parallel",
459
+ "\\part",
436
460
  "\\partial",
437
461
  "\\perp",
462
+ "\\phantom",
438
463
  "\\phi",
439
464
  "\\Phi",
440
465
  "\\pi",
@@ -478,6 +503,7 @@
478
503
  "\\rfloor",
479
504
  "\\rho",
480
505
  "\\Rho",
506
+ "\\right",
481
507
  "\\rightarrow",
482
508
  "\\Rightarrow",
483
509
  "\\rightarrowtail",
@@ -489,6 +515,7 @@
489
515
  "\\rightsquigarrow",
490
516
  "\\rightthreetimes",
491
517
  "\\risingdotseq",
518
+ "\\rm",
492
519
  "\\Rrightarrow",
493
520
  "\\Rsh",
494
521
  "\\rtimes",
@@ -508,6 +535,7 @@
508
535
  "\\sharp",
509
536
  "\\shortmid",
510
537
  "\\shortparallel",
538
+ "\\sideset",
511
539
  "\\sigma",
512
540
  "\\Sigma",
513
541
  "\\sim",
@@ -565,6 +593,7 @@
565
593
  "\\tau",
566
594
  "\\Tau",
567
595
  "\\tbinom",
596
+ "\\text",
568
597
  "\\textbf",
569
598
  "\\textit",
570
599
  "\\textrm",
@@ -611,27 +640,38 @@
611
640
  "\\upuparrows",
612
641
  "\\urcorner",
613
642
  "\\varcoppa",
643
+ "\\varDelta",
614
644
  "\\varepsilon",
645
+ "\\varGamma",
615
646
  "\\varinjlim",
616
647
  "\\varkappa",
648
+ "\\varLambda",
617
649
  "\\varliminf",
618
650
  "\\varlimsup",
619
651
  "\\varnothing",
652
+ "\\varointclockwise",
653
+ "\\varOmega",
620
654
  "\\varphi",
655
+ "\\varPhi",
621
656
  "\\varpi",
657
+ "\\varPi",
622
658
  "\\varprojlim",
623
659
  "\\varpropto",
624
660
  "\\varrho",
625
661
  "\\varsigma",
662
+ "\\varSigma",
626
663
  "\\varstigma",
627
664
  "\\varsubsetneq",
628
665
  "\\varsubsetneqq",
629
666
  "\\varsupsetneq",
630
667
  "\\varsupsetneqq",
631
668
  "\\vartheta",
669
+ "\\varTheta",
632
670
  "\\vartriangle",
633
671
  "\\vartriangleleft",
634
672
  "\\vartriangleright",
673
+ "\\varUpsilon",
674
+ "\\varXi",
635
675
  "\\vdash",
636
676
  "\\vDash",
637
677
  "\\Vdash",
@@ -642,6 +682,7 @@
642
682
  "\\vert",
643
683
  "\\Vert",
644
684
  "\\vline",
685
+ "\\vphantom",
645
686
  "\\Vvdash",
646
687
  "\\wedge",
647
688
  "\\weierp",
package/dist/base.d.mts CHANGED
@@ -267,15 +267,28 @@ export interface LanguageService {
267
267
  setTargetWikipedia(wiki: string, user: string): Promise<void>;
268
268
  }
269
269
  export type SeverityLevel = 0 | 1 | 2;
270
- export type LintConfigValue = SeverityLevel | [SeverityLevel, Record<string, unknown>];
271
- export type LintConfig = Partial<Record<LintError.Rule, LintConfigValue>>;
272
- export interface LintConfiguration extends LintConfig {
270
+ export type LintConfigValue = SeverityLevel | [SeverityLevel, Record<string, SeverityLevel>];
271
+ export type LintRuleConfig = Partial<Record<LintError.Rule, LintConfigValue>>;
272
+ export interface FullLintConfig {
273
+ rules: LintRuleConfig;
274
+ configurationComment?: string;
275
+ ignoreDisables?: boolean;
276
+ fix?: boolean;
277
+ computeEditInfo?: boolean;
278
+ }
279
+ export type LintConfig = LintRuleConfig | FullLintConfig;
280
+ export interface LintRuleConfiguration extends LintRuleConfig {
281
+ getSeverity(rule: LintError.Rule, key?: string): LintError.Severity | false;
282
+ }
283
+ export interface LintConfiguration extends FullLintConfig {
284
+ rules: LintRuleConfiguration;
285
+ getSeverity(rule: LintError.Rule, key?: string): LintError.Severity | false;
273
286
  }
274
287
  export interface Parser {
275
288
  config: ConfigData | string;
276
289
  i18n: Record<string, string> | string | undefined;
277
290
  /** @since v1.22.0 */
278
- lintConfig: LintConfiguration;
291
+ lintConfig: LintConfig;
279
292
  /** @since v1.9.0 */
280
293
  viewOnly: boolean;
281
294
  /**
package/dist/base.d.ts CHANGED
@@ -267,15 +267,28 @@ export interface LanguageService {
267
267
  setTargetWikipedia(wiki: string, user: string): Promise<void>;
268
268
  }
269
269
  export type SeverityLevel = 0 | 1 | 2;
270
- export type LintConfigValue = SeverityLevel | [SeverityLevel, Record<string, unknown>];
271
- export type LintConfig = Partial<Record<LintError.Rule, LintConfigValue>>;
272
- export interface LintConfiguration extends LintConfig {
270
+ export type LintConfigValue = SeverityLevel | [SeverityLevel, Record<string, SeverityLevel>];
271
+ export type LintRuleConfig = Partial<Record<LintError.Rule, LintConfigValue>>;
272
+ export interface FullLintConfig {
273
+ rules: LintRuleConfig;
274
+ configurationComment?: string;
275
+ ignoreDisables?: boolean;
276
+ fix?: boolean;
277
+ computeEditInfo?: boolean;
278
+ }
279
+ export type LintConfig = LintRuleConfig | FullLintConfig;
280
+ export interface LintRuleConfiguration extends LintRuleConfig {
281
+ getSeverity(rule: LintError.Rule, key?: string): LintError.Severity | false;
282
+ }
283
+ export interface LintConfiguration extends FullLintConfig {
284
+ rules: LintRuleConfiguration;
285
+ getSeverity(rule: LintError.Rule, key?: string): LintError.Severity | false;
273
286
  }
274
287
  export interface Parser {
275
288
  config: ConfigData | string;
276
289
  i18n: Record<string, string> | string | undefined;
277
290
  /** @since v1.22.0 */
278
- lintConfig: LintConfiguration;
291
+ lintConfig: LintConfig;
279
292
  /** @since v1.9.0 */
280
293
  viewOnly: boolean;
281
294
  /**
package/dist/bin/cli.js CHANGED
@@ -33,15 +33,16 @@ Available options:
33
33
  -i, --include Parse for inclusion
34
34
  --ignore <pattern> Ignore files that match the pattern
35
35
  -l, --lang <path or preset language> Choose i18n language
36
+ --lc, --lint-config <path> Specify lint config file
36
37
  -q, --quiet Report errors only
37
38
  -r, --recursive Lint files in directories recursively
38
39
  -s, --strict Exit when there is an error or warning
39
40
  Override -q or --quiet
40
41
  -v, --version Print package version
41
42
  `, root = path_1.default.join(__dirname, '..', '..'), configPath = path_1.default.join(root, 'config'), preset = new Set(fs_1.default.readdirSync(configPath).filter(file => file.endsWith('.json'))
42
- .map(file => file.slice(0, -5))), i18n = new Set(fs_1.default.readdirSync(path_1.default.join(root, 'i18n')).filter(file => file.endsWith('.json'))
43
+ .map(file => file.slice(0, -5))), lintConfigDefaults = ['.wikilintrc.json', '.wikilintrc.js', '.wikilintrc.cjs', '.wikilintrc.mjs'], i18n = new Set(fs_1.default.readdirSync(path_1.default.join(root, 'i18n')).filter(file => file.endsWith('.json'))
43
44
  .map(file => file.slice(0, -5))), { argv } = process, exts = [], ignorePatterns = [], jobs = [];
44
- let files = [], cacheFile = '.wikilintcache', cache, exiting = false, fixing = false, include = false, quiet = false, recursive = false, strict = false, caching = false, nErr = 0, nWarn = 0, nFixableErr = 0, nFixableWarn = 0, option;
45
+ let files = [], lintConfigFile, cacheFile = '.wikilintcache', cache, exiting = false, fixing = false, include = false, quiet = false, recursive = false, strict = false, caching = false, nErr = 0, nWarn = 0, nFixableErr = 0, nFixableWarn = 0, option;
45
46
  /**
46
47
  * exit with message
47
48
  * @param msg message
@@ -76,6 +77,38 @@ const throwOnConfig = (config) => {
76
77
  index_1.default.config = config;
77
78
  }
78
79
  };
80
+ /**
81
+ * throw if `--lc` or `--lint-config` option is incorrect
82
+ * @param config lintConfig input
83
+ * @throws `Error` unrecognized lintConfig input
84
+ */
85
+ const throwOnLintConfig = (config) => {
86
+ if (throwOnInput(config, '--lc/--lint-config', 'a path')) {
87
+ lintConfigFile = path_1.default.resolve('.', config);
88
+ }
89
+ };
90
+ /**
91
+ * load lintConfig
92
+ * @param file lintConfig file path
93
+ */
94
+ const loadLintConfig = async (file) => {
95
+ const symbol = Symbol('lintConfig');
96
+ let lintConfig = symbol;
97
+ try {
98
+ lintConfig = require(file);
99
+ }
100
+ catch { }
101
+ if (lintConfig === symbol) {
102
+ lintConfig = await import(file);
103
+ }
104
+ if (lintConfig && typeof lintConfig === 'object' && 'default' in lintConfig) {
105
+ lintConfig = lintConfig.default;
106
+ }
107
+ if (lintConfig !== undefined && lintConfig !== null && typeof lintConfig !== 'object') {
108
+ exit(`Not a valid lint config file: ${lintConfigFile}`);
109
+ }
110
+ return lintConfig;
111
+ };
79
112
  /**
80
113
  * throw if `-l` or `--lang` option is incorrect
81
114
  * @param lang lang input
@@ -138,6 +171,10 @@ for (let i = 2; i < argv.length; i++) {
138
171
  case '--config':
139
172
  throwOnConfig(argv[++i]);
140
173
  break;
174
+ case '--lc':
175
+ case '--lint-config':
176
+ throwOnLintConfig(argv[++i]);
177
+ break;
141
178
  case '--cache':
142
179
  caching = true;
143
180
  break;
@@ -273,61 +310,87 @@ try {
273
310
  catch {
274
311
  minimatch = path_1.default.matchesGlob.bind(path_1.default); // eslint-disable-line n/no-unsupported-features/node-builtins
275
312
  }
276
- for (const file of new Set(files.map(f => path_1.default.resolve(f)))) {
277
- const stat = fs_1.default.statSync(file);
278
- if (stat.isDirectory()) {
279
- console.error(`"${file}" is a directory. Please use -r or --recursive to lint directories.`);
280
- exiting = true;
281
- continue;
282
- }
283
- else if (ignorePatterns.some(ignore => minimatch(file, ignore))) {
284
- continue;
285
- }
286
- const fileCache = obj?.[file];
287
- let wikitext = fs_1.default.readFileSync(file, 'utf8'), problems, update = false;
288
- if (caching && fileCache?.[0] === stat.mtimeMs && fileCache[1] === config && fileCache[2] === mtimeMs) {
289
- [, , , problems] = fileCache;
290
- }
291
- else {
292
- problems = index_1.default.parse(wikitext, include).lint();
293
- update = true;
294
- }
295
- if (fixing && problems.output !== undefined) {
296
- wikitext = problems.output;
297
- jobs.push(fs_1.default.promises.writeFile(file, wikitext));
298
- problems = index_1.default.parse(wikitext, include).lint();
299
- update = true;
300
- }
301
- if (caching && update) {
302
- obj[file] = [stat.mtimeMs, config, mtimeMs, problems];
303
- }
304
- const errors = problems.filter(({ severity }) => severity === 'error'), fixable = problems.filter(({ fix }) => fix), nLocalErr = errors.length, nLocalWarn = problems.length - nLocalErr, nLocalFixableErr = fixable.filter(({ severity }) => severity === 'error').length, nLocalFixableWarn = fixable.length - nLocalFixableErr;
305
- if (quiet) {
306
- problems = errors;
313
+ (async () => {
314
+ if (lintConfigFile) {
315
+ try {
316
+ index_1.default.lintConfig = await loadLintConfig(lintConfigFile);
317
+ }
318
+ catch {
319
+ exit(`Cannot load lint config file: ${lintConfigFile}`);
320
+ }
307
321
  }
308
322
  else {
309
- nWarn += nLocalWarn;
310
- nFixableWarn += nLocalFixableWarn;
323
+ await (async () => {
324
+ let cur = process.cwd(), last;
325
+ while (last !== cur) {
326
+ for (const file of lintConfigDefaults) {
327
+ try {
328
+ index_1.default.lintConfig = await loadLintConfig(path_1.default.join(cur, file));
329
+ return;
330
+ }
331
+ catch { }
332
+ }
333
+ last = cur;
334
+ cur = path_1.default.dirname(cur);
335
+ }
336
+ })();
311
337
  }
312
- if (problems.length > 0) {
313
- console.error(`\n${chalk.underline('%s')}`, file);
314
- const maxLineChars = String(Math.max(...problems.map(({ startLine }) => startLine))).length, maxColChars = String(Math.max(...problems.map(({ startCol }) => startCol))).length, maxMessageChars = Math.max(...problems.map(({ message: { length } }) => length));
315
- for (const { rule, message, severity, startLine, startCol } of problems) {
316
- console.error(` ${chalk.dim('%s:%s')} %s %s ${chalk.dim('%s')}`, String(startLine).padStart(maxLineChars), String(startCol).padEnd(maxColChars), coloredSeverity(severity), message.padEnd(maxMessageChars), rule);
338
+ index_1.default.lintConfig.computeEditInfo = false;
339
+ index_1.default.lintConfig.fix = true;
340
+ for (const file of new Set(files.map(f => path_1.default.resolve(f)))) {
341
+ const stat = fs_1.default.statSync(file);
342
+ if (stat.isDirectory()) {
343
+ console.error(`"${file}" is a directory. Please use -r or --recursive to lint directories.`);
344
+ exiting = true;
345
+ continue;
346
+ }
347
+ else if (ignorePatterns.some(ignore => minimatch(file, ignore))) {
348
+ continue;
349
+ }
350
+ const fileCache = obj?.[file];
351
+ let wikitext = fs_1.default.readFileSync(file, 'utf8'), problems, update = false;
352
+ if (caching && fileCache?.[0] === stat.mtimeMs && fileCache[1] === config && fileCache[2] === mtimeMs) {
353
+ [, , , problems] = fileCache;
354
+ }
355
+ else {
356
+ problems = index_1.default.parse(wikitext, include).lint();
357
+ update = true;
317
358
  }
359
+ if (fixing && problems.output !== undefined) {
360
+ wikitext = problems.output;
361
+ jobs.push(fs_1.default.promises.writeFile(file, wikitext));
362
+ problems = index_1.default.parse(wikitext, include).lint();
363
+ update = true;
364
+ }
365
+ if (caching && update) {
366
+ obj[file] = [stat.mtimeMs, config, mtimeMs, problems];
367
+ }
368
+ const errors = problems.filter(({ severity }) => severity === 'error'), fixable = problems.filter(({ fix }) => fix), nLocalErr = errors.length, nLocalWarn = problems.length - nLocalErr, nLocalFixableErr = fixable.filter(({ severity }) => severity === 'error').length, nLocalFixableWarn = fixable.length - nLocalFixableErr;
369
+ if (quiet) {
370
+ problems = errors;
371
+ }
372
+ else {
373
+ nWarn += nLocalWarn;
374
+ nFixableWarn += nLocalFixableWarn;
375
+ }
376
+ if (problems.length > 0) {
377
+ console.error(`\n${chalk.underline('%s')}`, file);
378
+ const maxLineChars = String(Math.max(...problems.map(({ startLine }) => startLine))).length, maxColChars = String(Math.max(...problems.map(({ startCol }) => startCol))).length, maxMessageChars = Math.max(...problems.map(({ message: { length } }) => length));
379
+ for (const { rule, message, severity, startLine, startCol } of problems) {
380
+ console.error(` ${chalk.dim('%s:%s')} %s %s ${chalk.dim('%s')}`, String(startLine).padStart(maxLineChars), String(startCol).padEnd(maxColChars), coloredSeverity(severity), message.padEnd(maxMessageChars), rule);
381
+ }
382
+ }
383
+ nErr += nLocalErr;
384
+ nFixableErr += nLocalFixableErr;
385
+ exiting ||= Boolean(nLocalErr || strict && nLocalWarn);
318
386
  }
319
- nErr += nLocalErr;
320
- nFixableErr += nLocalFixableErr;
321
- exiting ||= Boolean(nLocalErr || strict && nLocalWarn);
322
- }
323
- if (nErr || nWarn) {
324
- console.error(chalk.red.bold('%s'), `\n✖ ${plural(nErr + nWarn, 'problem')} (${plural(nErr, 'error')}, ${plural(nWarn, 'warning')})`);
325
- if (nFixableErr || nFixableWarn) {
326
- console.error(chalk.red.bold('%s'), ` ${plural(nFixableErr, 'error')} and ${plural(nFixableWarn, 'warning')} potentially fixable with the \`--fix\` option.`);
387
+ if (nErr || nWarn) {
388
+ console.error(chalk.red.bold('%s'), `\n✖ ${plural(nErr + nWarn, 'problem')} (${plural(nErr, 'error')}, ${plural(nWarn, 'warning')})`);
389
+ if (nFixableErr || nFixableWarn) {
390
+ console.error(chalk.red.bold('%s'), ` ${plural(nFixableErr, 'error')} and ${plural(nFixableWarn, 'warning')} potentially fixable with the \`--fix\` option.`);
391
+ }
392
+ console.error();
327
393
  }
328
- console.error();
329
- }
330
- (async () => {
331
394
  await Promise.all(jobs);
332
395
  if (caching) {
333
396
  fs_1.default.writeFileSync(cacheFile, JSON.stringify(cache), 'utf8');