@markuplint/ml-core 3.4.0 → 3.6.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 (61) hide show
  1. package/lib/configs.js +1 -2
  2. package/lib/ml-core.d.ts +5 -5
  3. package/lib/ml-core.js +4 -4
  4. package/lib/ml-dom/helper/accname.js +18 -7
  5. package/lib/ml-dom/helper/create-node.d.ts +6 -5
  6. package/lib/ml-dom/helper/create-node.js +3 -1
  7. package/lib/ml-dom/helper/debug.js +9 -4
  8. package/lib/ml-dom/helper/getIndent.js +18 -12
  9. package/lib/ml-dom/helper/walkers.d.ts +7 -5
  10. package/lib/ml-dom/helper/walkers.js +4 -2
  11. package/lib/ml-dom/manipulations/child-node-methods.d.ts +7 -7
  12. package/lib/ml-dom/manipulations/child-node-methods.js +24 -6
  13. package/lib/ml-dom/manipulations/get-children.d.ts +2 -2
  14. package/lib/ml-dom/manipulations/get-children.js +3 -1
  15. package/lib/ml-dom/node/attr.d.ts +5 -2
  16. package/lib/ml-dom/node/attr.js +8 -4
  17. package/lib/ml-dom/node/block.d.ts +6 -2
  18. package/lib/ml-dom/node/block.js +14 -4
  19. package/lib/ml-dom/node/character-data.d.ts +2 -2
  20. package/lib/ml-dom/node/character-data.js +9 -3
  21. package/lib/ml-dom/node/child-node.d.ts +5 -3
  22. package/lib/ml-dom/node/child-node.js +3 -1
  23. package/lib/ml-dom/node/comment.d.ts +2 -2
  24. package/lib/ml-dom/node/document-fragment.d.ts +2 -2
  25. package/lib/ml-dom/node/document-type.d.ts +2 -2
  26. package/lib/ml-dom/node/document-type.js +14 -4
  27. package/lib/ml-dom/node/document.d.ts +20 -16
  28. package/lib/ml-dom/node/document.js +44 -19
  29. package/lib/ml-dom/node/dom-token-list.d.ts +2 -2
  30. package/lib/ml-dom/node/dom-token-list.js +4 -2
  31. package/lib/ml-dom/node/element.d.ts +15 -7
  32. package/lib/ml-dom/node/element.js +76 -27
  33. package/lib/ml-dom/node/named-node-map.d.ts +3 -3
  34. package/lib/ml-dom/node/named-node-map.js +11 -4
  35. package/lib/ml-dom/node/node-list.d.ts +4 -4
  36. package/lib/ml-dom/node/node-list.js +8 -3
  37. package/lib/ml-dom/node/node-store.d.ts +8 -3
  38. package/lib/ml-dom/node/node-store.js +8 -3
  39. package/lib/ml-dom/node/node.d.ts +2 -2
  40. package/lib/ml-dom/node/node.js +48 -17
  41. package/lib/ml-dom/node/parent-node.d.ts +2 -2
  42. package/lib/ml-dom/node/parent-node.js +15 -6
  43. package/lib/ml-dom/node/rule-mapper.d.ts +3 -3
  44. package/lib/ml-dom/node/rule-mapper.js +8 -3
  45. package/lib/ml-dom/node/text.d.ts +2 -2
  46. package/lib/ml-dom/node/types.d.ts +18 -6
  47. package/lib/ml-rule/create-rule.d.ts +4 -2
  48. package/lib/ml-rule/create-test-rule.d.ts +4 -4
  49. package/lib/ml-rule/ml-rule-context.d.ts +2 -2
  50. package/lib/ml-rule/ml-rule-context.js +3 -1
  51. package/lib/ml-rule/ml-rule.d.ts +14 -6
  52. package/lib/ml-rule/ml-rule.js +33 -28
  53. package/lib/ml-rule/types.d.ts +24 -12
  54. package/lib/plugin/plugin.d.ts +3 -1
  55. package/lib/plugin/types.d.ts +6 -6
  56. package/lib/ruleset/index.d.ts +3 -3
  57. package/lib/ruleset/index.js +4 -4
  58. package/lib/test/index.d.ts +5 -5
  59. package/lib/types.d.ts +9 -8
  60. package/lib/utils/get-location-from-chars.d.ts +1 -1
  61. package/package.json +14 -13
