@markuplint/ml-core 3.9.0 → 3.11.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.
- package/lib/index.d.ts +1 -11
- package/lib/ml-core.d.ts +11 -22
- package/lib/ml-dom/helper/create-node.d.ts +1 -5
- package/lib/ml-dom/helper/getIndent.d.ts +7 -7
- package/lib/ml-dom/helper/walkers.d.ts +4 -14
- package/lib/ml-dom/manipulations/child-node-methods.d.ts +5 -18
- package/lib/ml-dom/manipulations/get-children.d.ts +1 -3
- package/lib/ml-dom/node/attr.d.ts +90 -93
- package/lib/ml-dom/node/block.d.ts +31 -35
- package/lib/ml-dom/node/character-data.d.ts +52 -59
- package/lib/ml-dom/node/child-node.d.ts +2 -9
- package/lib/ml-dom/node/comment.d.ts +12 -15
- package/lib/ml-dom/node/document-fragment.d.ts +19 -22
- package/lib/ml-dom/node/document-type.d.ts +31 -34
- package/lib/ml-dom/node/document.d.ts +1583 -1600
- package/lib/ml-dom/node/document.js +12 -1
- package/lib/ml-dom/node/dom-token-list.d.ts +26 -26
- package/lib/ml-dom/node/element.d.ts +1904 -1902
- package/lib/ml-dom/node/element.js +17 -1
- package/lib/ml-dom/node/named-node-map.d.ts +39 -44
- package/lib/ml-dom/node/node-list.d.ts +3 -9
- package/lib/ml-dom/node/node-store.d.ts +3 -8
- package/lib/ml-dom/node/node-store.js +1 -1
- package/lib/ml-dom/node/node.d.ts +471 -491
- package/lib/ml-dom/node/parent-node.d.ts +57 -66
- package/lib/ml-dom/node/rule-mapper.d.ts +7 -7
- package/lib/ml-dom/node/text.d.ts +46 -49
- package/lib/ml-dom/node/types.d.ts +12 -80
- package/lib/ml-dom/node/unexpected-call-error.d.ts +2 -1
- package/lib/ml-dom/token/token.d.ts +44 -44
- package/lib/ml-rule/create-rule.d.ts +1 -3
- package/lib/ml-rule/create-test-rule.d.ts +3 -5
- package/lib/ml-rule/ml-rule-context.d.ts +47 -55
- package/lib/ml-rule/ml-rule.d.ts +23 -33
- package/lib/ml-rule/ml-rule.js +5 -1
- package/lib/ml-rule/types.d.ts +13 -31
- package/lib/plugin/plugin.d.ts +1 -3
- package/lib/plugin/types.d.ts +5 -5
- package/lib/ruleset/index.d.ts +4 -4
- package/lib/test/index.d.ts +7 -19
- package/lib/types.d.ts +8 -8
- package/lib/utils/get-location-from-chars.d.ts +4 -9
- package/package.json +14 -14
- package/test/ml-dom/ml-rule/create-rule.spec.js +108 -0
package/lib/ml-rule/ml-rule.js
CHANGED
|
@@ -56,7 +56,11 @@ class MLRule {
|
|
|
56
56
|
return {
|
|
57
57
|
disabled: false,
|
|
58
58
|
severity: (_a = configSettings.severity) !== null && _a !== void 0 ? _a : this.defaultSeverity,
|
|
59
|
-
value: configSettings.value
|
|
59
|
+
value: configSettings.value === undefined ||
|
|
60
|
+
// @ts-ignore
|
|
61
|
+
configSettings.value === true
|
|
62
|
+
? this.defaultValue
|
|
63
|
+
: configSettings.value,
|
|
60
64
|
options: mergeOptions(this.defaultOptions, configSettings.options),
|
|
61
65
|
reason: configSettings.reason,
|
|
62
66
|
};
|
package/lib/ml-rule/types.d.ts
CHANGED
|
@@ -3,36 +3,18 @@ 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
|
-
> = (params: P
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
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;
|
|
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;
|
|
38
20
|
export type AnyRuleSeed<T extends RuleConfigValue = RuleConfigValue, O extends PlainData = PlainData> = RuleSeed<T, O>;
|
package/lib/plugin/plugin.d.ts
CHANGED
|
@@ -1,4 +1,2 @@
|
|
|
1
1
|
import type { PluginCreator, CreatePluginSettings } from './types';
|
|
2
|
-
export declare function createPlugin<S extends CreatePluginSettings>(
|
|
3
|
-
fn: Readonly<PluginCreator<S>>,
|
|
4
|
-
): Readonly<PluginCreator<S>>;
|
|
2
|
+
export declare function createPlugin<S extends CreatePluginSettings>(fn: Readonly<PluginCreator<S>>): 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,26 +3,14 @@ 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
|
-
):
|
|
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/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,12 +1,7 @@
|
|
|
1
1
|
interface Location {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
2
|
+
line: number;
|
|
3
|
+
col: number;
|
|
4
|
+
raw: string;
|
|
5
5
|
}
|
|
6
|
-
export declare function getLocationFromChars(
|
|
7
|
-
searches: readonly 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
|
+
"version": "3.11.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,20 +23,20 @@
|
|
|
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.
|
|
30
|
-
"@markuplint/ml-ast": "3.
|
|
31
|
-
"@markuplint/ml-config": "3.
|
|
32
|
-
"@markuplint/ml-spec": "3.
|
|
33
|
-
"@markuplint/parser-utils": "3.
|
|
34
|
-
"@markuplint/selector": "3.
|
|
35
|
-
"@types/debug": "^4.1.
|
|
26
|
+
"@markuplint/config-presets": "3.7.0",
|
|
27
|
+
"@markuplint/html-parser": "3.9.0",
|
|
28
|
+
"@markuplint/html-spec": "3.10.0",
|
|
29
|
+
"@markuplint/i18n": "3.9.0",
|
|
30
|
+
"@markuplint/ml-ast": "3.2.0",
|
|
31
|
+
"@markuplint/ml-config": "3.10.0",
|
|
32
|
+
"@markuplint/ml-spec": "3.10.0",
|
|
33
|
+
"@markuplint/parser-utils": "3.9.0",
|
|
34
|
+
"@markuplint/selector": "3.10.0",
|
|
35
|
+
"@types/debug": "^4.1.8",
|
|
36
36
|
"debug": "^4.3.4",
|
|
37
37
|
"is-plain-object": "^5.0.0",
|
|
38
|
-
"tslib": "^2.
|
|
39
|
-
"type-fest": "^3.
|
|
38
|
+
"tslib": "^2.5.3",
|
|
39
|
+
"type-fest": "^3.11.1"
|
|
40
40
|
},
|
|
41
|
-
"gitHead": "
|
|
41
|
+
"gitHead": "9547b8dca20736a93e4d01af2d61bee314ba5718"
|
|
42
42
|
}
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
const { createRule } = require('../../../lib/ml-rule/create-test-rule');
|
|
2
|
+
const { createTestDocument } = require('../../../lib/test');
|
|
3
|
+
|
|
4
|
+
describe('createRule', () => {
|
|
5
|
+
test('defaultValue', () => {
|
|
6
|
+
const document = createTestDocument('<div></div>');
|
|
7
|
+
|
|
8
|
+
const rule = createRule({
|
|
9
|
+
name: 'test-rule',
|
|
10
|
+
defaultValue: [1, 2, 3],
|
|
11
|
+
verify({ document }) {
|
|
12
|
+
expect(document.rule.value).toStrictEqual([1, 2, 3]);
|
|
13
|
+
|
|
14
|
+
document.getElementsByTagName('div').forEach(el => {
|
|
15
|
+
expect(el.rule.value).toStrictEqual([1, 2, 3]);
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
return;
|
|
19
|
+
},
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
void rule.verify(document, { locale: 'en' });
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
test('Change value from config', () => {
|
|
26
|
+
const document = createTestDocument('<div></div>', {
|
|
27
|
+
config: {
|
|
28
|
+
rules: {
|
|
29
|
+
'test-rule': {
|
|
30
|
+
value: [4, 5, 6],
|
|
31
|
+
},
|
|
32
|
+
},
|
|
33
|
+
},
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
const rule = createRule({
|
|
37
|
+
name: 'test-rule',
|
|
38
|
+
defaultValue: [1, 2, 3],
|
|
39
|
+
verify({ document }) {
|
|
40
|
+
expect(document.rule.value).toStrictEqual([4, 5, 6]);
|
|
41
|
+
|
|
42
|
+
document.getElementsByTagName('div').forEach(el => {
|
|
43
|
+
expect(el.rule.value).toStrictEqual([4, 5, 6]);
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
return;
|
|
47
|
+
},
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
void rule.verify(document, { locale: 'en' });
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
test('Change value to true from config', () => {
|
|
54
|
+
const document = createTestDocument('<div></div>', {
|
|
55
|
+
config: {
|
|
56
|
+
rules: {
|
|
57
|
+
'test-rule': {
|
|
58
|
+
value: true,
|
|
59
|
+
},
|
|
60
|
+
},
|
|
61
|
+
},
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
const rule = createRule({
|
|
65
|
+
name: 'test-rule',
|
|
66
|
+
defaultValue: [1, 2, 3],
|
|
67
|
+
verify({ document }) {
|
|
68
|
+
expect(document.rule.value).toStrictEqual([1, 2, 3]);
|
|
69
|
+
|
|
70
|
+
document.getElementsByTagName('div').forEach(el => {
|
|
71
|
+
expect(el.rule.value).toStrictEqual([1, 2, 3]);
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
return;
|
|
75
|
+
},
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
void rule.verify(document, { locale: 'en' });
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
test('Change severity', () => {
|
|
82
|
+
const document = createTestDocument('<div></div>', {
|
|
83
|
+
config: {
|
|
84
|
+
rules: {
|
|
85
|
+
'test-rule': {
|
|
86
|
+
severity: 'warning',
|
|
87
|
+
},
|
|
88
|
+
},
|
|
89
|
+
},
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
const rule = createRule({
|
|
93
|
+
name: 'test-rule',
|
|
94
|
+
defaultValue: [],
|
|
95
|
+
verify({ document }) {
|
|
96
|
+
expect(document.rule.value).toStrictEqual([]);
|
|
97
|
+
|
|
98
|
+
document.getElementsByTagName('div').forEach(el => {
|
|
99
|
+
expect(el.rule.value).toStrictEqual([]);
|
|
100
|
+
});
|
|
101
|
+
|
|
102
|
+
return;
|
|
103
|
+
},
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
void rule.verify(document, { locale: 'en' });
|
|
107
|
+
});
|
|
108
|
+
});
|