@markuplint/ml-core 2.0.0-rc.1 → 2.0.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 (46) hide show
  1. package/README.md +0 -15
  2. package/lib/index.d.ts +0 -1
  3. package/lib/index.js +1 -3
  4. package/lib/ml-core.d.ts +12 -11
  5. package/lib/ml-core.js +35 -14
  6. package/lib/ml-dom/document.d.ts +66 -49
  7. package/lib/ml-dom/document.js +8 -6
  8. package/lib/ml-dom/helper/create-node.d.ts +5 -1
  9. package/lib/ml-dom/helper/debug.d.ts +4 -1
  10. package/lib/ml-dom/helper/getIndent.d.ts +7 -7
  11. package/lib/ml-dom/helper/mapped-nodes.d.ts +51 -3
  12. package/lib/ml-dom/helper/match-selector.d.ts +10 -6
  13. package/lib/ml-dom/helper/match-selector.js +2 -2
  14. package/lib/ml-dom/helper/node-store.d.ts +6 -3
  15. package/lib/ml-dom/helper/node-store.js +7 -2
  16. package/lib/ml-dom/helper/selector.d.ts +4 -4
  17. package/lib/ml-dom/helper/selector.js +30 -22
  18. package/lib/ml-dom/helper/walkers.d.ts +7 -2
  19. package/lib/ml-dom/index.d.ts +10 -1
  20. package/lib/ml-dom/rule-mapper.d.ts +7 -7
  21. package/lib/ml-dom/tokens/abstract-element.d.ts +40 -36
  22. package/lib/ml-dom/tokens/attribute.d.ts +36 -36
  23. package/lib/ml-dom/tokens/comment.d.ts +5 -2
  24. package/lib/ml-dom/tokens/doctype.d.ts +10 -7
  25. package/lib/ml-dom/tokens/element-close-tag.d.ts +19 -16
  26. package/lib/ml-dom/tokens/element.d.ts +18 -15
  27. package/lib/ml-dom/tokens/node.d.ts +23 -16
  28. package/lib/ml-dom/tokens/omitted-element.d.ts +7 -4
  29. package/lib/ml-dom/tokens/preprocessor-specific-attribute.d.ts +20 -20
  30. package/lib/ml-dom/tokens/preprocessor-specific-block.d.ts +8 -5
  31. package/lib/ml-dom/tokens/text.d.ts +9 -6
  32. package/lib/ml-dom/tokens/token.d.ts +13 -13
  33. package/lib/ml-dom/types.d.ts +35 -13
  34. package/lib/ml-error/ml-parse-error.d.ts +5 -5
  35. package/lib/ml-rule/create-test-rule.d.ts +5 -3
  36. package/lib/ml-rule/ml-rule-context.d.ts +52 -44
  37. package/lib/ml-rule/ml-rule.d.ts +33 -23
  38. package/lib/ml-rule/types.d.ts +5 -5
  39. package/lib/plugin/types.d.ts +5 -5
  40. package/lib/ruleset/index.d.ts +4 -4
  41. package/lib/test/index.d.ts +14 -5
  42. package/lib/types.d.ts +6 -6
  43. package/lib/utils/get-location-from-chars.d.ts +9 -4
  44. package/markuplint-recommended.json +13 -6
  45. package/package.json +10 -9
  46. package/tsconfig.tsbuildinfo +1 -1
@@ -4,10 +4,13 @@ import type { MLASTText } from '@markuplint/ml-ast';
4
4
  import type { RuleConfigValue } from '@markuplint/ml-config';
5
5
  import type { ContentModel } from '@markuplint/ml-spec';
6
6
  import MLDOMNode from './node';
