@markuplint/ml-core 3.3.1 → 3.5.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 (66) hide show
  1. package/lib/configs.js +1 -2
  2. package/lib/index.d.ts +1 -11
  3. package/lib/ml-core.d.ts +12 -23
  4. package/lib/ml-core.js +4 -4
  5. package/lib/ml-dom/helper/accname.js +15 -5
  6. package/lib/ml-dom/helper/create-node.d.ts +2 -5
  7. package/lib/ml-dom/helper/create-node.js +3 -1
  8. package/lib/ml-dom/helper/debug.js +6 -2
  9. package/lib/ml-dom/helper/getIndent.d.ts +7 -7
  10. package/lib/ml-dom/helper/getIndent.js +11 -3
  11. package/lib/ml-dom/helper/walkers.d.ts +5 -13
  12. package/lib/ml-dom/helper/walkers.js +3 -1
  13. package/lib/ml-dom/manipulations/child-node-methods.d.ts +7 -20
  14. package/lib/ml-dom/manipulations/child-node-methods.js +24 -6
  15. package/lib/ml-dom/manipulations/get-children.d.ts +2 -4
  16. package/lib/ml-dom/manipulations/get-children.js +3 -1
  17. package/lib/ml-dom/node/attr.d.ts +91 -91
  18. package/lib/ml-dom/node/attr.js +5 -1
  19. package/lib/ml-dom/node/block.d.ts +32 -32
  20. package/lib/ml-dom/node/block.js +14 -4
  21. package/lib/ml-dom/node/character-data.d.ts +53 -60
  22. package/lib/ml-dom/node/character-data.js +9 -3
  23. package/lib/ml-dom/node/child-node.d.ts +3 -8
  24. package/lib/ml-dom/node/child-node.js +3 -1
  25. package/lib/ml-dom/node/comment.d.ts +13 -16
  26. package/lib/ml-dom/node/document-fragment.d.ts +20 -23
  27. package/lib/ml-dom/node/document-type.d.ts +32 -35
  28. package/lib/ml-dom/node/document-type.js +14 -4
  29. package/lib/ml-dom/node/document.d.ts +1590 -1603
  30. package/lib/ml-dom/node/document.js +41 -7
  31. package/lib/ml-dom/node/dom-token-list.d.ts +26 -26
  32. package/lib/ml-dom/node/dom-token-list.js +8 -6
  33. package/lib/ml-dom/node/element.d.ts +1897 -1895
  34. package/lib/ml-dom/node/element.js +58 -14
  35. package/lib/ml-dom/node/named-node-map.d.ts +40 -45
  36. package/lib/ml-dom/node/named-node-map.js +11 -4
  37. package/lib/ml-dom/node/node-list.d.ts +4 -10
  38. package/lib/ml-dom/node/node-list.js +23 -4
  39. package/lib/ml-dom/node/node-store.d.ts +4 -4
  40. package/lib/ml-dom/node/node-store.js +8 -3
  41. package/lib/ml-dom/node/node.d.ts +473 -493
  42. package/lib/ml-dom/node/node.js +46 -16
  43. package/lib/ml-dom/node/parent-node.d.ts +58 -67
  44. package/lib/ml-dom/node/parent-node.js +9 -3
  45. package/lib/ml-dom/node/rule-mapper.d.ts +7 -7
  46. package/lib/ml-dom/node/rule-mapper.js +9 -2
  47. package/lib/ml-dom/node/text.d.ts +47 -50
  48. package/lib/ml-dom/node/types.d.ts +14 -70
  49. package/lib/ml-dom/node/unexpected-call-error.d.ts +2 -1
  50. package/lib/ml-dom/token/token.d.ts +44 -44
  51. package/lib/ml-rule/create-rule.d.ts +2 -2
  52. package/lib/ml-rule/create-test-rule.d.ts +4 -6
  53. package/lib/ml-rule/ml-rule-context.d.ts +50 -58
  54. package/lib/ml-rule/ml-rule-context.js +3 -1
  55. package/lib/ml-rule/ml-rule.d.ts +26 -28
  56. package/lib/ml-rule/ml-rule.js +30 -24
  57. package/lib/ml-rule/types.d.ts +17 -23
  58. package/lib/plugin/plugin.d.ts +1 -1
  59. package/lib/plugin/types.d.ts +7 -7
  60. package/lib/ruleset/index.d.ts +4 -4
  61. package/lib/ruleset/index.js +4 -4
  62. package/lib/test/index.d.ts +8 -20
  63. package/lib/test/index.js +1 -1
  64. package/lib/types.d.ts +9 -8
  65. package/lib/utils/get-location-from-chars.d.ts +4 -9
  66. package/package.json +14 -12
