wikilint 2.25.1 → 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 (45) hide show
  1. package/README.md +3 -3
  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 +15 -3
  10. package/dist/base.d.ts +15 -3
  11. package/dist/bin/cli.js +2 -0
  12. package/dist/bin/config.js +8 -2
  13. package/dist/index.d.ts +2 -1
  14. package/dist/index.js +2 -3
  15. package/dist/lib/lintConfig.d.ts +18 -7
  16. package/dist/lib/lintConfig.js +55 -12
  17. package/dist/lib/lsp.js +16 -8
  18. package/dist/lib/text.js +35 -33
  19. package/dist/src/arg.js +8 -6
  20. package/dist/src/attribute.js +23 -13
  21. package/dist/src/attributes.js +23 -15
  22. package/dist/src/converterFlags.js +9 -7
  23. package/dist/src/gallery.js +7 -5
  24. package/dist/src/heading.js +35 -25
  25. package/dist/src/html.js +38 -29
  26. package/dist/src/imageParameter.js +9 -5
  27. package/dist/src/imagemap.js +7 -5
  28. package/dist/src/index.js +50 -41
  29. package/dist/src/link/base.js +19 -11
  30. package/dist/src/link/file.js +24 -18
  31. package/dist/src/link/galleryImage.js +4 -2
  32. package/dist/src/link/index.js +4 -2
  33. package/dist/src/link/redirectTarget.js +4 -2
  34. package/dist/src/magicLink.js +13 -10
  35. package/dist/src/nested.js +7 -5
  36. package/dist/src/nowiki/comment.js +4 -2
  37. package/dist/src/nowiki/index.js +4 -2
  38. package/dist/src/nowiki/quote.js +10 -6
  39. package/dist/src/paramTag/index.js +4 -2
  40. package/dist/src/parameter.js +4 -2
  41. package/dist/src/table/td.js +9 -7
  42. package/dist/src/tagPair/ext.js +3 -3
  43. package/dist/src/tagPair/include.js +7 -3
  44. package/dist/src/transclude.js +13 -7
  45. package/package.json +4 -4
package/README.md CHANGED
@@ -18,7 +18,7 @@ npx wikilint --config zhwiki --include --lang zh-hans *.wiki
18
18
 
19
19
  | Option | Argument | Description | Default |
20
20
  | :----- | :------- | :---------- | :------ |
21
- | `-c`, `--config` | \<path or preset config\> | Choose parser's configuration | `default` |
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
22
  | `--cache` | | Enable caching | `false` |
23
23
  | `--cache-file` | \<path\> | Specify cache file and enable caching | `.wikilintcache` |
24
24
  | `--ext` | \<extension\> | Specify file extension<br>Can be used multiple times | all files |
@@ -26,8 +26,8 @@ npx wikilint --config zhwiki --include --lang zh-hans *.wiki
26
26
  | `-h`, `--help` | | Print available options | |
27
27
  | `-i`, `--include` | | Parse for inclusion | `false` |
28
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
- | `--lc`, `--lint-config` | \<path\> | Specify lint config file | `.wikilintrc.json`<br>`.wikilintrc.js`<br>`.wikilintrc.cjs`<br>`.wikilintrc.mjs` |
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
31
  | `-q`, `--quiet` | | Report errors only | errors and warnings |
32
32
  | `-r`, `--recursive` | | Recursively lint files | `false` |
33
33
  | `-s`, `--strict` | | Exit when there is an error or warning<br>Override `-q` or `--quiet` | Exit `1` only where there is an error |
@@ -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,9 +267,21 @@ 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;
273
285
  getSeverity(rule: LintError.Rule, key?: string): LintError.Severity | false;
274
286
  }
275
287
  export interface Parser {
package/dist/base.d.ts CHANGED
@@ -267,9 +267,21 @@ 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;
273
285
  getSeverity(rule: LintError.Rule, key?: string): LintError.Severity | false;
274
286
  }
275
287
  export interface Parser {
package/dist/bin/cli.js CHANGED
@@ -335,6 +335,8 @@ catch {
335
335
  }
336
336
  })();
337
337
  }
338
+ index_1.default.lintConfig.computeEditInfo = false;
339
+ index_1.default.lintConfig.fix = true;
338
340
  for (const file of new Set(files.map(f => path_1.default.resolve(f)))) {
339
341
  const stat = fs_1.default.statSync(file);
340
342
  if (stat.isDirectory()) {
@@ -77,7 +77,7 @@ const mw = {
77
77
  },
78
78
  },
79
79
  };