7
- export default class MLDOMText<T extends RuleConfigValue, O = null> extends MLDOMNode<T, O, MLASTText> implements IMLDOMText {
8
- readonly type = "Text";
9
- readonly isRawText: boolean;
10
- readonly ownModels: Set<ContentModel>;
11
- constructor(astNode: MLASTText, document: Document<T, O>);
12
- isWhitespace(): boolean;
7
+ export default class MLDOMText<T extends RuleConfigValue, O = null>
8
+ extends MLDOMNode<T, O, MLASTText>
9
+ implements IMLDOMText
10
+ {
11
+ readonly type = 'Text';
12
+ readonly isRawText: boolean;
13
+ readonly ownModels: Set<ContentModel>;
14
+ constructor(astNode: MLASTText, document: Document<T, O>);
15
+ isWhitespace(): boolean;
13
16
  }
@@ -1,16 +1,16 @@
1
1
  import type { MLToken } from '@markuplint/ml-ast';
2
2
  export default class MLDOMToken<A extends MLToken> {
3
- #private;
4
- readonly uuid: string;
5
- protected readonly _astToken: A;
6
- constructor(astToken: A);
7
- get originRaw(): string;
8
- get raw(): string;
9
- get startOffset(): number;
10
- get endOffset(): number;
11
- get startLine(): number;
12
- get endLine(): number;
13
- get startCol(): number;
14
- get endCol(): number;
15
- fix(raw: string): void;
3
+ #private;
4
+ readonly uuid: string;
5
+ protected readonly _astToken: A;
6
+ constructor(astToken: A);
7
+ get originRaw(): string;
8
+ get raw(): string;
9
+ get startOffset(): number;
10
+ get endOffset(): number;
11
+ get startLine(): number;
12
+ get endLine(): number;
13
+ get startCol(): number;
14
+ get endCol(): number;
15
+ fix(raw: string): void;
16
16
  }
@@ -1,27 +1,49 @@
1
- import type { MLDOMComment, MLDOMDoctype, MLDOMElement, MLDOMElementCloseTag, MLDOMOmittedElement, MLDOMPreprocessorSpecificBlock, MLDOMText } from './tokens';
1
+ import type {
2
+ MLDOMComment,
3
+ MLDOMDoctype,
4
+ MLDOMElement,
5
+ MLDOMElementCloseTag,
6
+ MLDOMOmittedElement,
7
+ MLDOMPreprocessorSpecificBlock,
8
+ MLDOMText,
9
+ } from './tokens';
2
10
  import type { RuleConfigValue } from '@markuplint/ml-config';
3
11
  export interface IMLDOMDoctype extends IMLDOMNode {
4
- type: 'Doctype';
12
+ type: 'Doctype';
5
13
  }
6
14
  export interface IMLDOMElement extends IMLDOMNode {
7
- type: 'Element';
15
+ type: 'Element';
8
16
  }
9
17
  export interface IMLDOMElementCloseTag extends IMLDOMNode {
10
- type: 'ElementCloseTag';
18
+ type: 'ElementCloseTag';
11
19
  }
12
20
  export interface IMLDOMOmittedElement extends IMLDOMNode {
13
- type: 'OmittedElement';
21
+ type: 'OmittedElement';
14
22
  }
15
23
  export interface IMLDOMComment extends IMLDOMNode {
16
- type: 'Comment';
24
+ type: 'Comment';
17
25
  }
18
26
  export interface IMLDOMText extends IMLDOMNode {
19
- type: 'Text';
27
+ type: 'Text';
20
28
  }
21
29
  export interface IMLDOMPreprocessorSpecificBlock extends IMLDOMNode {
22
- type: 'PSBlock';
23
- }
24
- export interface IMLDOMNode {
25
- }
26
- export declare type AnonymousNode<T extends RuleConfigValue, O = null> = MLDOMDoctype<T, O> | MLDOMElement<T, O> | MLDOMElementCloseTag<T, O> | MLDOMOmittedElement<T, O> | MLDOMComment<T, O> | MLDOMPreprocessorSpecificBlock<T, O> | MLDOMText<T, O>;
27
- export declare type NodeType = 'Doctype' | 'Element' | 'ElementCloseTag' | 'OmittedElement' | 'Comment' | 'Text' | 'Node' | 'PSBlock';
30
+ type: 'PSBlock';
31
+ }
32
+ export interface IMLDOMNode {}
33
+ export declare type AnonymousNode<T extends RuleConfigValue, O = null> =
34
+ | MLDOMDoctype<T, O>
35
+ | MLDOMElement<T, O>
36
+ | MLDOMElementCloseTag<T, O>
37
+ | MLDOMOmittedElement<T, O>
38
+ | MLDOMComment<T, O>
39
+ | MLDOMPreprocessorSpecificBlock<T, O>
40
+ | MLDOMText<T, O>;
41
+ export declare type NodeType =
42
+ | 'Doctype'
43
+ | 'Element'
44
+ | 'ElementCloseTag'
45
+ | 'OmittedElement'
46
+ | 'Comment'
47
+ | 'Text'
48
+ | 'Node'
49
+ | 'PSBlock';
@@ -1,7 +1,7 @@
1
1
  export default class MLParseError extends Error {
2
- readonly line: number;
3
- readonly col: number;
4
- readonly raw: string;
5
- readonly nodeName: string;
6
- constructor(line: number, col: number, raw: string, nodeName: string);
2
+ readonly line: number;
3
+ readonly col: number;
4
+ readonly raw: string;
5
+ readonly nodeName: string;
6
+ constructor(line: number, col: number, raw: string, nodeName: string);
7
7
  }
