@markuplint/ml-core 3.5.0 → 3.6.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/index.d.ts +11 -1
- package/lib/ml-dom/helper/accname.js +3 -2
- package/lib/ml-dom/helper/create-node.d.ts +5 -1
- package/lib/ml-dom/helper/debug.js +3 -2
- package/lib/ml-dom/helper/getIndent.d.ts +7 -7
- package/lib/ml-dom/helper/getIndent.js +7 -9
- package/lib/ml-dom/helper/walkers.d.ts +14 -4
- package/lib/ml-dom/helper/walkers.js +1 -1
- package/lib/ml-dom/manipulations/child-node-methods.d.ts +18 -5
- package/lib/ml-dom/manipulations/get-children.d.ts +3 -1
- package/lib/ml-dom/node/attr.d.ts +93 -90
- package/lib/ml-dom/node/attr.js +3 -3
- package/lib/ml-dom/node/block.d.ts +35 -31
- package/lib/ml-dom/node/character-data.d.ts +59 -52
- package/lib/ml-dom/node/child-node.d.ts +9 -2
- package/lib/ml-dom/node/comment.d.ts +15 -12
- package/lib/ml-dom/node/document-fragment.d.ts +22 -19
- package/lib/ml-dom/node/document-type.d.ts +34 -31
- package/lib/ml-dom/node/document.d.ts +1600 -1583
- package/lib/ml-dom/node/document.js +15 -12
- package/lib/ml-dom/node/dom-token-list.d.ts +26 -26
- package/lib/ml-dom/node/dom-token-list.js +1 -1
- package/lib/ml-dom/node/element.d.ts +1902 -1896
- package/lib/ml-dom/node/element.js +18 -13
- package/lib/ml-dom/node/named-node-map.d.ts +44 -39
- package/lib/ml-dom/node/named-node-map.js +2 -1
- package/lib/ml-dom/node/node-list.d.ts +9 -3
- package/lib/ml-dom/node/node-list.js +2 -1
- package/lib/ml-dom/node/node-store.d.ts +8 -3
- package/lib/ml-dom/node/node.d.ts +491 -471
- package/lib/ml-dom/node/node.js +6 -3
- package/lib/ml-dom/node/parent-node.d.ts +66 -57
- package/lib/ml-dom/node/parent-node.js +6 -3
- package/lib/ml-dom/node/rule-mapper.d.ts +7 -7
- package/lib/ml-dom/node/rule-mapper.js +2 -1
- package/lib/ml-dom/node/text.d.ts +49 -46
- package/lib/ml-dom/node/types.d.ts +80 -12
- package/lib/ml-dom/node/unexpected-call-error.d.ts +1 -2
- package/lib/ml-dom/token/token.d.ts +44 -44
- package/lib/ml-rule/create-rule.d.ts +3 -1
- package/lib/ml-rule/create-test-rule.d.ts +5 -3
- package/lib/ml-rule/ml-rule-context.d.ts +55 -47
- package/lib/ml-rule/ml-rule.d.ts +33 -23
- package/lib/ml-rule/ml-rule.js +4 -5
- package/lib/ml-rule/types.d.ts +31 -13
- package/lib/plugin/plugin.d.ts +3 -1
- package/lib/plugin/types.d.ts +5 -5
- package/lib/ruleset/index.d.ts +4 -4
- package/lib/test/index.d.ts +19 -7
- package/lib/types.d.ts +8 -8
- package/lib/utils/get-location-from-chars.d.ts +9 -4
- package/package.json +10 -11
|
@@ -3,51 +3,59 @@ import type { MLDocument } from '../ml-dom/node/document';
|
|
|
3
3
|
import type { LocaleSet, Translator } from '@markuplint/i18n';
|
|
4
4
|
import type { PlainData, Report, RuleConfigValue } from '@markuplint/ml-config';
|
|
5
5
|
export declare class MLRuleContext<T extends RuleConfigValue, O extends PlainData = undefined> {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
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;
|
|
53
61
|
}
|
package/lib/ml-rule/ml-rule.d.ts
CHANGED
|
@@ -2,29 +2,39 @@ 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 {
|
|
5
|
+
import type {
|
|
6
|
+
GlobalRuleInfo,
|
|
7
|
+
PlainData,
|
|
8
|
+
Rule,
|
|
9
|
+
RuleConfigValue,
|
|
10
|
+
RuleInfo,
|
|
11
|
+
Severity,
|
|
12
|
+
Violation,
|
|
13
|
+
} from '@markuplint/ml-config';
|
|
6
14
|
export declare class MLRule<T extends RuleConfigValue, O extends PlainData = undefined> {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
15
|
+
#private;
|
|
16
|
+
readonly defaultOptions: O;
|
|
17
|
+
readonly defaultSeverity: Severity;
|
|
18
|
+
readonly defaultValue: T;
|
|
19
|
+
readonly name: string;
|
|
20
|
+
constructor(
|
|
21
|
+
o: Readonly<RuleSeed<T, O>> & {
|
|
22
|
+
readonly name: string;
|
|
23
|
+
},
|
|
24
|
+
);
|
|
25
|
+
/**
|
|
26
|
+
* The following getter is unused internally,
|
|
27
|
+
* only for extending from 3rd party library
|
|
28
|
+
*/
|
|
29
|
+
protected get f(): RuleSeed<T, O>['fix'];
|
|
30
|
+
/**
|
|
31
|
+
* The following getter is unused internally,
|
|
32
|
+
* only for extending from 3rd party library
|
|
33
|
+
*/
|
|
34
|
+
protected get v(): RuleSeed<T, O>['verify'];
|
|
35
|
+
getRuleInfo(ruleSet: Ruleset, ruleName: string): GlobalRuleInfo<T, O>;
|
|
36
|
+
optimizeOption(configSettings: Rule<T, O> | null | undefined): RuleInfo<T, O>;
|
|
37
|
+
verify(document: MLDocument<T, O>, locale: LocaleSet, fix: boolean): Promise<Violation[]>;
|
|
38
|
+
private _optimize;
|
|
29
39
|
}
|
|
30
40
|
export type AnyMLRule = MLRule<RuleConfigValue, PlainData>;
|
package/lib/ml-rule/ml-rule.js
CHANGED
|
@@ -41,6 +41,7 @@ class MLRule {
|
|
|
41
41
|
};
|
|
42
42
|
}
|
|
43
43
|
optimizeOption(configSettings) {
|
|
44
|
+
var _a;
|
|
44
45
|
if (configSettings === undefined || typeof configSettings === 'boolean') {
|
|
45
46
|
return {
|
|
46
47
|
disabled: !configSettings,
|
|
@@ -53,7 +54,7 @@ class MLRule {
|
|
|
53
54
|
if (isRuleConfig(configSettings)) {
|
|
54
55
|
return {
|
|
55
56
|
disabled: false,
|
|
56
|
-
severity: configSettings.severity
|
|
57
|
+
severity: (_a = configSettings.severity) !== null && _a !== void 0 ? _a : this.defaultSeverity,
|
|
57
58
|
value: configSettings.value !== undefined ? configSettings.value : this.defaultValue,
|
|
58
59
|
options: mergeOptions(this.defaultOptions, configSettings.options),
|
|
59
60
|
reason: configSettings.reason,
|
|
@@ -70,9 +71,6 @@ class MLRule {
|
|
|
70
71
|
async verify(
|
|
71
72
|
// eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
|
|
72
73
|
document, locale, fix) {
|
|
73
|
-
if (!tslib_1.__classPrivateFieldGet(this, _MLRule_v, "f")) {
|
|
74
|
-
return [];
|
|
75
|
-
}
|
|
76
74
|
document.setRule(this);
|
|
77
75
|
const context = new ml_rule_context_1.MLRuleContext(document, locale);
|
|
78
76
|
const providableContext = context.provide();
|
|
@@ -81,6 +79,7 @@ class MLRule {
|
|
|
81
79
|
await tslib_1.__classPrivateFieldGet(this, _MLRule_f, "f").call(this, providableContext);
|
|
82
80
|
}
|
|
83
81
|
const violation = context.reports.map(report => {
|
|
82
|
+
var _a;
|
|
84
83
|
if ('scope' in report) {
|
|
85
84
|
let line = report.scope.startLine;
|
|
86
85
|
let col = report.scope.startCol;
|
|
@@ -97,7 +96,7 @@ class MLRule {
|
|
|
97
96
|
col,
|
|
98
97
|
raw,
|
|
99
98
|
ruleId: this.name,
|
|
100
|
-
reason: report.scope.rule.reason
|
|
99
|
+
reason: (_a = report.scope.rule.reason) !== null && _a !== void 0 ? _a : document.rule.reason,
|
|
101
100
|
};
|
|
102
101
|
(0, ml_config_1.deleteUndefProp)(violation);
|
|
103
102
|
return violation;
|
package/lib/ml-rule/types.d.ts
CHANGED
|
@@ -3,18 +3,36 @@ import type { Attr, Element } from '../ml-dom';
|
|
|
3
3
|
import type { Translator } from '@markuplint/i18n';
|
|
4
4
|
import type { PlainData, Report, RuleConfigValue, Severity } from '@markuplint/ml-config';
|
|
5
5
|
export type RuleSeed<T extends RuleConfigValue = boolean, O extends PlainData = undefined> = {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
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<
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
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
|
+
> = (
|
|
22
|
+
params: P & {
|
|
23
|
+
el: Element<T, O>;
|
|
24
|
+
},
|
|
25
|
+
) => CheckerReport<T, O>;
|
|
26
|
+
export type AttrChecker<
|
|
27
|
+
T extends RuleConfigValue,
|
|
28
|
+
O extends PlainData = undefined,
|
|
29
|
+
P extends Record<string, unknown> = {},
|
|
30
|
+
> = (
|
|
31
|
+
params: P & {
|
|
32
|
+
attr: Attr<T, O>;
|
|
33
|
+
},
|
|
34
|
+
) => CheckerReport<T, O>;
|
|
35
|
+
export type CheckerReport<T extends RuleConfigValue, O extends PlainData = undefined> = (
|
|
36
|
+
t: Translator,
|
|
37
|
+
) => Report<T, O> | undefined | null;
|
|
20
38
|
export type AnyRuleSeed<T extends RuleConfigValue = RuleConfigValue, O extends PlainData = PlainData> = RuleSeed<T, O>;
|
package/lib/plugin/plugin.d.ts
CHANGED
|
@@ -1,2 +1,4 @@
|
|
|
1
1
|
import type { PluginCreator, CreatePluginSettings } from './types';
|
|
2
|
-
export declare function createPlugin<S extends CreatePluginSettings>(
|
|
2
|
+
export declare function createPlugin<S extends CreatePluginSettings>(
|
|
3
|
+
fn: Readonly<PluginCreator<S>>,
|
|
4
|
+
): Readonly<PluginCreator<S>>;
|
package/lib/plugin/types.d.ts
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import type { RuleSeed } from '../ml-rule';
|
|
2
2
|
import type { Config } from '@markuplint/ml-config';
|
|
3
3
|
export type Plugin = {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
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
|
-
|
|
10
|
-
|
|
9
|
+
readonly name: string;
|
|
10
|
+
create(setting: S): Omit<Plugin, 'name'>;
|
|
11
11
|
};
|
|
12
12
|
export type CreatePluginSettings = Readonly<Record<string, unknown>>;
|
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
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
3
|
+
readonly childNodeRules: readonly ChildNodeRule[];
|
|
4
|
+
readonly nodeRules: readonly NodeRule[];
|
|
5
|
+
readonly rules: Rules;
|
|
6
|
+
constructor(config: Config);
|
|
7
7
|
}
|
package/lib/test/index.d.ts
CHANGED
|
@@ -3,14 +3,26 @@ 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
|
-
|
|
7
|
-
|
|
8
|
-
|
|
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 extends PlainData = any>(
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
10
|
+
export declare function createTestDocument<T extends RuleConfigValue = any, O extends PlainData = 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>;
|
|
14
26
|
/**
|
|
15
27
|
* for test suite
|
|
16
28
|
*/
|
package/lib/types.d.ts
CHANGED
|
@@ -6,12 +6,12 @@ import type { Pretender } from '@markuplint/ml-config';
|
|
|
6
6
|
import type { ExtendedSpec, MLMLSpec } from '@markuplint/ml-spec';
|
|
7
7
|
export type MLSchema = readonly [MLMLSpec, ...ExtendedSpec[]];
|
|
8
8
|
export type MLFabric = {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
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>[];
|
|
17
17
|
};
|
|
@@ -1,7 +1,12 @@
|
|
|
1
1
|
interface Location {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
2
|
+
line: number;
|
|
3
|
+
col: number;
|
|
4
|
+
raw: string;
|
|
5
5
|
}
|
|
6
|
-
export declare function getLocationFromChars(
|
|
6
|
+
export declare function getLocationFromChars(
|
|
7
|
+
searches: readonly string[],
|
|
8
|
+
text: string,
|
|
9
|
+
currentLine: number,
|
|
10
|
+
currentCol: number,
|
|
11
|
+
): Location[];
|
|
7
12
|
export {};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@markuplint/ml-core",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.6.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>",
|
|
@@ -23,23 +23,22 @@
|
|
|
23
23
|
"./lib/configs.js": "./lib/configs.browser.js"
|
|
24
24
|
},
|
|
25
25
|
"dependencies": {
|
|
26
|
-
"@markuplint/config-presets": "3.
|
|
27
|
-
"@markuplint/html-parser": "3.
|
|
28
|
-
"@markuplint/html-spec": "3.
|
|
29
|
-
"@markuplint/i18n": "3.
|
|
26
|
+
"@markuplint/config-presets": "3.5.0",
|
|
27
|
+
"@markuplint/html-parser": "3.6.1",
|
|
28
|
+
"@markuplint/html-spec": "3.6.1",
|
|
29
|
+
"@markuplint/i18n": "3.6.0",
|
|
30
30
|
"@markuplint/ml-ast": "3.1.0",
|
|
31
|
-
"@markuplint/ml-config": "3.
|
|
32
|
-
"@markuplint/ml-spec": "3.
|
|
33
|
-
"@markuplint/parser-utils": "3.
|
|
34
|
-
"@markuplint/selector": "3.
|
|
31
|
+
"@markuplint/ml-config": "3.6.1",
|
|
32
|
+
"@markuplint/ml-spec": "3.6.1",
|
|
33
|
+
"@markuplint/parser-utils": "3.6.1",
|
|
34
|
+
"@markuplint/selector": "3.6.1",
|
|
35
35
|
"debug": "^4.3.4",
|
|
36
36
|
"is-plain-object": "^5.0.0",
|
|
37
37
|
"tslib": "^2.4.1"
|
|
38
38
|
},
|
|
39
39
|
"devDependencies": {
|
|
40
|
-
"@markuplint/html-parser": "3.3.0",
|
|
41
40
|
"@types/debug": "^4.1.7",
|
|
42
41
|
"type-fest": "^3.6.1"
|
|
43
42
|
},
|
|
44
|
-
"gitHead": "
|
|
43
|
+
"gitHead": "3cdf5a088b2da03773d5d4461d0e65ec32290a00"
|
|
45
44
|
}
|