80
- const pkg = "wikilint", version = "2.25.1";
80
+ const pkg = "wikilint", version = "2.26.0";
81
81
  let mwConfig;
82
82
  /**
83
83
  * Get the parser configuration for a Wikimedia Foundation project.
@@ -123,7 +123,13 @@ exports.default = async (site, url, user, force, internal) => {
123
123
  format: 'json',
124
124
  formatversion: '2',
125
125
  }, { query: { general: { articlepath, variants }, magicwords, namespaces, namespacealiases, functionhooks, }, } = await (await fetch(`${url}/api.php?${new URLSearchParams(params).toString()}`, headers)).json();
126
- eval(m); // eslint-disable-line no-eval
126
+ try {
127
+ eval(m); // eslint-disable-line no-eval
128
+ }
129
+ catch (e) {
130
+ console.log(m);
131
+ throw e;
132
+ }
127
133
  if (!mwConfig) {
128
134
  throw new RangeError('Extension:CodeMirror is not installed!');
129
135
  }
package/dist/index.d.ts CHANGED
@@ -1,4 +1,5 @@
1
- import type { Config, ConfigData, LintError, LintConfig, LintConfiguration, TokenTypes, Parser as ParserBase, Stage } from './base';
1
+ import { LintConfiguration } from './lib/lintConfig';
2
+ import type { Config, ConfigData, LintError, LintConfig, TokenTypes, Parser as ParserBase, Stage } from './base';
2
3
  import type { Title, TitleOptions } from './lib/title';
3
4
  import type { LanguageService, QuickFixData } from './lib/lsp';
4
5
  import type { Token } from './internal';
package/dist/index.js CHANGED
@@ -27,7 +27,7 @@ const rootRequire = (file, dir) => require(path_1.default.isAbsolute(file)
27
27
  /* NOT FOR BROWSER ONLY END */
28
28
  let viewOnly = true;
29
29
  let lintConfig = (() => {
30
- LINT: return (0, lintConfig_1.getLintConfig)(); // eslint-disable-line no-unused-labels
30
+ LINT: return new lintConfig_1.LintConfiguration(); // eslint-disable-line no-unused-labels
31
31
  })(), i18n;
