@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.
Files changed (52) hide show
  1. package/lib/index.d.ts +11 -1
  2. package/lib/ml-dom/helper/accname.js +3 -2
  3. package/lib/ml-dom/helper/create-node.d.ts +5 -1
  4. package/lib/ml-dom/helper/debug.js +3 -2
  5. package/lib/ml-dom/helper/getIndent.d.ts +7 -7
  6. package/lib/ml-dom/helper/getIndent.js +7 -9
  7. package/lib/ml-dom/helper/walkers.d.ts +14 -4
  8. package/lib/ml-dom/helper/walkers.js +1 -1
  9. package/lib/ml-dom/manipulations/child-node-methods.d.ts +18 -5
  10. package/lib/ml-dom/manipulations/get-children.d.ts +3 -1
  11. package/lib/ml-dom/node/attr.d.ts +93 -90
  12. package/lib/ml-dom/node/attr.js +3 -3
  13. package/lib/ml-dom/node/block.d.ts +35 -31
  14. package/lib/ml-dom/node/character-data.d.ts +59 -52
  15. package/lib/ml-dom/node/child-node.d.ts +9 -2
  16. package/lib/ml-dom/node/comment.d.ts +15 -12
  17. package/lib/ml-dom/node/document-fragment.d.ts +22 -19
  18. package/lib/ml-dom/node/document-type.d.ts +34 -31
  19. package/lib/ml-dom/node/document.d.ts +1600 -1583
  20. package/lib/ml-dom/node/document.js +15 -12
  21. package/lib/ml-dom/node/dom-token-list.d.ts +26 -26
  22. package/lib/ml-dom/node/dom-token-list.js +1 -1
  23. package/lib/ml-dom/node/element.d.ts +1902 -1896
  24. package/lib/ml-dom/node/element.js +18 -13
  25. package/lib/ml-dom/node/named-node-map.d.ts +44 -39
  26. package/lib/ml-dom/node/named-node-map.js +2 -1
  27. package/lib/ml-dom/node/node-list.d.ts +9 -3
  28. package/lib/ml-dom/node/node-list.js +2 -1
  29. package/lib/ml-dom/node/node-store.d.ts +8 -3
  30. package/lib/ml-dom/node/node.d.ts +491 -471
  31. package/lib/ml-dom/node/node.js +6 -3
  32. package/lib/ml-dom/node/parent-node.d.ts +66 -57
  33. package/lib/ml-dom/node/parent-node.js +6 -3
  34. package/lib/ml-dom/node/rule-mapper.d.ts +7 -7
  35. package/lib/ml-dom/node/rule-mapper.js +2 -1
  36. package/lib/ml-dom/node/text.d.ts +49 -46
  37. package/lib/ml-dom/node/types.d.ts +80 -12
  38. package/lib/ml-dom/node/unexpected-call-error.d.ts +1 -2
  39. package/lib/ml-dom/token/token.d.ts +44 -44
  40. package/lib/ml-rule/create-rule.d.ts +3 -1
  41. package/lib/ml-rule/create-test-rule.d.ts +5 -3
  42. package/lib/ml-rule/ml-rule-context.d.ts +55 -47
  43. package/lib/ml-rule/ml-rule.d.ts +33 -23
  44. package/lib/ml-rule/ml-rule.js +4 -5
  45. package/lib/ml-rule/types.d.ts +31 -13
  46. package/lib/plugin/plugin.d.ts +3 -1
  47. package/lib/plugin/types.d.ts +5 -5
  48. package/lib/ruleset/index.d.ts +4 -4
  49. package/lib/test/index.d.ts +19 -7
  50. package/lib/types.d.ts +8 -8
  51. package/lib/utils/get-location-from-chars.d.ts +9 -4
  52. 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
- #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;
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
  }
@@ -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 { GlobalRuleInfo, PlainData, Rule, RuleConfigValue, RuleInfo, Severity, Violation } from '@markuplint/ml-config';
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
- #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;
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>;
@@ -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 || this.defaultSeverity,
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 || document.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;
@@ -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
- 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>;
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 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;
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>;
@@ -1,2 +1,4 @@
1
1
  import type { PluginCreator, CreatePluginSettings } from './types';
2
- export declare function createPlugin<S extends CreatePluginSettings>(fn: Readonly<PluginCreator<S>>): Readonly<PluginCreator<S>>;
2
+ export declare function createPlugin<S extends CreatePluginSettings>(
3
+ fn: Readonly<PluginCreator<S>>,
4
+ ): Readonly<PluginCreator<S>>;
@@ -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
- readonly name: string;
5
- readonly rules?: Readonly<Record<string, Readonly<RuleSeed<any, any>>>>;
6
- readonly configs?: Readonly<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
- readonly name: string;
10
- create(setting: S): Omit<Plugin, 'name'>;
9
+ readonly name: string;
10
+ create(setting: S): Omit<Plugin, 'name'>;
11
11
  };
12
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: readonly ChildNodeRule[];
4
- readonly nodeRules: readonly NodeRule[];
5
- readonly rules: 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
  }
@@ -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
- readonly config?: Config;
7
- readonly parser?: Readonly<MLMarkupLanguageParser>;
8
- readonly 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 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>;
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
- 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>[];
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
- line: number;
3
- col: number;
4
- raw: string;
2
+ line: number;
3
+ col: number;
4
+ raw: string;
5
5
  }
6
- export declare function getLocationFromChars(searches: readonly string[], text: string, currentLine: number, currentCol: number): Location[];
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.5.0",
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.4.0",
27
- "@markuplint/html-parser": "3.5.0",
28
- "@markuplint/html-spec": "3.5.0",
29
- "@markuplint/i18n": "3.5.0",
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.5.0",
32
- "@markuplint/ml-spec": "3.5.0",
33
- "@markuplint/parser-utils": "3.5.0",
34
- "@markuplint/selector": "3.5.0",
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": "0c47b2c2722f6823a17f36edbab98486275f8ab4"
43
+ "gitHead": "3cdf5a088b2da03773d5d4461d0e65ec32290a00"
45
44
  }