@@ -1,6 +1,8 @@
1
1
  import type { RuleSeed } from './types';
2
2
  import type { RuleConfigValue } from '@markuplint/ml-config';
3
3
  import { MLRule } from './ml-rule';
4
- export declare function createRule<T extends RuleConfigValue, O = null>(seed: RuleSeed<T, O> & {
5
- name: string;
6
- }): MLRule<T, O>;
4
+ export declare function createRule<T extends RuleConfigValue, O = null>(
5
+ seed: RuleSeed<T, O> & {
6
+ name: string;
7
+ },
8
+ ): MLRule<T, O>;
@@ -2,48 +2,56 @@ import type Document from '../ml-dom/document';
2
2
  import type { LocaleSet, Translator } from '@markuplint/i18n';
3
3
  import type { Report, RuleConfigValue, RuleInfo } from '@markuplint/ml-config';
4
4
  export declare class MLRuleContext<T extends RuleConfigValue, O = null> {
5
- #private;
6
- readonly document: Document<T, O>;
7
- readonly globalRule: RuleInfo<T, O>;
8
- readonly translate: Translator;
9
- readonly locale: string;
10
- constructor(document: Document<T, O>, locale: LocaleSet, rule: RuleInfo<T, O>);
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
- report(report: Report<T, O>): void;
27
- provide(): {
28
- document: Document<T, O>;
29
- translate: Translator;
30
- t: Translator;
31
- globalRule: RuleInfo<T, O>;
32
- reports: ({
33
- message: string;
34
- line: number;
35
- col: number;
36
- raw: string;
37
- } | {
38
- message: string;
39
- scope: import("@markuplint/ml-config").Scope<T, O>;
40
- } | {
41
- message: string;
42
- scope: import("@markuplint/ml-config").Scope<T, O>;
43
- line: number;
44
- col: number;
45
- raw: string;
46
- })[];
47
- report: (report: Report<T, O>) => void;
48
- };
5
+ #private;
6
+ readonly document: Document<T, O>;
7
+ readonly globalRule: RuleInfo<T, O>;
8
+ readonly translate: Translator;
9
+ readonly locale: string;
10
+ constructor(document: Document<T, O>, locale: LocaleSet, rule: RuleInfo<T, O>);
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
+ report(report: Report<T, O>): void;
31
+ provide(): {
32
+ document: Document<T, O>;
33
+ translate: Translator;
34
+ t: Translator;
35
+ globalRule: RuleInfo<T, O>;
36
+ reports: (
37
+ | {
38
+ message: string;
39
+ line: number;
40
+ col: number;
41
+ raw: string;
42
+ }
43
+ | {
44
+ message: string;
45
+ scope: import('@markuplint/ml-config').Scope<T, O>;
46
+ }
47
+ | {
48
+ message: string;
49
+ scope: import('@markuplint/ml-config').Scope<T, O>;
50
+ line: number;
51
+ col: number;
52
+ raw: string;
53
+ }
54
+ )[];
55
+ report: (report: Report<T, O>) => void;
56
+ };
49
57
  }
@@ -2,29 +2,39 @@ import type { Ruleset } from '..';
2
2
  import type Document from '../ml-dom/document';
3
3
  import type { RuleSeed } from './types';
4
4
  import type { LocaleSet } from '@markuplint/i18n';