@@ -1,47 +1,47 @@
1
1
  import type { MLToken as MLASTToken } from '@markuplint/ml-ast';
2
2
  export declare class MLToken<A extends MLASTToken = MLASTToken> {
3
- #private;
4
- readonly uuid: string;
5
- protected readonly _astToken: A;
6
- constructor(astToken: A);
7
- /**
8
- * @implements `@markuplint/ml-core` API: `MLDOMToken`
9
- */
10
- get endCol(): number;
11
- /**
12
- * @implements `@markuplint/ml-core` API: `MLDOMToken`
13
- */
14
- get endLine(): number;
15
- /**
16
- * @implements `@markuplint/ml-core` API: `MLDOMToken`
17
- */
18
- get endOffset(): number;
19
- /**
20
- * @implements `@markuplint/ml-core` API: `MLDOMToken`
21
- */
22
- get originRaw(): string;
23
- /**
24
- * @implements `@markuplint/ml-core` API: `MLDOMToken`
25
- */
26
- get raw(): string;
27
- /**
28
- * @implements `@markuplint/ml-core` API: `MLDOMToken`
29
- */
30
- get startCol(): number;
31
- /**
32
- * @implements `@markuplint/ml-core` API: `MLDOMToken`
33
- */
34
- get startLine(): number;
35
- /**
36
- * @implements `@markuplint/ml-core` API: `MLDOMToken`
37
- */
38
- get startOffset(): number;
39
- /**
40
- * @implements `@markuplint/ml-core` API: `MLDOMToken`
41
- */
42
- fix(raw: string): void;
43
- /**
44
- * @implements `@markuplint/ml-core` API: `MLDOMToken`
45
- */
46
- toString(): string;
3
+ #private;
4
+ readonly uuid: string;
5
+ protected readonly _astToken: A;
6
+ constructor(astToken: A);
7
+ /**
8
+ * @implements `@markuplint/ml-core` API: `MLDOMToken`
9
+ */
10
+ get endCol(): number;
11
+ /**
12
+ * @implements `@markuplint/ml-core` API: `MLDOMToken`
13
+ */
14
+ get endLine(): number;
15
+ /**
16
+ * @implements `@markuplint/ml-core` API: `MLDOMToken`
17
+ */
18
+ get endOffset(): number;
19
+ /**
20
+ * @implements `@markuplint/ml-core` API: `MLDOMToken`
21
+ */
22
+ get originRaw(): string;
23
+ /**
24
+ * @implements `@markuplint/ml-core` API: `MLDOMToken`
25
+ */
26
+ get raw(): string;
27
+ /**
28
+ * @implements `@markuplint/ml-core` API: `MLDOMToken`
29
+ */
30
+ get startCol(): number;
31
+ /**
32
+ * @implements `@markuplint/ml-core` API: `MLDOMToken`
33
+ */
34
+ get startLine(): number;
35
+ /**
36
+ * @implements `@markuplint/ml-core` API: `MLDOMToken`
37
+ */
38
+ get startOffset(): number;
39
+ /**
40
+ * @implements `@markuplint/ml-core` API: `MLDOMToken`
41
+ */
42
+ fix(raw: string): void;
43
+ /**
44
+ * @implements `@markuplint/ml-core` API: `MLDOMToken`
45
+ */
46
+ toString(): string;
47
47
  }
@@ -1,3 +1,3 @@
1
1
  import type { RuleSeed } from './types';
2
- import type { RuleConfigValue } from '@markuplint/ml-config';
3
- export declare function createRule<T extends RuleConfigValue, O = null>(seed: RuleSeed<T, O>): RuleSeed<T, O>;
2
+ import type { PlainData, RuleConfigValue } from '@markuplint/ml-config';
3
+ export declare function createRule<T extends RuleConfigValue, O extends PlainData = undefined>(seed: Readonly<RuleSeed<T, O>>): Readonly<RuleSeed<T, O>>;
@@ -1,8 +1,6 @@
1
1
  import type { RuleSeed } from './types';
2
- import type { RuleConfigValue } from '@markuplint/ml-config';
2
+ import type { PlainData, RuleConfigValue } from '@markuplint/ml-config';
3
3
  import { MLRule } from './ml-rule';