32
32
  const Parser = {
33
33
  config: 'default',
@@ -54,7 +54,7 @@ const Parser = {
54
54
  LINT: return lintConfig; // eslint-disable-line no-unused-labels
55
55
  },
56
56
  set lintConfig(config) {
57
- LINT: lintConfig = (0, lintConfig_1.getLintConfig)(config); // eslint-disable-line no-unused-labels
57
+ LINT: lintConfig = new lintConfig_1.LintConfiguration(config); // eslint-disable-line no-unused-labels
58
58
  },
59
59
  /** @implements */
60
60
  get viewOnly() {
@@ -68,7 +68,6 @@ const Parser = {
68
68
  },
69
69
  /* NOT FOR BROWSER ONLY */
70
70
  configPaths: [],
71
- lintCSS: true,
72
71
  /* NOT FOR BROWSER ONLY END */
73
72
  /** @implements */
74
73
  getConfig(config) {
@@ -1,13 +1,24 @@
1
- import type { LintError, LintConfig, LintConfiguration as LintConfigurationBase } from '../base';
1
+ import type { LintError, LintRuleConfig, LintRuleConfiguration as LintRuleConfigurationBase, LintConfig, LintConfiguration as LintConfigurationBase } from '../base';
2
+ interface LintRuleConfiguration extends LintRuleConfigurationBase {
3
+ }
4
+ /** 语法规则设置 */
5
+ declare class LintRuleConfiguration implements LintRuleConfigurationBase {
6
+ /** @param config 语法规则设置 */
7
+ constructor(config?: LintRuleConfig);
8
+ /** @implements */
9
+ getSeverity(rule: LintError.Rule, key?: string): LintError.Severity | false;
10
+ }
11
+ export interface LintConfiguration extends LintConfigurationBase {
12
+ }
2
13
  /** 语法检查设置 */
3
14
  export declare class LintConfiguration implements LintConfigurationBase {
15
+ #private;
16
+ /** @implements */
17
+ get rules(): LintRuleConfiguration;
18
+ set rules(config: LintRuleConfig | undefined);
4
19
  /** @param config 语法检查设置 */
5
20
  constructor(config?: LintConfig);
6
21
  /** @implements */
7
- getSeverity(this: LintConfigurationBase, rule: LintError.Rule, key?: string): LintError.Severity | false;
22
+ getSeverity(rule: LintError.Rule, key?: string): LintError.Severity | false;
8
23
  }
9
- /**
10
- * 获取语法检查设置
11
- * @param config 语法检查设置
12
- */
13
- export declare const getLintConfig: (config?: LintConfig) => LintConfiguration;
24
+ export {};
@@ -1,13 +1,13 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getLintConfig = exports.LintConfiguration = void 0;
3
+ exports.LintConfiguration = void 0;
4
4
  const base_1 = require("../base");
5
5
  const severities = new Set([0, 1, 2]), dict = new Map([
6
6
  [0, false],
7
7
  [1, 'warning'],
8
8
  [2, 'error'],
9
9
  ]);
10
- const defaultLintConfig = {
10
+ const defaultLintRuleConfig = {
11
11
  'bold-header': [
12
12
  1,
13
13
  {
@@ -211,6 +211,13 @@ const defaultLintConfig = {
211
211
  },
212
212
  ],
213
213
  };
214
+ Object.freeze(defaultLintRuleConfig);
215
+ const defaultLintConfig = {
216
+ configurationComment: 'lint',
217
+ ignoreDisables: false,
218
+ fix: true,
219
+ computeEditInfo: true,
220
+ };
214
221
  Object.freeze(defaultLintConfig);
215
222
  /**
216
223
  * 验证错误级别是否符合规范
@@ -235,17 +242,20 @@ const set = (obj, key, value) => {
235
242
  if (!base_1.rules.includes(key)) {
236
243
  throw new RangeError(`Unknown lint rule: ${key}`);
237
244
  }
245
+ else if (value === undefined) {
246
+ return false;
247
+ }
238
248
  else if (validateConfigValue(value)) {
239
249
  obj[key] = value;
240
250
  return true;
241
251
  }
242
252
  throw new RangeError(`Invalid lint config for ${key}: ${JSON.stringify(value)}`);
243
253
  };
244
- /** 语法检查设置 */
245
- class LintConfiguration {
246
- /** @param config 语法检查设置 */
254
+ /** 语法规则设置 */
255
+ class LintRuleConfiguration {
256
+ /** @param config 语法规则设置 */
247
257
  constructor(config) {
248
- Object.assign(this, structuredClone(defaultLintConfig));
258
+ Object.assign(this, structuredClone(defaultLintRuleConfig));
249
259
  if (!config) {
250
260
  return;
251
261
  }
@@ -262,10 +272,43 @@ class LintConfiguration {
262
272
  return key ? dict.get(value[1][key]) ?? dict.get(value[0]) : dict.get(value[0]);
263
273
  }
264
274
  }
275
+ /** 语法检查设置 */
276
+ class LintConfiguration {
277
+ #rules;
278
+ /** @implements */
279
+ get rules() {
280
+ return this.#rules;
281
+ }
282
+ set rules(config) {
283
+ this.#rules = new Proxy(new LintRuleConfiguration(config), {
284
+ set,
285
+ /** @ignore */
286
+ deleteProperty() {
287
+ return false;
288
+ },
289
+ });
290
+ }
291
+ /** @param config 语法检查设置 */
292
+ constructor(config) {
293
+ Object.assign(this, defaultLintConfig);
294
+ if (config
295
+ && !('rules' in config)
296
+ && Object.keys(config).some(key => base_1.rules.includes(key))) {
297
+ this.rules = config;
298
+ }
299
+ else {
300
+ const { rules: ruleConfig, ...other } = (config ?? {});
301
+ this.rules = ruleConfig;
302
+ for (const [key, value] of Object.entries(other)) {
303
+ if (value !== undefined && Object.prototype.hasOwnProperty.call(defaultLintConfig, key)) {
304
+ this[key] = value;
305
+ }
306
+ }
307
+ }
308
+ }
309
+ /** @implements */
310
+ getSeverity(rule, key) {
311
+ return this.#rules.getSeverity(rule, key);
312
+ }
313
+ }
265
314
  exports.LintConfiguration = LintConfiguration;
266
- /**
267
- * 获取语法检查设置
268
- * @param config 语法检查设置
269
- */
270
- const getLintConfig = (config) => new Proxy(new LintConfiguration(config), { set });
271
- exports.getLintConfig = getLintConfig;