5
- import type { GlobalRuleInfo, RuleConfig, RuleConfigValue, RuleInfo, Rules, Severity, Violation } from '@markuplint/ml-config';
5
+ import type {
6
+ GlobalRuleInfo,
7
+ RuleConfig,
8
+ RuleConfigValue,
9
+ RuleInfo,
10
+ Rules,
11
+ Severity,
12
+ Violation,
13
+ } from '@markuplint/ml-config';
6
14
  export declare class MLRule<T extends RuleConfigValue, O = null> {
7
- #private;
8
- readonly name: string;
9
- readonly defaultServerity: Severity;
10
- readonly defaultValue: T;
11
- readonly defaultOptions: O;
12
- /**
13
- * The following getter is unused internally,
14
- * only for extending from 3rd party library
15
- */
16
- protected get v(): RuleSeed<T, O>['verify'];
17
- /**
18
- * The following getter is unused internally,
19
- * only for extending from 3rd party library
20
- */
21
- protected get f(): RuleSeed<T, O>['fix'];
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[]>;
26
- getRuleInfo(ruleSet: Ruleset, ruleName: string): GlobalRuleInfo<T, O>;
27
- _optimize(rules: Rules | undefined, ruleName: string): RuleInfo<T, O>;
28
- optimizeOption(configSettings: T | RuleConfig<T, O> | undefined): RuleInfo<T, O>;
15
+ #private;
16
+ readonly name: string;
17
+ readonly defaultServerity: Severity;
18
+ readonly defaultValue: T;
19
+ readonly defaultOptions: O;
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
+ /**
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
+ constructor(
31
+ o: RuleSeed<T, O> & {
32
+ name: string;
33
+ },
34
+ );
35
+ verify(document: Document<T, O>, locale: LocaleSet, globalRule: RuleInfo<T, O>, fix: boolean): Promise<Violation[]>;
36
+ getRuleInfo(ruleSet: Ruleset, ruleName: string): GlobalRuleInfo<T, O>;
37
+ _optimize(rules: Rules | undefined, ruleName: string): RuleInfo<T, O>;
38
+ optimizeOption(configSettings: T | RuleConfig<T, O> | undefined): RuleInfo<T, O>;
29
39
  }
30
40
  export declare type AnyMLRule = MLRule<RuleConfigValue, unknown>;
@@ -1,10 +1,10 @@
1
1
  import type { MLRuleContext } from './ml-rule-context';
2
2
  import type { RuleConfigValue, Severity } from '@markuplint/ml-config';
3
3
  export declare type RuleSeed<T extends RuleConfigValue = boolean, O = null> = {
4
- defaultServerity?: Severity;
5
- defaultValue?: T;
6
- defaultOptions?: O;
7
- verify(context: ReturnType<MLRuleContext<T, O>['provide']>): void | Promise<void>;
8
- fix?(context: ReturnType<MLRuleContext<T, O>['provide']>): void | Promise<void>;
4
+ defaultServerity?: Severity;
5
+ defaultValue?: T;
6
+ defaultOptions?: O;
7
+ verify(context: ReturnType<MLRuleContext<T, O>['provide']>): void | Promise<void>;
8
+ fix?(context: ReturnType<MLRuleContext<T, O>['provide']>): void | Promise<void>;
9
9
  };
10
10
  export declare type AnyRuleSeed = RuleSeed<any, any>;
@@ -1,12 +1,12 @@
1
1
  import type { AnyRuleSeed } from '../ml-rule';
2
2
  import type { Config } from '@markuplint/ml-config';
3
3
  export declare type Plugin = {
4
- name: string;
5
- rules?: Record<string, AnyRuleSeed>;
6
- configs?: Record<string, Config>;
4
+ name: string;
5
+ rules?: Record<string, AnyRuleSeed>;
6
+ configs?: Record<string, Config>;
7
7
  };
8
8
  export declare type PluginCreator<S extends CreatePluginSettings> = {
9
- name: string;
10
- create(setting: S): Omit<Plugin, 'name'>;
9
+ name: string;
10
+ create(setting: S): Omit<Plugin, 'name'>;
11
11
  };
12
12
  export declare type CreatePluginSettings = 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 rules: Readonly<Rules>;
4
- readonly nodeRules: ReadonlyArray<NodeRule>;
5
- readonly childNodeRules: ReadonlyArray<ChildNodeRule>;
6
- constructor(config: Config);
3
+ readonly rules: Readonly<Rules>;
4
+ readonly nodeRules: ReadonlyArray<NodeRule>;
5
+ readonly childNodeRules: ReadonlyArray<ChildNodeRule>;
6
+ constructor(config: Config);
7
7
  }
@@ -3,12 +3,21 @@ import type { Config, 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 declare type CreateTestOptions = {
6
- config?: Config;
7
- parser?: MLMarkupLanguageParser;
6
+ config?: Config;
7
+ parser?: MLMarkupLanguageParser;
8
8
  };
9
- 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").AnonymousNode<any, any>[];
11
- export declare function createTestElement(sourceCode: string, options?: CreateTestOptions): import("../ml-dom").Element<any, any>;
9
+ export declare function createTestDocument<T extends RuleConfigValue = any, O = any>(
10
+ sourceCode: string,
11
+ options?: CreateTestOptions,
12
+ ): Document<T, O>;
13
+ export declare function createTestNodeList(
14
+ sourceCode: string,
15
+ options?: CreateTestOptions,
16
+ ): readonly import('../ml-dom').AnonymousNode<any, any>[];
17
+ export declare function createTestElement(
18
+ sourceCode: string,
19
+ options?: CreateTestOptions,
20
+ ): import('../ml-dom').Element<any, any>;
12
21
  /**
13
22
  * for test suite
14
23
  */
package/lib/types.d.ts CHANGED
@@ -6,10 +6,10 @@ import type { ParserOptions } 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 = {
9
- parser: MLMarkupLanguageParser;
10
- ruleset: Partial<Ruleset>;
11
- rules: AnyMLRule[];
12
- locale: LocaleSet;
13
- schemas: MLSchema;
14
- parserOptions: ParserOptions;
9
+ parser: MLMarkupLanguageParser;
10
+ ruleset: Partial<Ruleset>;
11
+ rules: AnyMLRule[];
12
+ locale: LocaleSet;
13
+ schemas: MLSchema;
14
+ parserOptions: ParserOptions;
15
15
  };
@@ -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: string[], text: string, currentLine: number, currentCol: number): Location[];
6
+ export declare function getLocationFromChars(
7
+ searches: string[],
8
+ text: string,
9
+ currentLine: number,
10
+ currentCol: number,
11
+ ): Location[];
7
12
  export {};