4
- export declare function createRule<T extends RuleConfigValue, O = null>(
5
- seed: RuleSeed<T, O> & {
6
- name: string;
7
- },
8
- ): MLRule<T, O>;
4
+ export declare function createRule<T extends RuleConfigValue, O extends PlainData = undefined>(seed: Readonly<RuleSeed<T, O>> & {
5
+ readonly name: string;
6
+ }): MLRule<T, O>;
@@ -1,61 +1,53 @@
1
- import type { MLDocument } from '../ml-dom/node/document';
2
1
  import type { CheckerReport } from './types';
2
+ import type { MLDocument } from '../ml-dom/node/document';
3
3
  import type { LocaleSet, Translator } from '@markuplint/i18n';
4
- import type { Report, RuleConfigValue } from '@markuplint/ml-config';
5
- export declare class MLRuleContext<T extends RuleConfigValue, O = null> {
6
- #private;
7
- readonly document: MLDocument<T, O>;
8
- readonly locale: string;
9
- readonly translate: Translator;
10
- constructor(document: MLDocument<T, O>, locale: LocaleSet);
11
- get reports(): (
12
- | {
13
- message: string;
14
- line: number;
15
- col: number;
16
- raw: string;
17
- }
18
- | {
19
- message: string;
20
- scope: import('@markuplint/ml-config').Scope<T, O>;
21
- }
22
- | {
23
- message: string;
24
- scope: import('@markuplint/ml-config').Scope<T, O>;
25
- line: number;
26
- col: number;
27
- raw: string;
28
- }
29
- )[];
30
- provide(): {
31
- document: MLDocument<T, O>;
32
- translate: Translator;
33
- t: Translator;
34
- reports: (
35
- | {
36
- message: string;
37
- line: number;
38
- col: number;
39
- raw: string;
40
- }
41
- | {
42
- message: string;
43
- scope: import('@markuplint/ml-config').Scope<T, O>;
44
- }
45
- | {
46
- message: string;
47
- scope: import('@markuplint/ml-config').Scope<T, O>;
48
- line: number;
49
- col: number;
50
- raw: string;
51
- }
52
- )[];
53
- report: {
54
- (report: Report<T, O>): undefined;
55
- (report: CheckerReport<T, O>): boolean;
56
- };
57
- };
58
- report(report: Report<T, O>): undefined;
59
- report(report: CheckerReport<T, O>): boolean;
60
- private _push;
4
+ import type { PlainData, Report, RuleConfigValue } from '@markuplint/ml-config';
5
+ export declare class MLRuleContext<T extends RuleConfigValue, O extends PlainData = undefined> {
6
+ #private;
7
+ readonly document: MLDocument<T, O>;
8
+ readonly locale: string;
9
+ readonly translate: Translator;
10
+ constructor(document: MLDocument<T, O>, locale: LocaleSet);
11
+ get reports(): ({
12
+ message: string;
13
+ line: number;
14
+ col: number;
15
+ raw: string;
16
+ } | {
17
+ message: string;
18
+ scope: import("@markuplint/ml-config").Scope<T, O>;
19
+ } | {
20
+ message: string;
21
+ scope: import("@markuplint/ml-config").Scope<T, O>;
22
+ line: number;
23
+ col: number;
24
+ raw: string;
25
+ })[];
26
+ provide(): {
27
+ document: MLDocument<T, O>;
28
+ translate: Translator;
29
+ t: Translator;
30
+ reports: ({
31
+ message: string;
32
+ line: number;
33
+ col: number;
34
+ raw: string;
35
+ } | {
36
+ message: string;
37
+ scope: import("@markuplint/ml-config").Scope<T, O>;
38
+ } | {
39
+ message: string;
40
+ scope: import("@markuplint/ml-config").Scope<T, O>;
41
+ line: number;
42
+ col: number;
43
+ raw: string;
44
+ })[];
45
+ report: {
46
+ (report: Report<T, O>): undefined;
47
+ (report: CheckerReport<T, O>): boolean;
48
+ };
49
+ };
50
+ report(report: Report<T, O>): undefined;
51
+ report(report: CheckerReport<T, O>): boolean;
52
+ private _push;
61
53
  }
@@ -5,7 +5,9 @@ exports.MLRuleContext = void 0;
5
5
  const tslib_1 = require("tslib");
6
6
  const i18n_1 = require("@markuplint/i18n");
7
7
  class MLRuleContext {
8
- constructor(document, locale) {
8
+ constructor(
9
+ // eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
10
+ document, locale) {
9
11
  _MLRuleContext_reports.set(this, []);
10
12
  this.document = document;
11
13
  this.translate = (0, i18n_1.translator)(locale);
@@ -1,32 +1,30 @@
1
+ import type { RuleSeed } from './types';
1
2
  import type { Ruleset } from '..';
2
3
  import type { MLDocument } from '../ml-dom/node/document';
3
- import type { RuleSeed } from './types';
4
4
  import type { LocaleSet } from '@markuplint/i18n';
5
- import type { GlobalRuleInfo, RuleConfig, RuleConfigValue, RuleInfo, Severity, Violation } from '@markuplint/ml-config';
6
- export declare class MLRule<T extends RuleConfigValue, O = null> {
7
- #private;
8
- readonly defaultOptions: O;
9
- readonly defaultSeverity: Severity;
10
- readonly defaultValue: T;
11
- readonly name: string;
12
- constructor(
13
- o: RuleSeed<T, O> & {
14
- name: string;
15
- },
16
- );
17
- /**
18
- * The following getter is unused internally,
19
- * only for extending from 3rd party library
20
- */
21
- protected get f(): RuleSeed<T, O>['fix'];
22
- /**
23
- * The following getter is unused internally,
24
- * only for extending from 3rd party library
25
- */
26
- protected get v(): RuleSeed<T, O>['verify'];
27
- getRuleInfo(ruleSet: Ruleset, ruleName: string): GlobalRuleInfo<T, O>;
28
- optimizeOption(configSettings: T | RuleConfig<T, O> | undefined): RuleInfo<T, O>;
29
- verify(document: MLDocument<T, O>, locale: LocaleSet, fix: boolean): Promise<Violation[]>;
30
- private _optimize;
5
+ import type { GlobalRuleInfo, PlainData, Rule, RuleConfigValue, RuleInfo, Severity, Violation } from '@markuplint/ml-config';
6
+ export declare class MLRule<T extends RuleConfigValue, O extends PlainData = undefined> {
7
+ #private;
8
+ readonly defaultOptions: O;
9
+ readonly defaultSeverity: Severity;
10
+ readonly defaultValue: T;
11
+ readonly name: string;
12
+ constructor(o: Readonly<RuleSeed<T, O>> & {
13
+ readonly name: string;
14
+ });
15
+ /**
16
+ * The following getter is unused internally,
17
+ * only for extending from 3rd party library
18
+ */
19
+ protected get f(): RuleSeed<T, O>['fix'];
20
+ /**
21
+ * The following getter is unused internally,
22
+ * only for extending from 3rd party library
23
+ */
24
+ protected get v(): RuleSeed<T, O>['verify'];
25
+ getRuleInfo(ruleSet: Ruleset, ruleName: string): GlobalRuleInfo<T, O>;
26
+ optimizeOption(configSettings: Rule<T, O> | null | undefined): RuleInfo<T, O>;
27
+ verify(document: MLDocument<T, O>, locale: LocaleSet, fix: boolean): Promise<Violation[]>;
28
+ private _optimize;
31
29
  }
32
- export type AnyMLRule = MLRule<RuleConfigValue, unknown>;
30
+ export type AnyMLRule = MLRule<RuleConfigValue, PlainData>;
@@ -3,6 +3,8 @@ var _MLRule_f, _MLRule_v;
3
3
  Object.defineProperty(exports, "__esModule", { value: true });
4
4
  exports.MLRule = void 0;
5
5
  const tslib_1 = require("tslib");
6
+ const ml_config_1 = require("@markuplint/ml-config");
7
+ const is_plain_object_1 = require("is-plain-object");
6
8
  const ml_rule_context_1 = require("./ml-rule-context");
7
9
  class MLRule {
8
10
  constructor(o) {
@@ -10,9 +12,9 @@ class MLRule {
10
12
  _MLRule_f.set(this, void 0);
11
13
  _MLRule_v.set(this, void 0);
12
14
  this.name = o.name;
13
- this.defaultSeverity = o.defaultSeverity || 'error';
14
- this.defaultValue = (_a = o.defaultValue) !== null && _a !== void 0 ? _a : true;
15
- this.defaultOptions = (_b = o.defaultOptions) !== null && _b !== void 0 ? _b : null;
15
+ this.defaultSeverity = (_a = o.defaultSeverity) !== null && _a !== void 0 ? _a : 'error';
16
+ this.defaultValue = ((_b = o.defaultValue) !== null && _b !== void 0 ? _b : true);
17
+ this.defaultOptions = o.defaultOptions;
16
18
  tslib_1.__classPrivateFieldSet(this, _MLRule_v, o.verify, "f");
17
19
  tslib_1.__classPrivateFieldSet(this, _MLRule_f, o.fix, "f");
18
20
  }
@@ -48,23 +50,12 @@ class MLRule {
48
50
  reason: undefined,
49
51
  };
50
52
  }
51
- if (!Array.isArray(configSettings) && typeof configSettings === 'object' && configSettings !== null) {
53
+ if (isRuleConfig(configSettings)) {
52
54
  return {
53
55
  disabled: false,
54
56
  severity: configSettings.severity || this.defaultSeverity,
55
57
  value: configSettings.value !== undefined ? configSettings.value : this.defaultValue,
56
- options: Array.isArray(this.defaultOptions)
57
- ? configSettings.options
58
- ? // prettier-ignore
59
- // @ts-ignore for "as" casting
60
- this.defaultOptions.concat(configSettings.option)
61
- : this.defaultOptions
62
- : this.defaultOptions !== null &&
63
- typeof this.defaultOptions === 'object' &&
64
- // for example `configSettings.option === true`
65
- (configSettings.options == null || typeof configSettings.options === 'object')
66
- ? { ...this.defaultOptions, ...(configSettings.options || {}) }
67
- : configSettings.options || this.defaultOptions,
58
+ options: mergeOptions(this.defaultOptions, configSettings.options),
68
59
  reason: configSettings.reason,
69
60
  };
70
61
  }
@@ -76,7 +67,9 @@ class MLRule {
76
67
  reason: undefined,
77
68
  };
78
69
  }
79
- async verify(document, locale, fix) {
70
+ async verify(
71
+ // eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
72
+ document, locale, fix) {
80
73
  if (!tslib_1.__classPrivateFieldGet(this, _MLRule_v, "f")) {
81
74
  return [];
82
75
  }
@@ -104,10 +97,9 @@ class MLRule {
104
97
  col,
105
98
  raw,
106
99
  ruleId: this.name,
100
+ reason: report.scope.rule.reason || document.rule.reason,
107
101
  };
108
- if (report.scope.rule.reason || document.rule.reason) {
109
- violation.reason = report.scope.rule.reason || document.rule.reason;
110
- }
102
+ (0, ml_config_1.deleteUndefProp)(violation);
111
103
  return violation;
112
104
  }
113
105
  const violation = {
@@ -117,20 +109,34 @@ class MLRule {
117
109
  col: report.col,
118
110
  raw: report.raw,
119
111
  ruleId: this.name,
112
+ reason: document.rule.reason,
120
113
  };
121
- if (document.rule.reason) {
122
- violation.reason = document.rule.reason;
123
- }
114
+ (0, ml_config_1.deleteUndefProp)(violation);
124
115
  return violation;
125
116
  });
126
117
  document.setRule(null);
127
118
  return violation;
128
119
  }
129
120
  _optimize(rules, ruleName) {
130
- const rule = (rules && rules[ruleName]) || false;
121
+ var _a;
122
+ const rule = ((_a = rules === null || rules === void 0 ? void 0 : rules[ruleName]) !== null && _a !== void 0 ? _a : false);
131
123
  const info = this.optimizeOption(rule);
132
124
  return info;
133
125
  }
134
126
  }
135
127
  exports.MLRule = MLRule;
136
128
  _MLRule_f = new WeakMap(), _MLRule_v = new WeakMap();
129
+ function isRuleConfig(data) {
130
+ return (0, is_plain_object_1.isPlainObject)(data);
131
+ }
132
+ function mergeOptions(a, b) {
133
+ if (Array.isArray(a) && Array.isArray(b)) {
134
+ // @ts-ignore
135
+ return [...a, ...b];
136
+ }
137
+ if ((0, is_plain_object_1.isPlainObject)(a) && (0, is_plain_object_1.isPlainObject)(b)) {
138
+ // @ts-ignore
139
+ return { ...a, ...b };
140
+ }
141
+ return b !== null && b !== void 0 ? b : a;
142
+ }
@@ -1,26 +1,20 @@
1
- import type { Attr, Element } from '../ml-dom';
2
1
  import type { MLRuleContext } from './ml-rule-context';
2
+ import type { Attr, Element } from '../ml-dom';
3
3
  import type { Translator } from '@markuplint/i18n';
4
- import type { Report, RuleConfigValue, Severity } from '@markuplint/ml-config';
5
- export type RuleSeed<T extends RuleConfigValue = boolean, O = null> = {
6
- defaultSeverity?: Severity;
7
- defaultValue?: T;
8
- defaultOptions?: O;
9
- verify(context: ReturnType<MLRuleContext<T, O>['provide']>): void | Promise<void>;
10
- fix?(context: ReturnType<MLRuleContext<T, O>['provide']>): void | Promise<void>;
4
+ import type { PlainData, Report, RuleConfigValue, Severity } from '@markuplint/ml-config';
5
+ export type RuleSeed<T extends RuleConfigValue = boolean, O extends PlainData = undefined> = {
6
+ readonly defaultSeverity?: Severity;
7
+ readonly defaultValue?: T;
8
+ readonly defaultOptions?: O;
9
+ verify(context: ReturnType<MLRuleContext<T, O>['provide']>): void | Promise<void>;
10
+ fix?(context: ReturnType<MLRuleContext<T, O>['provide']>): void | Promise<void>;
11
11
  };
12
- export type Checker<T extends RuleConfigValue, O = null, P extends Record<string, unknown> = {}> = (
13
- params: P,
14
- ) => CheckerReport<T, O>;
15
- export type ElementChecker<T extends RuleConfigValue, O = null, P extends Record<string, unknown> = {}> = (
16
- params: P & {
17
- el: Element<T, O>;
18
- },
19
- ) => CheckerReport<T, O>;
20
- export type AttrChecker<T extends RuleConfigValue, O = null, P extends Record<string, unknown> = {}> = (
21
- params: P & {
22
- attr: Attr<T, O>;
23
- },
24
- ) => CheckerReport<T, O>;
25
- export type CheckerReport<T extends RuleConfigValue, O = null> = (t: Translator) => Report<T, O> | undefined | null;
26
- export type AnyRuleSeed = RuleSeed<any, any>;
12
+ export type Checker<T extends RuleConfigValue, O extends PlainData = undefined, P extends Record<string, unknown> = {}> = (params: P) => CheckerReport<T, O>;
13
+ export type ElementChecker<T extends RuleConfigValue, O extends PlainData = undefined, P extends Record<string, unknown> = {}> = (params: P & {
14
+ el: Element<T, O>;
15
+ }) => CheckerReport<T, O>;
16
+ export type AttrChecker<T extends RuleConfigValue, O extends PlainData = undefined, P extends Record<string, unknown> = {}> = (params: P & {
17
+ attr: Attr<T, O>;
18
+ }) => CheckerReport<T, O>;
19
+ export type CheckerReport<T extends RuleConfigValue, O extends PlainData = undefined> = (t: Translator) => Report<T, O> | undefined | null;
20
+ export type AnyRuleSeed<T extends RuleConfigValue = RuleConfigValue, O extends PlainData = PlainData> = RuleSeed<T, O>;
@@ -1,2 +1,2 @@
1
1
  import type { PluginCreator, CreatePluginSettings } from './types';
2
- export declare function createPlugin<S extends CreatePluginSettings>(fn: PluginCreator<S>): PluginCreator<S>;
2
+ export declare function createPlugin<S extends CreatePluginSettings>(fn: Readonly<PluginCreator<S>>): Readonly<PluginCreator<S>>;
@@ -1,12 +1,12 @@
1
- import type { AnyRuleSeed } from '../ml-rule';
1
+ import type { RuleSeed } from '../ml-rule';
2
2
  import type { Config } from '@markuplint/ml-config';
3
3
  export type Plugin = {
4
- name: string;
5
- rules?: Record<string, AnyRuleSeed>;
6
- configs?: Record<string, Config>;
4
+ readonly name: string;
5
+ readonly rules?: Readonly<Record<string, Readonly<RuleSeed<any, any>>>>;
6
+ readonly configs?: Readonly<Record<string, Config>>;
7
7
  };
8
8
  export type PluginCreator<S extends CreatePluginSettings> = {
9
- name: string;
10
- create(setting: S): Omit<Plugin, 'name'>;
9
+ readonly name: string;
10
+ create(setting: S): Omit<Plugin, 'name'>;
11
11
  };
12
- export type CreatePluginSettings = Record<string, unknown>;
12
+ export type CreatePluginSettings = Readonly<Record<string, unknown>>;
@@ -1,7 +1,7 @@
1
1
  import type { ChildNodeRule, Config, NodeRule, Rules } from '@markuplint/ml-config';
2
2
  export default class Ruleset {
3
- readonly childNodeRules: ReadonlyArray<ChildNodeRule>;
4
- readonly nodeRules: ReadonlyArray<NodeRule>;
5
- readonly rules: Readonly<Rules>;
6
- constructor(config: Config);
3
+ readonly childNodeRules: readonly ChildNodeRule[];
4
+ readonly nodeRules: readonly NodeRule[];
5
+ readonly rules: Rules;
6
+ constructor(config: Config);
7
7
  }
@@ -2,10 +2,10 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  class Ruleset {
4
4
  constructor(config) {
5
- // TODO: deep freeze
6
- this.rules = Object.freeze(config.rules || {});
7
- this.nodeRules = Object.freeze(config.nodeRules || []);
8
- this.childNodeRules = Object.freeze(config.childNodeRules || []);
5
+ var _a, _b, _c;
6
+ this.rules = (_a = config.rules) !== null && _a !== void 0 ? _a : {};
7
+ this.nodeRules = (_b = config.nodeRules) !== null && _b !== void 0 ? _b : [];
8
+ this.childNodeRules = (_c = config.childNodeRules) !== null && _c !== void 0 ? _c : [];
9
9
  }
10
10
  }
11
11
  exports.default = Ruleset;
@@ -1,28 +1,16 @@
1
1
  import type { MLMarkupLanguageParser } from '@markuplint/ml-ast';
2
- import type { Config, RuleConfigValue } from '@markuplint/ml-config';
2
+ import type { Config, PlainData, RuleConfigValue } from '@markuplint/ml-config';
3
3
  import type { ExtendedSpec, MLMLSpec } from '@markuplint/ml-spec';
4
4
  import { Document } from '../ml-dom';
5
5
  export type CreateTestOptions = {
6
- config?: Config;
7
- parser?: MLMarkupLanguageParser;
8
- specs?: MLMLSpec;
6
+ readonly config?: Config;
7
+ readonly parser?: Readonly<MLMarkupLanguageParser>;
8
+ readonly specs?: MLMLSpec;
9
9
  };
10
- export declare function createTestDocument<T extends RuleConfigValue = any, O = any>(
11
- sourceCode: string,
12
- options?: CreateTestOptions,
13
- ): Document<T, O>;
14
- export declare function createTestNodeList(
15
- sourceCode: string,
16
- options?: CreateTestOptions,
17
- ): readonly import('../ml-dom/node/node').MLNode<any, any, import('@markuplint/ml-ast').MLASTAbstractNode>[];
18
- export declare function createTestTokenList(
19
- sourceCode: string,
20
- options?: CreateTestOptions,
21
- ): readonly import('../ml-dom/token/token').MLToken<import('@markuplint/ml-ast').MLToken>[];
22
- export declare function createTestElement(
23
- sourceCode: string,
24
- options?: CreateTestOptions,
25
- ): import('../ml-dom').Element<any, any>;
10
+ export declare function createTestDocument<T extends RuleConfigValue = any, O extends PlainData = any>(sourceCode: string, options?: CreateTestOptions): Document<T, O>;
11
+ export declare function createTestNodeList(sourceCode: string, options?: CreateTestOptions): readonly import("../ml-dom/node/node").MLNode<any, any, import("@markuplint/ml-ast").MLASTAbstractNode>[];
12
+ export declare function createTestTokenList(sourceCode: string, options?: CreateTestOptions): readonly import("../ml-dom/token/token").MLToken<import("@markuplint/ml-ast").MLToken>[];
13
+ export declare function createTestElement(sourceCode: string, options?: CreateTestOptions): import("../ml-dom").Element<any, any>;
26
14
  /**
27
15
  * for test suite
28
16
  */
package/lib/test/index.js CHANGED
@@ -27,7 +27,7 @@ exports.createTestTokenList = createTestTokenList;
27
27
  function createTestElement(sourceCode, options) {
28
28
  const document = createTestDocument(sourceCode, options);
29
29
  const el = document.nodeList[0];
30
- if (el.is(el.ELEMENT_NODE)) {
30
+ if (el && el.is(el.ELEMENT_NODE)) {
31
31
  return el;
32
32
  }
33
33
  throw TypeError(`Could not parse it to be an element from: ${sourceCode}`);
package/lib/types.d.ts CHANGED
@@ -4,13 +4,14 @@ import type { LocaleSet } from '@markuplint/i18n';
4
4
  import type { MLMarkupLanguageParser, ParserOptions } from '@markuplint/ml-ast';
5
5
  import type { Pretender } from '@markuplint/ml-config';
6
6
  import type { ExtendedSpec, MLMLSpec } from '@markuplint/ml-spec';
7
- export type MLSchema = Readonly<[MLMLSpec, ...ExtendedSpec[]]>;
7
+ export type MLSchema = readonly [MLMLSpec, ...ExtendedSpec[]];
8
8
  export type MLFabric = {
9
- parser: MLMarkupLanguageParser;
10
- ruleset: Partial<Ruleset>;
11
- rules: AnyMLRule[];
12
- locale: LocaleSet;
13
- schemas: MLSchema;
14
- parserOptions: ParserOptions;
15
- pretenders: Pretender[];
9
+ readonly parser: Readonly<MLMarkupLanguageParser>;
10
+ readonly ruleset: Partial<Readonly<Ruleset>>;
11
+ readonly rules: readonly Readonly<AnyMLRule>[];
12
+ readonly locale: LocaleSet;
13
+ readonly schemas: MLSchema;
14
+ readonly parserOptions: ParserOptions;
15
+ readonly pretenders: readonly Pretender[];
16
+ readonly configErrors?: readonly Readonly<Error>[];
16
17
  };
@@ -1,12 +1,7 @@
1
1
  interface Location {
2
- line: number;
3
- col: number;
4
- raw: string;
2
+ line: number;
3
+ col: number;
4
+ raw: string;
5
5
  }
6
- export declare function getLocationFromChars(
7
- searches: string[],
8
- text: string,
9
- currentLine: number,
10
- currentCol: number,
11
- ): Location[];
6
+ export declare function getLocationFromChars(searches: readonly string[], text: string, currentLine: number, currentCol: number): Location[];
12
7
  export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@markuplint/ml-core",
3
- "version": "3.3.1",
3
+ "version": "3.5.0",
4
4
  "description": "The core module of markuplint",
5
5
  "repository": "git@github.com:markuplint/markuplint.git",
6
6
  "author": "Yusuke Hirao <yusukehirao@me.com>",
@@ -23,21 +23,23 @@
23
23
  "./lib/configs.js": "./lib/configs.browser.js"
24
24
  },
25
25
  "dependencies": {
26
- "@markuplint/config-presets": "3.3.0",
27
- "@markuplint/html-parser": "3.3.1",
28
- "@markuplint/html-spec": "3.3.1",
29
- "@markuplint/i18n": "3.3.0",
30
- "@markuplint/ml-ast": "3.0.0",
31
- "@markuplint/ml-config": "3.3.0",
32
- "@markuplint/ml-spec": "3.3.0",
33
- "@markuplint/parser-utils": "3.3.0",
34
- "@markuplint/selector": "3.3.0",
26
+ "@markuplint/config-presets": "3.4.0",
27
+ "@markuplint/html-parser": "3.5.0",
28
+ "@markuplint/html-spec": "3.5.0",
29
+ "@markuplint/i18n": "3.5.0",
30
+ "@markuplint/ml-ast": "3.1.0",
31
+ "@markuplint/ml-config": "3.5.0",
32
+ "@markuplint/ml-spec": "3.5.0",
33
+ "@markuplint/parser-utils": "3.5.0",
34
+ "@markuplint/selector": "3.5.0",
35
35
  "debug": "^4.3.4",
36
+ "is-plain-object": "^5.0.0",
36
37
  "tslib": "^2.4.1"
37
38
  },
38
39
  "devDependencies": {
39
40
  "@markuplint/html-parser": "3.3.0",
40
- "@types/debug": "^4.1.7"
41
+ "@types/debug": "^4.1.7",
42
+ "type-fest": "^3.6.1"
41
43
  },
42
- "gitHead": "f19e7de726cf01d53342bc5513c30da75d28da63"
44
+ "gitHead": "0c47b2c2722f6823a17f36edbab98486275f8ab4"
43
45
  }