@markuplint/ml-core 2.3.3 → 3.0.0-alpha.1
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.
- package/lib/configs.d.ts +1 -1
- package/lib/configs.js +29 -9
- package/lib/index.d.ts +8 -8
- package/lib/index.js +18 -10
- package/lib/ml-core.d.ts +3 -3
- package/lib/ml-core.js +48 -44
- package/lib/ml-dom/helper/accname.d.ts +3 -2
- package/lib/ml-dom/helper/accname.js +53 -5
- package/lib/ml-dom/helper/create-node.d.ts +4 -5
- package/lib/ml-dom/helper/create-node.js +12 -16
- package/lib/ml-dom/helper/debug.d.ts +2 -2
- package/lib/ml-dom/helper/debug.js +35 -21
- package/lib/ml-dom/helper/getIndent.d.ts +5 -5
- package/lib/ml-dom/helper/getIndent.js +14 -14
- package/lib/ml-dom/helper/walkers.d.ts +5 -4
- package/lib/ml-dom/helper/walkers.js +39 -3
- package/lib/ml-dom/index.d.ts +8 -3
- package/lib/ml-dom/index.js +3 -15
- package/lib/ml-dom/manipulations/child-node-methods.d.ts +33 -0
- package/lib/ml-dom/manipulations/child-node-methods.js +73 -0
- package/lib/ml-dom/manipulations/get-children.d.ts +4 -0
- package/lib/ml-dom/manipulations/get-children.js +10 -0
- package/lib/ml-dom/node/attr.d.ts +98 -0
- package/lib/ml-dom/node/attr.js +157 -0
- package/lib/ml-dom/node/block.d.ts +38 -0
- package/lib/ml-dom/node/block.js +53 -0
- package/lib/ml-dom/node/character-data.d.ts +57 -0
- package/lib/ml-dom/node/character-data.js +87 -0
- package/lib/ml-dom/node/child-node.d.ts +9 -0
- package/lib/ml-dom/node/child-node.js +10 -0
- package/lib/ml-dom/node/comment.d.ts +17 -0
- package/lib/ml-dom/node/comment.js +24 -0
- package/lib/ml-dom/node/document-fragment.d.ts +24 -0
- package/lib/ml-dom/node/document-fragment.js +33 -0
- package/lib/ml-dom/node/document-type.d.ts +38 -0
- package/lib/ml-dom/node/document-type.js +52 -0
- package/lib/ml-dom/node/document.d.ts +1563 -0
- package/lib/ml-dom/node/document.js +2140 -0
- package/lib/ml-dom/node/dom-token-list.d.ts +33 -0
- package/lib/ml-dom/node/dom-token-list.js +137 -0
- package/lib/ml-dom/node/element.d.ts +1844 -0
- package/lib/ml-dom/node/element.js +2601 -0
- package/lib/ml-dom/node/named-node-map.d.ts +42 -0
- package/lib/ml-dom/node/named-node-map.js +64 -0
- package/lib/ml-dom/node/node-list.d.ts +6 -0
- package/lib/ml-dom/node/node-list.js +39 -0
- package/lib/ml-dom/node/node-store.d.ts +14 -0
- package/lib/ml-dom/{helper → node}/node-store.js +8 -4
- package/lib/ml-dom/node/node.d.ts +482 -0
- package/lib/ml-dom/node/node.js +675 -0
- package/lib/ml-dom/node/parent-node.d.ts +66 -0
- package/lib/ml-dom/node/parent-node.js +131 -0
- package/lib/ml-dom/node/rule-mapper.d.ts +17 -0
- package/lib/ml-dom/{rule-mapper.js → node/rule-mapper.js} +20 -28
- package/lib/ml-dom/node/text.d.ts +51 -0
- package/lib/ml-dom/node/text.js +76 -0
- package/lib/ml-dom/node/types.d.ts +35 -0
- package/lib/ml-dom/{types.js → node/types.js} +0 -0
- package/lib/ml-dom/node/unexpected-call-error.d.ts +2 -0
- package/lib/ml-dom/node/unexpected-call-error.js +5 -0
- package/lib/ml-dom/token/token.d.ts +47 -0
- package/lib/ml-dom/token/token.js +89 -0
- package/lib/ml-rule/ml-rule-context.d.ts +14 -10
- package/lib/ml-rule/ml-rule-context.js +29 -6
- package/lib/ml-rule/ml-rule.d.ts +12 -12
- package/lib/ml-rule/ml-rule.js +63 -63
- package/lib/ml-rule/types.d.ts +12 -2
- package/lib/ruleset/index.d.ts +2 -2
- package/lib/test/index.d.ts +3 -1
- package/lib/test/index.js +12 -5
- package/lib/types.d.ts +3 -2
- package/package.json +11 -10
- package/tsconfig.tsbuildinfo +1 -1
- package/lib/ml-dom/document.d.ts +0 -85
- package/lib/ml-dom/document.js +0 -273
- package/lib/ml-dom/helper/index.d.ts +0 -4
- package/lib/ml-dom/helper/index.js +0 -12
- package/lib/ml-dom/helper/mapped-nodes.d.ts +0 -4
- package/lib/ml-dom/helper/mapped-nodes.js +0 -2
- package/lib/ml-dom/helper/match-selector.d.ts +0 -16
- package/lib/ml-dom/helper/match-selector.js +0 -233
- package/lib/ml-dom/helper/node-store.d.ts +0 -9
- package/lib/ml-dom/helper/selector.d.ts +0 -11
- package/lib/ml-dom/helper/selector.js +0 -549
- package/lib/ml-dom/rule-mapper.d.ts +0 -16
- package/lib/ml-dom/tokens/abstract-element.d.ts +0 -49
- package/lib/ml-dom/tokens/abstract-element.js +0 -249
- package/lib/ml-dom/tokens/attribute.d.ts +0 -42
- package/lib/ml-dom/tokens/attribute.js +0 -85
- package/lib/ml-dom/tokens/comment.d.ts +0 -9
- package/lib/ml-dom/tokens/comment.js +0 -15
- package/lib/ml-dom/tokens/doctype.d.ts +0 -15
- package/lib/ml-dom/tokens/doctype.js +0 -32
- package/lib/ml-dom/tokens/element-close-tag.d.ts +0 -24
- package/lib/ml-dom/tokens/element-close-tag.js +0 -45
- package/lib/ml-dom/tokens/element.d.ts +0 -23
- package/lib/ml-dom/tokens/element.js +0 -66
- package/lib/ml-dom/tokens/index.d.ts +0 -10
- package/lib/ml-dom/tokens/index.js +0 -26
- package/lib/ml-dom/tokens/node.d.ts +0 -39
- package/lib/ml-dom/tokens/node.js +0 -126
- package/lib/ml-dom/tokens/omitted-element.d.ts +0 -10
- package/lib/ml-dom/tokens/omitted-element.js +0 -12
- package/lib/ml-dom/tokens/preprocessor-specific-attribute.d.ts +0 -24
- package/lib/ml-dom/tokens/preprocessor-specific-attribute.js +0 -37
- package/lib/ml-dom/tokens/preprocessor-specific-block.d.ts +0 -11
- package/lib/ml-dom/tokens/preprocessor-specific-block.js +0 -16
- package/lib/ml-dom/tokens/text.d.ts +0 -15
- package/lib/ml-dom/tokens/text.js +0 -26
- package/lib/ml-dom/tokens/token.d.ts +0 -16
- package/lib/ml-dom/tokens/token.js +0 -55
- package/lib/ml-dom/types.d.ts +0 -27
- package/markuplint-recommended.json +0 -196
|
@@ -5,10 +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(document, locale) {
|
|
9
9
|
_MLRuleContext_reports.set(this, []);
|
|
10
10
|
this.document = document;
|
|
11
|
-
this.globalRule = rule;
|
|
12
11
|
this.translate = (0, i18n_1.translator)(locale);
|
|
13
12
|
this.locale = locale.locale;
|
|
14
13
|
}
|
|
@@ -18,19 +17,31 @@ class MLRuleContext {
|
|
|
18
17
|
message: finish(report.message),
|
|
19
18
|
}));
|
|
20
19
|
}
|
|
21
|
-
report(report) {
|
|
22
|
-
tslib_1.__classPrivateFieldGet(this, _MLRuleContext_reports, "f").push(report);
|
|
23
|
-
}
|
|
24
20
|
provide() {
|
|
25
21
|
return {
|
|
26
22
|
document: this.document,
|
|
27
23
|
translate: this.translate,
|
|
28
24
|
t: this.translate,
|
|
29
|
-
globalRule: this.globalRule,
|
|
30
25
|
reports: this.reports,
|
|
31
26
|
report: this.report.bind(this),
|
|
32
27
|
};
|
|
33
28
|
}
|
|
29
|
+
report(report) {
|
|
30
|
+
if (typeof report === 'function') {
|
|
31
|
+
const r = report(this.translate);
|
|
32
|
+
if (r) {
|
|
33
|
+
this._push(r);
|
|
34
|
+
return true;
|
|
35
|
+
}
|
|
36
|
+
return false;
|
|
37
|
+
}
|
|
38
|
+
this._push(report);
|
|
39
|
+
}
|
|
40
|
+
_push(report) {
|
|
41
|
+
if (!tslib_1.__classPrivateFieldGet(this, _MLRuleContext_reports, "f").find(r => is(r, report))) {
|
|
42
|
+
tslib_1.__classPrivateFieldGet(this, _MLRuleContext_reports, "f").push(report);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
34
45
|
}
|
|
35
46
|
exports.MLRuleContext = MLRuleContext;
|
|
36
47
|
_MLRuleContext_reports = new WeakMap();
|
|
@@ -42,3 +53,15 @@ function finish(message, locale = 'en') {
|
|
|
42
53
|
}
|
|
43
54
|
return message;
|
|
44
55
|
}
|
|
56
|
+
function is(r1, r2) {
|
|
57
|
+
if ('col' in r1 && 'col' in r2) {
|
|
58
|
+
return r1.col === r2.col && r1.line === r2.line && r1.message === r2.message && r1.raw === r2.raw;
|
|
59
|
+
}
|
|
60
|
+
if ('scope' in r1) {
|
|
61
|
+
if (!('scope' in r2)) {
|
|
62
|
+
return false;
|
|
63
|
+
}
|
|
64
|
+
return r1.scope === r2.scope && r1.message === r2.message;
|
|
65
|
+
}
|
|
66
|
+
return false;
|
|
67
|
+
}
|
package/lib/ml-rule/ml-rule.d.ts
CHANGED
|
@@ -1,30 +1,30 @@
|
|
|
1
1
|
import type { Ruleset } from '..';
|
|
2
|
-
import type
|
|
2
|
+
import type { MLDocument } from '../ml-dom/node/document';
|
|
3
3
|
import type { RuleSeed } from './types';
|
|
4
4
|
import type { LocaleSet } from '@markuplint/i18n';
|
|
5
|
-
import type { GlobalRuleInfo, RuleConfig, RuleConfigValue, RuleInfo,
|
|
5
|
+
import type { GlobalRuleInfo, RuleConfig, RuleConfigValue, RuleInfo, Severity, Violation } from '@markuplint/ml-config';
|
|
6
6
|
export declare class MLRule<T extends RuleConfigValue, O = null> {
|
|
7
7
|
#private;
|
|
8
|
-
readonly name: string;
|
|
9
|
-
readonly defaultServerity: Severity;
|
|
10
|
-
readonly defaultValue: T;
|
|
11
8
|
readonly defaultOptions: O;
|
|
9
|
+
readonly defaultSeverity: Severity;
|
|
10
|
+
readonly defaultValue: T;
|
|
11
|
+
readonly name: string;
|
|
12
|
+
constructor(o: RuleSeed<T, O> & {
|
|
13
|
+
name: string;
|
|
14
|
+
});
|
|
12
15
|
/**
|
|
13
16
|
* The following getter is unused internally,
|
|
14
17
|
* only for extending from 3rd party library
|
|
15
18
|
*/
|
|
16
|
-
protected get
|
|
19
|
+
protected get f(): RuleSeed<T, O>['fix'];
|
|
17
20
|
/**
|
|
18
21
|
* The following getter is unused internally,
|
|
19
22
|
* only for extending from 3rd party library
|
|
20
23
|
*/
|
|
21
|
-
protected get
|
|
22
|
-
constructor(o: RuleSeed<T, O> & {
|
|
23
|
-
name: string;
|
|
24
|
-
});
|
|
25
|
-
verify(document: Document<T, O>, locale: LocaleSet, globalRule: RuleInfo<T, O>, fix: boolean): Promise<Violation[]>;
|
|
24
|
+
protected get v(): RuleSeed<T, O>['verify'];
|
|
26
25
|
getRuleInfo(ruleSet: Ruleset, ruleName: string): GlobalRuleInfo<T, O>;
|
|
27
|
-
_optimize(rules: Rules | undefined, ruleName: string): RuleInfo<T, O>;
|
|
28
26
|
optimizeOption(configSettings: T | RuleConfig<T, O> | undefined): RuleInfo<T, O>;
|
|
27
|
+
verify(document: MLDocument<T, O>, locale: LocaleSet, fix: boolean): Promise<Violation[]>;
|
|
28
|
+
private _optimize;
|
|
29
29
|
}
|
|
30
30
|
export declare type AnyMLRule = MLRule<RuleConfigValue, unknown>;
|
package/lib/ml-rule/ml-rule.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var
|
|
2
|
+
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");
|
|
@@ -7,10 +7,10 @@ const ml_rule_context_1 = require("./ml-rule-context");
|
|
|
7
7
|
class MLRule {
|
|
8
8
|
constructor(o) {
|
|
9
9
|
var _a, _b;
|
|
10
|
-
_MLRule_v.set(this, void 0);
|
|
11
10
|
_MLRule_f.set(this, void 0);
|
|
11
|
+
_MLRule_v.set(this, void 0);
|
|
12
12
|
this.name = o.name;
|
|
13
|
-
this.
|
|
13
|
+
this.defaultSeverity = o.defaultSeverity || 'error';
|
|
14
14
|
this.defaultValue = (_a = o.defaultValue) !== null && _a !== void 0 ? _a : true;
|
|
15
15
|
this.defaultOptions = (_b = o.defaultOptions) !== null && _b !== void 0 ? _b : null;
|
|
16
16
|
tslib_1.__classPrivateFieldSet(this, _MLRule_v, o.verify, "f");
|
|
@@ -20,22 +20,69 @@ class MLRule {
|
|
|
20
20
|
* The following getter is unused internally,
|
|
21
21
|
* only for extending from 3rd party library
|
|
22
22
|
*/
|
|
23
|
-
get
|
|
24
|
-
return tslib_1.__classPrivateFieldGet(this,
|
|
23
|
+
get f() {
|
|
24
|
+
return tslib_1.__classPrivateFieldGet(this, _MLRule_f, "f");
|
|
25
25
|
}
|
|
26
26
|
/**
|
|
27
27
|
* The following getter is unused internally,
|
|
28
28
|
* only for extending from 3rd party library
|
|
29
29
|
*/
|
|
30
|
-
get
|
|
31
|
-
return tslib_1.__classPrivateFieldGet(this,
|
|
30
|
+
get v() {
|
|
31
|
+
return tslib_1.__classPrivateFieldGet(this, _MLRule_v, "f");
|
|
32
|
+
}
|
|
33
|
+
getRuleInfo(ruleSet, ruleName) {
|
|
34
|
+
const info = this._optimize(ruleSet.rules, ruleName);
|
|
35
|
+
return {
|
|
36
|
+
...info,
|
|
37
|
+
nodeRules: ruleSet.nodeRules.map(r => this._optimize(r.rules, ruleName)).filter(r => !r.disabled),
|
|
38
|
+
childNodeRules: ruleSet.childNodeRules.map(r => this._optimize(r.rules, ruleName)).filter(r => !r.disabled),
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
optimizeOption(configSettings) {
|
|
42
|
+
if (configSettings === undefined || typeof configSettings === 'boolean') {
|
|
43
|
+
return {
|
|
44
|
+
disabled: !configSettings,
|
|
45
|
+
severity: this.defaultSeverity,
|
|
46
|
+
value: this.defaultValue,
|
|
47
|
+
option: this.defaultOptions,
|
|
48
|
+
reason: undefined,
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
if (!Array.isArray(configSettings) && typeof configSettings === 'object' && configSettings !== null) {
|
|
52
|
+
return {
|
|
53
|
+
disabled: false,
|
|
54
|
+
severity: configSettings.severity || this.defaultSeverity,
|
|
55
|
+
value: configSettings.value !== undefined ? configSettings.value : this.defaultValue,
|
|
56
|
+
option: Array.isArray(this.defaultOptions)
|
|
57
|
+
? configSettings.option
|
|
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.option == null || typeof configSettings.option === 'object')
|
|
66
|
+
? { ...this.defaultOptions, ...(configSettings.option || {}) }
|
|
67
|
+
: configSettings.option || this.defaultOptions,
|
|
68
|
+
reason: configSettings.reason,
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
return {
|
|
72
|
+
disabled: false,
|
|
73
|
+
severity: this.defaultSeverity,
|
|
74
|
+
// @ts-ignore TODO: Wait for fix to bug of type guards in TypeScript
|
|
75
|
+
value: configSettings == null ? this.defaultValue : configSettings,
|
|
76
|
+
option: this.defaultOptions,
|
|
77
|
+
reason: undefined,
|
|
78
|
+
};
|
|
32
79
|
}
|
|
33
|
-
async verify(document, locale,
|
|
80
|
+
async verify(document, locale, fix) {
|
|
34
81
|
if (!tslib_1.__classPrivateFieldGet(this, _MLRule_v, "f")) {
|
|
35
82
|
return [];
|
|
36
83
|
}
|
|
37
84
|
document.setRule(this);
|
|
38
|
-
const context = new ml_rule_context_1.MLRuleContext(document, locale
|
|
85
|
+
const context = new ml_rule_context_1.MLRuleContext(document, locale);
|
|
39
86
|
const providableContext = context.provide();
|
|
40
87
|
await tslib_1.__classPrivateFieldGet(this, _MLRule_v, "f").call(this, providableContext);
|
|
41
88
|
if (tslib_1.__classPrivateFieldGet(this, _MLRule_f, "f") && fix) {
|
|
@@ -46,7 +93,7 @@ class MLRule {
|
|
|
46
93
|
let line = report.scope.startLine;
|
|
47
94
|
let col = report.scope.startCol;
|
|
48
95
|
let raw = report.scope.raw;
|
|
49
|
-
if ('line' in report) {
|
|
96
|
+
if ('line' in report && report.line != null) {
|
|
50
97
|
line = report.line;
|
|
51
98
|
col = report.col;
|
|
52
99
|
raw = report.raw;
|
|
@@ -59,79 +106,32 @@ class MLRule {
|
|
|
59
106
|
raw,
|
|
60
107
|
ruleId: this.name,
|
|
61
108
|
};
|
|
62
|
-
if (report.scope.rule.reason ||
|
|
63
|
-
violation.reason = report.scope.rule.reason ||
|
|
109
|
+
if (report.scope.rule.reason || document.rule.reason) {
|
|
110
|
+
violation.reason = report.scope.rule.reason || document.rule.reason;
|
|
64
111
|
}
|
|
65
112
|
return violation;
|
|
66
113
|
}
|
|
67
114
|
const violation = {
|
|
68
|
-
severity:
|
|
115
|
+
severity: document.rule.severity,
|
|
69
116
|
message: report.message,
|
|
70
117
|
line: report.line,
|
|
71
118
|
col: report.col,
|
|
72
119
|
raw: report.raw,
|
|
73
120
|
ruleId: this.name,
|
|
74
121
|
};
|
|
75
|
-
if (
|
|
76
|
-
violation.reason =
|
|
122
|
+
if (document.rule.reason) {
|
|
123
|
+
violation.reason = document.rule.reason;
|
|
77
124
|
}
|
|
78
125
|
return violation;
|
|
79
126
|
});
|
|
80
127
|
document.setRule(null);
|
|
81
128
|
return violation;
|
|
82
129
|
}
|
|
83
|
-
getRuleInfo(ruleSet, ruleName) {
|
|
84
|
-
const info = this._optimize(ruleSet.rules, ruleName);
|
|
85
|
-
return {
|
|
86
|
-
...info,
|
|
87
|
-
nodeRules: ruleSet.nodeRules.map(r => this._optimize(r.rules, ruleName)).filter(r => !r.disabled),
|
|
88
|
-
childNodeRules: ruleSet.childNodeRules.map(r => this._optimize(r.rules, ruleName)).filter(r => !r.disabled),
|
|
89
|
-
};
|
|
90
|
-
}
|
|
91
130
|
_optimize(rules, ruleName) {
|
|
92
131
|
const rule = (rules && rules[ruleName]) || false;
|
|
93
132
|
const info = this.optimizeOption(rule);
|
|
94
133
|
return info;
|
|
95
134
|
}
|
|
96
|
-
optimizeOption(configSettings) {
|
|
97
|
-
if (configSettings === undefined || typeof configSettings === 'boolean') {
|
|
98
|
-
return {
|
|
99
|
-
disabled: !configSettings,
|
|
100
|
-
severity: this.defaultServerity,
|
|
101
|
-
value: this.defaultValue,
|
|
102
|
-
option: this.defaultOptions,
|
|
103
|
-
reason: undefined,
|
|
104
|
-
};
|
|
105
|
-
}
|
|
106
|
-
if (!Array.isArray(configSettings) && typeof configSettings === 'object' && configSettings !== null) {
|
|
107
|
-
return {
|
|
108
|
-
disabled: false,
|
|
109
|
-
severity: configSettings.severity || this.defaultServerity,
|
|
110
|
-
value: configSettings.value !== undefined ? configSettings.value : this.defaultValue,
|
|
111
|
-
option: Array.isArray(this.defaultOptions)
|
|
112
|
-
? configSettings.option
|
|
113
|
-
? // prettier-ignore
|
|
114
|
-
// @ts-ignore for "as" casting
|
|
115
|
-
this.defaultOptions.concat(configSettings.option)
|
|
116
|
-
: this.defaultOptions
|
|
117
|
-
: this.defaultOptions !== null &&
|
|
118
|
-
typeof this.defaultOptions === 'object' &&
|
|
119
|
-
// for example `configSettings.option === true`
|
|
120
|
-
(configSettings.option == null || typeof configSettings.option === 'object')
|
|
121
|
-
? { ...this.defaultOptions, ...(configSettings.option || {}) }
|
|
122
|
-
: configSettings.option || this.defaultOptions,
|
|
123
|
-
reason: configSettings.reason,
|
|
124
|
-
};
|
|
125
|
-
}
|
|
126
|
-
return {
|
|
127
|
-
disabled: false,
|
|
128
|
-
severity: this.defaultServerity,
|
|
129
|
-
// @ts-ignore TODO: Wait for fix to bug of type guards in TypeScript
|
|
130
|
-
value: configSettings == null ? this.defaultValue : configSettings,
|
|
131
|
-
option: this.defaultOptions,
|
|
132
|
-
reason: undefined,
|
|
133
|
-
};
|
|
134
|
-
}
|
|
135
135
|
}
|
|
136
136
|
exports.MLRule = MLRule;
|
|
137
|
-
|
|
137
|
+
_MLRule_f = new WeakMap(), _MLRule_v = new WeakMap();
|
package/lib/ml-rule/types.d.ts
CHANGED
|
@@ -1,10 +1,20 @@
|
|
|
1
|
+
import type { Attr, Element } from '../ml-dom';
|
|
1
2
|
import type { MLRuleContext } from './ml-rule-context';
|
|
2
|
-
import type {
|
|
3
|
+
import type { Translator } from '@markuplint/i18n';
|
|
4
|
+
import type { Report, RuleConfigValue, Severity } from '@markuplint/ml-config';
|
|
3
5
|
export declare type RuleSeed<T extends RuleConfigValue = boolean, O = null> = {
|
|
4
|
-
|
|
6
|
+
defaultSeverity?: Severity;
|
|
5
7
|
defaultValue?: T;
|
|
6
8
|
defaultOptions?: O;
|
|
7
9
|
verify(context: ReturnType<MLRuleContext<T, O>['provide']>): void | Promise<void>;
|
|
8
10
|
fix?(context: ReturnType<MLRuleContext<T, O>['provide']>): void | Promise<void>;
|
|
9
11
|
};
|
|
12
|
+
export declare type Checker<T extends RuleConfigValue, O = null, P extends Record<string, unknown> = {}> = (params: P) => CheckerReport<T, O>;
|
|
13
|
+
export declare type ElementChecker<T extends RuleConfigValue, O = null, P extends Record<string, unknown> = {}> = (params: P & {
|
|
14
|
+
el: Element<T, O>;
|
|
15
|
+
}) => CheckerReport<T, O>;
|
|
16
|
+
export declare type AttrChecker<T extends RuleConfigValue, O = null, P extends Record<string, unknown> = {}> = (params: P & {
|
|
17
|
+
attr: Attr<T, O>;
|
|
18
|
+
}) => CheckerReport<T, O>;
|
|
19
|
+
export declare type CheckerReport<T extends RuleConfigValue, O = null> = (t: Translator) => Report<T, O> | undefined | null;
|
|
10
20
|
export declare type AnyRuleSeed = RuleSeed<any, any>;
|
package/lib/ruleset/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { ChildNodeRule, Config, NodeRule, Rules } from '@markuplint/ml-config';
|
|
2
2
|
export default class Ruleset {
|
|
3
|
-
readonly rules: Readonly<Rules>;
|
|
4
|
-
readonly nodeRules: ReadonlyArray<NodeRule>;
|
|
5
3
|
readonly childNodeRules: ReadonlyArray<ChildNodeRule>;
|
|
4
|
+
readonly nodeRules: ReadonlyArray<NodeRule>;
|
|
5
|
+
readonly rules: Readonly<Rules>;
|
|
6
6
|
constructor(config: Config);
|
|
7
7
|
}
|
package/lib/test/index.d.ts
CHANGED
|
@@ -5,9 +5,11 @@ import { Document } from '../ml-dom';
|
|
|
5
5
|
export declare type CreateTestOptions = {
|
|
6
6
|
config?: Config;
|
|
7
7
|
parser?: MLMarkupLanguageParser;
|
|
8
|
+
specs?: MLMLSpec;
|
|
8
9
|
};
|
|
9
10
|
export declare function createTestDocument<T extends RuleConfigValue = any, O = any>(sourceCode: string, options?: CreateTestOptions): Document<T, O>;
|
|
10
|
-
export declare function createTestNodeList(sourceCode: string, options?: CreateTestOptions): readonly import("../ml-dom").
|
|
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>[];
|
|
11
13
|
export declare function createTestElement(sourceCode: string, options?: CreateTestOptions): import("../ml-dom").Element<any, any>;
|
|
12
14
|
/**
|
|
13
15
|
* for test suite
|
package/lib/test/index.js
CHANGED
|
@@ -1,13 +1,16 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.dummySchemas = exports.createTestElement = exports.createTestNodeList = exports.createTestDocument = void 0;
|
|
3
|
+
exports.dummySchemas = exports.createTestElement = exports.createTestTokenList = exports.createTestNodeList = exports.createTestDocument = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
4
5
|
const html_parser_1 = require("@markuplint/html-parser");
|
|
6
|
+
const html_spec_1 = tslib_1.__importDefault(require("@markuplint/html-spec"));
|
|
5
7
|
const convert_ruleset_1 = require("../convert-ruleset");
|
|
6
8
|
const ml_dom_1 = require("../ml-dom");
|
|
7
9
|
function createTestDocument(sourceCode, options) {
|
|
10
|
+
var _a;
|
|
8
11
|
const ast = (options === null || options === void 0 ? void 0 : options.parser) ? options.parser.parse(sourceCode) : (0, html_parser_1.parse)(sourceCode);
|
|
9
12
|
const ruleset = (0, convert_ruleset_1.convertRuleset)(options === null || options === void 0 ? void 0 : options.config);
|
|
10
|
-
const document = new ml_dom_1.Document(ast, ruleset, [{}, {}]);
|
|
13
|
+
const document = new ml_dom_1.Document(ast, ruleset, [(_a = options === null || options === void 0 ? void 0 : options.specs) !== null && _a !== void 0 ? _a : {}, {}]);
|
|
11
14
|
return document;
|
|
12
15
|
}
|
|
13
16
|
exports.createTestDocument = createTestDocument;
|
|
@@ -16,10 +19,15 @@ function createTestNodeList(sourceCode, options) {
|
|
|
16
19
|
return document.nodeList;
|
|
17
20
|
}
|
|
18
21
|
exports.createTestNodeList = createTestNodeList;
|
|
22
|
+
function createTestTokenList(sourceCode, options) {
|
|
23
|
+
const document = createTestDocument(sourceCode, options);
|
|
24
|
+
return document.getTokenList();
|
|
25
|
+
}
|
|
26
|
+
exports.createTestTokenList = createTestTokenList;
|
|
19
27
|
function createTestElement(sourceCode, options) {
|
|
20
28
|
const document = createTestDocument(sourceCode, options);
|
|
21
29
|
const el = document.nodeList[0];
|
|
22
|
-
if (el.
|
|
30
|
+
if (el.is(el.ELEMENT_NODE)) {
|
|
23
31
|
return el;
|
|
24
32
|
}
|
|
25
33
|
throw TypeError(`Could not parse it to be an element from: ${sourceCode}`);
|
|
@@ -29,7 +37,6 @@ exports.createTestElement = createTestElement;
|
|
|
29
37
|
* for test suite
|
|
30
38
|
*/
|
|
31
39
|
function dummySchemas() {
|
|
32
|
-
|
|
33
|
-
return [{}, {}];
|
|
40
|
+
return [html_spec_1.default];
|
|
34
41
|
}
|
|
35
42
|
exports.dummySchemas = dummySchemas;
|
package/lib/types.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import type { AnyMLRule } from './ml-rule';
|
|
2
2
|
import type Ruleset from './ruleset';
|
|
3
3
|
import type { LocaleSet } from '@markuplint/i18n';
|
|
4
|
-
import type { MLMarkupLanguageParser } from '@markuplint/ml-ast';
|
|
5
|
-
import type {
|
|
4
|
+
import type { MLMarkupLanguageParser, ParserOptions } from '@markuplint/ml-ast';
|
|
5
|
+
import type { Pretender } from '@markuplint/ml-config';
|
|
6
6
|
import type { ExtendedSpec, MLMLSpec } from '@markuplint/ml-spec';
|
|
7
7
|
export declare type MLSchema = Readonly<[MLMLSpec, ...ExtendedSpec[]]>;
|
|
8
8
|
export declare type MLFabric = {
|
|
@@ -12,4 +12,5 @@ export declare type MLFabric = {
|
|
|
12
12
|
locale: LocaleSet;
|
|
13
13
|
schemas: MLSchema;
|
|
14
14
|
parserOptions: ParserOptions;
|
|
15
|
+
pretenders: Pretender[];
|
|
15
16
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@markuplint/ml-core",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "3.0.0-alpha.1",
|
|
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>",
|
|
@@ -17,19 +17,20 @@
|
|
|
17
17
|
"clean": "tsc --build --clean"
|
|
18
18
|
},
|
|
19
19
|
"dependencies": {
|
|
20
|
-
"@markuplint/
|
|
21
|
-
"@markuplint/
|
|
22
|
-
"@markuplint/ml-
|
|
23
|
-
"@markuplint/ml-
|
|
24
|
-
"@markuplint/
|
|
20
|
+
"@markuplint/config-presets": "3.0.0-alpha.1",
|
|
21
|
+
"@markuplint/i18n": "3.0.0-alpha.1",
|
|
22
|
+
"@markuplint/ml-ast": "3.0.0-alpha.1",
|
|
23
|
+
"@markuplint/ml-config": "3.0.0-alpha.1",
|
|
24
|
+
"@markuplint/ml-spec": "3.0.0-alpha.1",
|
|
25
|
+
"@markuplint/parser-utils": "3.0.0-alpha.1",
|
|
26
|
+
"@markuplint/selector": "3.0.0-alpha.1",
|
|
25
27
|
"debug": "^4.3.4",
|
|
26
|
-
"dom-accessibility-api": "^0.5.13",
|
|
27
28
|
"postcss-selector-parser": "^6.0.10",
|
|
28
|
-
"tslib": "^2.
|
|
29
|
+
"tslib": "^2.4.0"
|
|
29
30
|
},
|
|
30
31
|
"devDependencies": {
|
|
31
|
-
"@markuplint/html-parser": "
|
|
32
|
+
"@markuplint/html-parser": "3.0.0-alpha.1",
|
|
32
33
|
"@types/debug": "^4.1.7"
|
|
33
34
|
},
|
|
34
|
-
"gitHead": "
|
|
35
|
+
"gitHead": "56de89456146a06777eb5b6d4e8ba456147dd18b"
|
|
35
36
|
}
|