@@ -13,6 +13,7 @@
13
13
  "deprecated-element": true,
14
14
  "disallowed-element": ["hgroup"],
15
15
  "doctype": true,
16
+ "end-tag": false,
16
17
  "id-duplication": true,
17
18
  "indentation": false,
18
19
  "ineffective-attr": true,
@@ -24,6 +25,9 @@
24
25
  },
25
26
  "accesskey": {
26
27
  "disallowed": true
28
+ },
29
+ "tabindex": {
30
+ "enum": ["-1", "0"]
27
31
  }
28
32
  }
29
33
  }
@@ -129,12 +133,15 @@
129
133
  {
130
134
  "selector": ":where(a[target=_blank], area[target=_blank])",
131
135
  "rules": {
132
- "required-attr": [
133
- {
134
- "name": "rel",
135
- "value": "noreferrer"
136
- }
137
- ]
136
+ "required-attr": {
137
+ "value": [
138
+ {
139
+ "name": "rel",
140
+ "value": "/(?<![^\\s]+)noreferrer(?![^\\s]+)/"
141
+ }
142
+ ],
143
+ "reason": "The \"rel\" attribute should be required with \"noreferrer\" if the \"a\" element has the \"target=_black\""
144
+ }
138
145
  }
139
146
  },
140
147
  {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@markuplint/ml-core",
3
- "version": "2.0.0-rc.1",
3
+ "version": "2.0.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>",
@@ -17,17 +17,18 @@
17
17
  "clean": "tsc --build --clean"
18
18
  },
19
19
  "dependencies": {
20
- "@markuplint/i18n": "2.0.0-rc.1",
21
- "@markuplint/ml-ast": "2.0.0-rc.1",
22
- "@markuplint/ml-config": "2.0.0-rc.1",
23
- "@markuplint/ml-spec": "2.0.0-rc.1",
24
- "debug": "^4.3.2",
25
- "postcss-selector-parser": "^6.0.6",
20
+ "@markuplint/i18n": "2.0.0",
21
+ "@markuplint/ml-ast": "2.0.0",
22
+ "@markuplint/ml-config": "2.0.0",
23
+ "@markuplint/ml-spec": "2.0.0",
24
+ "@markuplint/parser-utils": "2.0.0",
25
+ "debug": "^4.3.3",
26
+ "postcss-selector-parser": "^6.0.9",
26
27
  "tslib": "^2.3.1"
27
28
  },
28
29
  "devDependencies": {
29
- "@markuplint/html-parser": "2.0.0-rc.1",
30
+ "@markuplint/html-parser": "2.0.0",
30
31
  "@types/debug": "^4.1.7"
31
32
  },
32
- "gitHead": "34dbaf8bc5ee499315a32857c59b9c6f6bb73594"
33
+ "gitHead": "de81fc514acdf472f87184e3499e9364258f9b66"
33
34
  }