@@ -48,14 +48,16 @@ class MLParentNode extends node_1.MLNode {
48
48
  * @see https://dom.spec.whatwg.org/#ref-for-dom-parentnode-firstelementchild%E2%91%A0
49
49
  */
50
50
  get firstElementChild() {
51
- return this.children[0] || null;
51
+ var _a;
52
+ return (_a = this.children[0]) !== null && _a !== void 0 ? _a : null;
52
53
  }
53
54
  /**
54
55
  * @implements DOM API: `Element`, `Document`, `DocumentFragment`
55
56
  * @see https://dom.spec.whatwg.org/#ref-for-dom-parentnode-lastelementchild%E2%91%A0
56
57
  */
57
58
  get lastElementChild() {
58
- return this.children[0] || null;
59
+ var _a;
60
+ return (_a = this.children[0]) !== null && _a !== void 0 ? _a : null;
59
61
  }
60
62
  /**
61
63
  * **IT THROWS AN ERROR WHEN CALLING THIS.**
@@ -64,7 +66,9 @@ class MLParentNode extends node_1.MLNode {
64
66
  * @implements DOM API: `Element`, `Document`, `DocumentFragment`
65
67
  * @see https://dom.spec.whatwg.org/#ref-for-dom-parentnode-append%E2%91%A0
66
68
  */
67
- append(...nodes) {
69
+ append(
70
+ // eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
71
+ ...nodes) {
68
72
  throw new unexpected_call_error_1.default('Not supported "append" method');
69
73
  }
70
74
  /**
@@ -74,7 +78,9 @@ class MLParentNode extends node_1.MLNode {
74
78
  * @implements DOM API: `Element`, `Document`, `DocumentFragment`
75
79
  * @see https://dom.spec.whatwg.org/#ref-for-dom-parentnode-prepend%E2%91%A0
76
80
  */
77
- prepend(...nodes) {
81
+ prepend(
82
+ // eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
83
+ ...nodes) {
78
84
  throw new unexpected_call_error_1.default('Not supported "prepend" method');
79
85
  }
80
86
  /**
@@ -82,8 +88,9 @@ class MLParentNode extends node_1.MLNode {
82
88
  * @see https://dom.spec.whatwg.org/#ref-for-dom-parentnode-queryselector%E2%91%A0
83
89
  */
84
90
  querySelector(selectors) {
91
+ var _a;
85
92
  const selected = this.querySelectorAll(selectors);
86
- return selected[0] || null;
93
+ return (_a = selected[0]) !== null && _a !== void 0 ? _a : null;
87
94
  }
88
95
  /**
89
96
  * @implements DOM API: `Element`, `Document`, `DocumentFragment`
@@ -109,7 +116,9 @@ class MLParentNode extends node_1.MLNode {
109
116
  * @implements DOM API: `Element`, `Document`, `DocumentFragment`
110
117
  * @see https://dom.spec.whatwg.org/#ref-for-dom-parentnode-replacechildren%E2%91%A0
111
118
  */
112
- replaceChildren(...nodes) {
119
+ replaceChildren(
120
+ // eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
121
+ ...nodes) {
113
122
  throw new unexpected_call_error_1.default('Not supported "replaceChildren" method');
114
123
  }
115
124
  _descendantsToArray(filter) {
@@ -4,9 +4,9 @@ import type { AnyRule } from '@markuplint/ml-config';
4
4
  import type { Specificity } from '@markuplint/selector';
5
5
  type RuleType = 'rules' | 'nodeRules' | 'childNodeRules';
6
6
  type MappingLayer = {
7
- from: RuleType;
8
- specificity: Specificity;
9
- rule: AnyRule;
7
+ readonly from: RuleType;
8
+ readonly specificity: Specificity;
9
+ readonly rule: AnyRule;
10
10
  };
11
11
  export declare class RuleMapper {
12
12
  #private;
@@ -9,7 +9,9 @@ const ruleMapperLog = debug_1.log.extend('rule-mapper');
9
9
  const ruleMapperNodeLog = ruleMapperLog.extend('node');
10
10
  const ruleMapperNodeRuleLog = ruleMapperNodeLog.extend('rule');
11
11
  class RuleMapper {
12
- constructor(document) {
12
+ constructor(
13
+ // eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
14
+ document) {
13
15
  _RuleMapper_nodeList.set(this, void 0);
14
16
  _RuleMapper_ruleMap.set(this, new Map());
15
17
  tslib_1.__classPrivateFieldSet(this, _RuleMapper_nodeList, Object.freeze([document, ...document.nodeList]), "f");
@@ -32,8 +34,11 @@ class RuleMapper {
32
34
  });
33
35
  });
34
36
  }
35
- set(node, ruleName, rule) {
36
- const rules = tslib_1.__classPrivateFieldGet(this, _RuleMapper_ruleMap, "f").get(node.uuid) || {};
37
+ set(
38
+ // eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
39
+ node, ruleName, rule) {
40
+ var _a;
41
+ const rules = (_a = tslib_1.__classPrivateFieldGet(this, _RuleMapper_ruleMap, "f").get(node.uuid)) !== null && _a !== void 0 ? _a : {};
37
42
  const currentRule = rules[ruleName];
38
43
  if (currentRule) {
39
44
  const order = (0, selector_1.compareSpecificity)(currentRule.specificity, rule.specificity);
@@ -1,8 +1,8 @@
1
1
  import type { TextNodeType } from './types';
2
2
  import type { MLASTText } from '@markuplint/ml-ast';
3
- import type { RuleConfigValue } from '@markuplint/ml-config';
3
+ import type { PlainData, RuleConfigValue } from '@markuplint/ml-config';
4
4
  import { MLCharacterData } from './character-data';
5
- export declare class MLText<T extends RuleConfigValue, O = null>
5
+ export declare class MLText<T extends RuleConfigValue, O extends PlainData = undefined>
6
6
  extends MLCharacterData<T, O, MLASTText>
7
7
  implements Text
8
8
  {
@@ -19,8 +19,8 @@ import type {
19
19
  MLASTText,
20
20
  MLToken as MLASTToken,
21
21
  } from '@markuplint/ml-ast/';
22
- import type { PretenderARIA, RuleConfigValue } from '@markuplint/ml-config';
23
- export type MappedNode<N, T extends RuleConfigValue, O = null> = N extends MLASTElement
22
+ import type { PlainData, PretenderARIA, RuleConfigValue } from '@markuplint/ml-config';
23
+ export type MappedNode<N, T extends RuleConfigValue, O extends PlainData = undefined> = N extends MLASTElement
24
24
  ? MLElement<T, O>
25
25
  : N extends MLASTParentNode
26
26
  ? MLElement<T, O>
@@ -39,7 +39,11 @@ export type MappedNode<N, T extends RuleConfigValue, O = null> = N extends MLAST
39
39
  : N extends MLASTToken
40
40
  ? MLToken
41
41
  : never;
42
- export type NodeTypeOf<NT extends NodeType, T extends RuleConfigValue, O = null> = NT extends ElementNodeType
42
+ export type NodeTypeOf<
43
+ NT extends NodeType,
44
+ T extends RuleConfigValue,
45
+ O extends PlainData = undefined,
46
+ > = NT extends ElementNodeType
43
47
  ? MLElement<T, O>
44
48
  : NT extends CommentNodeType
45
49
  ? MLComment<T, O>
@@ -77,15 +81,23 @@ export type NodeType =
77
81
  | DocumentTypeNodeType
78
82
  | DocumentFragmentNodeType
79
83
  | MarkuplintPreprocessorBlockType;
80
- export type PretenderContext<N extends MLElement<T, O>, T extends RuleConfigValue, O = null> =
84
+ export type PretenderContext<N extends MLElement<T, O>, T extends RuleConfigValue, O extends PlainData = undefined> =
81
85
  | PretenderContextPretender<N, T, O>
82
86
  | PretenderContextPretended<N, T, O>;
83
- export type PretenderContextPretender<N extends MLElement<T, O>, T extends RuleConfigValue, O = null> = {
87
+ export type PretenderContextPretender<
88
+ N extends MLElement<T, O>,
89
+ T extends RuleConfigValue,
90
+ O extends PlainData = undefined,
91
+ > = {
84
92
  readonly type: 'pretender';
85
93
  readonly as: N;
86
94
  readonly aria?: PretenderARIA;
87
95
  };
88
- export type PretenderContextPretended<N extends MLElement<T, O>, T extends RuleConfigValue, O = null> = {
96
+ export type PretenderContextPretended<
97
+ N extends MLElement<T, O>,
98
+ T extends RuleConfigValue,
99
+ O extends PlainData = undefined,
100
+ > = {
89
101
  readonly type: 'origin';
90
102
  readonly origin: N;
91
103
  };
@@ -1,3 +1,5 @@
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>(
4
+ seed: Readonly<RuleSeed<T, O>>,
5
+ ): Readonly<RuleSeed<T, O>>;
@@ -1,8 +1,8 @@
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;
4
+ export declare function createRule<T extends RuleConfigValue, O extends PlainData = undefined>(
5
+ seed: Readonly<RuleSeed<T, O>> & {
6
+ readonly name: string;
7
7
  },
8
8
  ): MLRule<T, O>;
@@ -1,8 +1,8 @@
1
1
  import type { CheckerReport } from './types';
2
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> {
4
+ import type { PlainData, Report, RuleConfigValue } from '@markuplint/ml-config';
5
+ export declare class MLRuleContext<T extends RuleConfigValue, O extends PlainData = undefined> {
6
6
  #private;
7
7
  readonly document: MLDocument<T, O>;
8
8
  readonly locale: string;
@@ -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);
@@ -2,16 +2,24 @@ import type { RuleSeed } from './types';
2
2
  import type { Ruleset } from '..';
3
3
  import type { MLDocument } from '../ml-dom/node/document';
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> {
5
+ import type {
6
+ GlobalRuleInfo,
7
+ PlainData,
8
+ Rule,
9
+ RuleConfigValue,
10
+ RuleInfo,
11
+ Severity,
12
+ Violation,
13
+ } from '@markuplint/ml-config';
14
+ export declare class MLRule<T extends RuleConfigValue, O extends PlainData = undefined> {
7
15
  #private;
8
16
  readonly defaultOptions: O;
9
17
  readonly defaultSeverity: Severity;
10
18
  readonly defaultValue: T;
11
19
  readonly name: string;
12
20
  constructor(
13
- o: RuleSeed<T, O> & {
14
- name: string;
21
+ o: Readonly<RuleSeed<T, O>> & {
22
+ readonly name: string;
15
23
  },
16
24
  );
17
25
  /**
@@ -25,8 +33,8 @@ export declare class MLRule<T extends RuleConfigValue, O = null> {
25
33
  */
26
34
  protected get v(): RuleSeed<T, O>['verify'];
27
35
  getRuleInfo(ruleSet: Ruleset, ruleName: string): GlobalRuleInfo<T, O>;
28
- optimizeOption(configSettings: T | RuleConfig<T, O> | undefined): RuleInfo<T, O>;
36
+ optimizeOption(configSettings: Rule<T, O> | null | undefined): RuleInfo<T, O>;
29
37
  verify(document: MLDocument<T, O>, locale: LocaleSet, fix: boolean): Promise<Violation[]>;
30
38
  private _optimize;
31
39
  }
32
- export type AnyMLRule = MLRule<RuleConfigValue, unknown>;
40
+ 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
  }
@@ -39,6 +41,7 @@ class MLRule {
39
41
  };
40
42
  }
41
43
  optimizeOption(configSettings) {
44
+ var _a;
42
45
  if (configSettings === undefined || typeof configSettings === 'boolean') {
43
46
  return {
44
47
  disabled: !configSettings,
@@ -48,23 +51,12 @@ class MLRule {
48
51
  reason: undefined,
49
52
  };
50
53
  }
51
- if (!Array.isArray(configSettings) && typeof configSettings === 'object' && configSettings !== null) {
54
+ if (isRuleConfig(configSettings)) {
52
55
  return {
53
56
  disabled: false,
54
- severity: configSettings.severity || this.defaultSeverity,
57
+ severity: (_a = configSettings.severity) !== null && _a !== void 0 ? _a : this.defaultSeverity,
55
58
  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,
59
+ options: mergeOptions(this.defaultOptions, configSettings.options),
68
60
  reason: configSettings.reason,
69
61
  };
70
62
  }
@@ -76,10 +68,9 @@ class MLRule {
76
68
  reason: undefined,
77
69
  };
78
70
  }
79
- async verify(document, locale, fix) {
80
- if (!tslib_1.__classPrivateFieldGet(this, _MLRule_v, "f")) {
81
- return [];
82
- }
71
+ async verify(
72
+ // eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
73
+ document, locale, fix) {
83
74
  document.setRule(this);
84
75
  const context = new ml_rule_context_1.MLRuleContext(document, locale);
85
76
  const providableContext = context.provide();
@@ -88,6 +79,7 @@ class MLRule {
88
79
  await tslib_1.__classPrivateFieldGet(this, _MLRule_f, "f").call(this, providableContext);
89
80
  }
90
81
  const violation = context.reports.map(report => {
82
+ var _a;
91
83
  if ('scope' in report) {
92
84
  let line = report.scope.startLine;
93
85
  let col = report.scope.startCol;
@@ -104,10 +96,9 @@ class MLRule {
104
96
  col,
105
97
  raw,
106
98
  ruleId: this.name,
99
+ reason: (_a = report.scope.rule.reason) !== null && _a !== void 0 ? _a : document.rule.reason,
107
100
  };
108
- if (report.scope.rule.reason || document.rule.reason) {
109
- violation.reason = report.scope.rule.reason || document.rule.reason;
110
- }
101
+ (0, ml_config_1.deleteUndefProp)(violation);
111
102
  return violation;
112
103
  }
113
104
  const violation = {
@@ -117,20 +108,34 @@ class MLRule {
117
108
  col: report.col,
118
109
  raw: report.raw,
119
110
  ruleId: this.name,
111
+ reason: document.rule.reason,
120
112
  };
121
- if (document.rule.reason) {
122
- violation.reason = document.rule.reason;
123
- }
113
+ (0, ml_config_1.deleteUndefProp)(violation);
124
114
  return violation;
125
115
  });
126
116
  document.setRule(null);
127
117
  return violation;
128
118
  }
129
119
  _optimize(rules, ruleName) {
130
- const rule = (rules && rules[ruleName]) || false;
120
+ var _a;
121
+ const rule = ((_a = rules === null || rules === void 0 ? void 0 : rules[ruleName]) !== null && _a !== void 0 ? _a : false);
131
122
  const info = this.optimizeOption(rule);
132
123
  return info;
133
124
  }
134
125
  }
135
126
  exports.MLRule = MLRule;
136
127
  _MLRule_f = new WeakMap(), _MLRule_v = new WeakMap();
128
+ function isRuleConfig(data) {
129
+ return (0, is_plain_object_1.isPlainObject)(data);
130
+ }
131
+ function mergeOptions(a, b) {
132
+ if (Array.isArray(a) && Array.isArray(b)) {
133
+ // @ts-ignore
134
+ return [...a, ...b];
135
+ }
136
+ if ((0, is_plain_object_1.isPlainObject)(a) && (0, is_plain_object_1.isPlainObject)(b)) {
137
+ // @ts-ignore
138
+ return { ...a, ...b };
139
+ }
140
+ return b !== null && b !== void 0 ? b : a;
141
+ }
@@ -1,26 +1,38 @@
1
1
  import type { MLRuleContext } from './ml-rule-context';
2
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;
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
9
  verify(context: ReturnType<MLRuleContext<T, O>['provide']>): void | Promise<void>;
10
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> = {}> = (
12
+ export type Checker<
13
+ T extends RuleConfigValue,
14
+ O extends PlainData = undefined,
15
+ P extends Record<string, unknown> = {},
16
+ > = (params: P) => CheckerReport<T, O>;
17
+ export type ElementChecker<
18
+ T extends RuleConfigValue,
19
+ O extends PlainData = undefined,
20
+ P extends Record<string, unknown> = {},
21
+ > = (
16
22
  params: P & {
17
23
  el: Element<T, O>;
18
24
  },
19
25
  ) => CheckerReport<T, O>;
20
- export type AttrChecker<T extends RuleConfigValue, O = null, P extends Record<string, unknown> = {}> = (
26
+ export type AttrChecker<
27
+ T extends RuleConfigValue,
28
+ O extends PlainData = undefined,
29
+ P extends Record<string, unknown> = {},
30
+ > = (
21
31
  params: P & {
22
32
  attr: Attr<T, O>;
23
33
  },
24
34
  ) => 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>;
35
+ export type CheckerReport<T extends RuleConfigValue, O extends PlainData = undefined> = (
36
+ t: Translator,
37
+ ) => Report<T, O> | undefined | null;
38
+ export type AnyRuleSeed<T extends RuleConfigValue = RuleConfigValue, O extends PlainData = PlainData> = RuleSeed<T, O>;
@@ -1,2 +1,4 @@
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>(
3
+ fn: Readonly<PluginCreator<S>>,
4
+ ): 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;
9
+ readonly name: string;
10
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>;
3
+ readonly childNodeRules: readonly ChildNodeRule[];
4
+ readonly nodeRules: readonly NodeRule[];
5
+ readonly rules: Rules;
6
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,13 +1,13 @@
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>(
10
+ export declare function createTestDocument<T extends RuleConfigValue = any, O extends PlainData = any>(
11
11
  sourceCode: string,
12
12
  options?: CreateTestOptions,
13
13
  ): Document<T, O>;
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
  };
@@ -4,7 +4,7 @@ interface Location {
4
4
  raw: string;
5
5
  }
6
6
  export declare function getLocationFromChars(
7
- searches: string[],
7
+ searches: readonly string[],
8
8
  text: string,
9
9
  currentLine: number,
10
10
  currentCol: number,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@markuplint/ml-core",
3
- "version": "3.4.0",
3
+ "version": "3.6.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,22 @@
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.4.0",
28
- "@markuplint/html-spec": "3.4.0",
29
- "@markuplint/i18n": "3.4.0",
30
- "@markuplint/ml-ast": "3.0.0",
31
- "@markuplint/ml-config": "3.4.0",
32
- "@markuplint/ml-spec": "3.4.0",
33
- "@markuplint/parser-utils": "3.4.0",
34
- "@markuplint/selector": "3.4.0",
26
+ "@markuplint/config-presets": "3.5.0",
27
+ "@markuplint/html-parser": "3.6.0",
28
+ "@markuplint/html-spec": "3.6.0",
29
+ "@markuplint/i18n": "3.6.0",
30
+ "@markuplint/ml-ast": "3.1.0",
31
+ "@markuplint/ml-config": "3.6.0",
32
+ "@markuplint/ml-spec": "3.6.0",
33
+ "@markuplint/parser-utils": "3.6.0",
34
+ "@markuplint/selector": "3.6.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
- "@markuplint/html-parser": "3.3.0",
40
- "@types/debug": "^4.1.7"
40
+ "@types/debug": "^4.1.7",
41
+ "type-fest": "^3.6.1"
41
42
  },
42
- "gitHead": "a83e0f5f214a9bbcc0286b9e269074ddca6189e7"
43
+ "gitHead": "715dd53d3b1064a9bcf616c1533921cad9e3b187"
43
44
  }