@markuplint/ml-core 4.9.0 → 4.10.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/CHANGELOG.md CHANGED
@@ -3,24 +3,29 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
5
 
6
- # [4.9.0](https://github.com/markuplint/markuplint/compare/@markuplint/ml-core@4.8.3...@markuplint/ml-core@4.9.0) (2024-09-23)
6
+ ## [4.10.1](https://github.com/markuplint/markuplint/compare/@markuplint/ml-core@4.10.0...@markuplint/ml-core@4.10.1) (2024-10-15)
7
7
 
8
+ **Note:** Version bump only for package @markuplint/ml-core
8
9
 
9
- ### Features
10
10
 
11
- * **ml-core:** update DOM API according to TypeScript DOM Libs ([b95b689](https://github.com/markuplint/markuplint/commit/b95b689a84f0a176175943edf5d4163de8b1522f))
12
11
 
13
12
 
14
13
 
14
+ # [4.10.0](https://github.com/markuplint/markuplint/compare/@markuplint/ml-core@4.9.0...@markuplint/ml-core@4.10.0) (2024-10-14)
15
15
 
16
+ ### Features
16
17
 
17
- ## [4.8.3](https://github.com/markuplint/markuplint/compare/@markuplint/ml-core@4.8.2...@markuplint/ml-core@4.8.3) (2024-09-02)
18
+ - **ml-core:** enabled control over parse-error output using `severity.parseError` ([7ef6d6a](https://github.com/markuplint/markuplint/commit/7ef6d6ad58845c81367d5a2944c254a12eeaa17e))
18
19
 
19
- **Note:** Version bump only for package @markuplint/ml-core
20
+ # [4.9.0](https://github.com/markuplint/markuplint/compare/@markuplint/ml-core@4.8.3...@markuplint/ml-core@4.9.0) (2024-09-23)
20
21
 
22
+ ### Features
21
23
 
24
+ - **ml-core:** update DOM API according to TypeScript DOM Libs ([b95b689](https://github.com/markuplint/markuplint/commit/b95b689a84f0a176175943edf5d4163de8b1522f))
22
25
 
26
+ ## [4.8.3](https://github.com/markuplint/markuplint/compare/@markuplint/ml-core@4.8.2...@markuplint/ml-core@4.8.3) (2024-09-02)
23
27
 
28
+ **Note:** Version bump only for package @markuplint/ml-core
24
29
 
25
30
  ## [4.8.2](https://github.com/markuplint/markuplint/compare/@markuplint/ml-core@4.8.1...@markuplint/ml-core@4.8.2) (2024-06-25)
26
31
 
package/lib/ml-core.d.ts CHANGED
@@ -9,11 +9,12 @@ export type MLCoreParams = {
9
9
  } & MLFabric;
10
10
  export declare class MLCore {
11
11
  #private;
12
- constructor({ parser, sourceCode, ruleset, rules, locale, schemas, parserOptions, pretenders, filename, debug, configErrors, }: MLCoreParams);
12
+ constructor({ parser, sourceCode, ruleset, rules, locale, schemas, parserOptions, severity, pretenders, filename, debug, configErrors, }: MLCoreParams);
13
13
  get document(): ParserError | Document<RuleConfigValue, PlainData>;
14
14
  setCode(sourceCode: string): void;
15
15
  update({ parser, ruleset, rules, locale, schemas, parserOptions, configErrors }: Partial<MLFabric>): void;
16
16
  verify(fix?: boolean): Promise<Violation[]>;
17
17
  private _createDocument;
18
+ private _createParseError;
18
19
  private _parse;
19
20
  }
package/lib/ml-core.js CHANGED
@@ -9,19 +9,20 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
9
9
  if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
10
10
  return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
11
11
  };
12
- var _MLCore_ast, _MLCore_document, _MLCore_filename, _MLCore_locale, _MLCore_parser, _MLCore_parserOptions, _MLCore_pretenders, _MLCore_rules, _MLCore_ruleset, _MLCore_schemas, _MLCore_sourceCode, _MLCore_configErrors;
12
+ var _MLCore_ast, _MLCore_document, _MLCore_filename, _MLCore_locale, _MLCore_parser, _MLCore_parserOptions, _MLCore_severity, _MLCore_pretenders, _MLCore_rules, _MLCore_ruleset, _MLCore_schemas, _MLCore_sourceCode, _MLCore_configErrors;
13
13
  import { ParserError } from '@markuplint/parser-utils';
14
14
  import { log, enableDebug } from './debug.js';
15
15
  import { Document } from './ml-dom/index.js';
16
16
  const resultLog = log.extend('result');
17
17
  export class MLCore {
18
- constructor({ parser, sourceCode, ruleset, rules, locale, schemas, parserOptions, pretenders, filename, debug, configErrors, }) {
18
+ constructor({ parser, sourceCode, ruleset, rules, locale, schemas, parserOptions, severity, pretenders, filename, debug, configErrors, }) {
19
19
  _MLCore_ast.set(this, null);
20
20
  _MLCore_document.set(this, void 0);
21
21
  _MLCore_filename.set(this, void 0);
22
22
  _MLCore_locale.set(this, void 0);
23
23
  _MLCore_parser.set(this, void 0);
24
24
  _MLCore_parserOptions.set(this, void 0);
25
+ _MLCore_severity.set(this, void 0);
25
26
  _MLCore_pretenders.set(this, void 0);
26
27
  _MLCore_rules.set(this, void 0);
27
28
  _MLCore_ruleset.set(this, void 0);
@@ -43,6 +44,7 @@ export class MLCore {
43
44
  __classPrivateFieldSet(this, _MLCore_schemas, schemas, "f");
44
45
  __classPrivateFieldSet(this, _MLCore_filename, filename, "f");
45
46
  __classPrivateFieldSet(this, _MLCore_rules, [...rules], "f");
47
+ __classPrivateFieldSet(this, _MLCore_severity, severity, "f");
46
48
  __classPrivateFieldSet(this, _MLCore_pretenders, [...pretenders], "f");
47
49
  __classPrivateFieldSet(this, _MLCore_configErrors, [...(configErrors ?? [])], "f");
48
50
  this._parse();
@@ -78,14 +80,11 @@ export class MLCore {
78
80
  log('verify: start');
79
81
  const violations = [];
80
82
  if (__classPrivateFieldGet(this, _MLCore_document, "f") instanceof ParserError) {
81
- violations.push({
82
- ruleId: 'parse-error',
83
- severity: 'error',
84
- message: __classPrivateFieldGet(this, _MLCore_document, "f").message,
85
- col: __classPrivateFieldGet(this, _MLCore_document, "f").col,
86
- line: __classPrivateFieldGet(this, _MLCore_document, "f").line,
87
- raw: __classPrivateFieldGet(this, _MLCore_document, "f").raw,
88
- });
83
+ const parseError = this._createParseError(__classPrivateFieldGet(this, _MLCore_document, "f").message, __classPrivateFieldGet(this, _MLCore_document, "f").line, __classPrivateFieldGet(this, _MLCore_document, "f").col, __classPrivateFieldGet(this, _MLCore_document, "f").raw);
84
+ if (!parseError) {
85
+ return [];
86
+ }
87
+ violations.push(parseError);
89
88
  log('verify: error %o', __classPrivateFieldGet(this, _MLCore_document, "f").message);
90
89
  return violations;
91
90
  }
@@ -112,15 +111,11 @@ export class MLCore {
112
111
  throw error;
113
112
  });
114
113
  if (results instanceof ParserError) {
115
- log('%s Rule: verify error %o', rule.name, results.message);
116
- violations.push({
117
- ruleId: 'parse-error',
118
- severity: 'error',
119
- message: results.message,
120
- col: results.col,
121
- line: results.line,
122
- raw: results.raw,
123
- });
114
+ const parseError = this._createParseError(results.message, results.line, results.col, results.raw);
115
+ if (parseError) {
116
+ log('%s Rule: verify error %o', rule.name, results.message);
117
+ violations.push(parseError);
118
+ }
124
119
  }
125
120
  else {
126
121
  violations.push(...results);
@@ -167,6 +162,23 @@ export class MLCore {
167
162
  }
168
163
  }
169
164
  }
165
+ _createParseError(message, line, col, raw) {
166
+ if (__classPrivateFieldGet(this, _MLCore_severity, "f").parseError === false || __classPrivateFieldGet(this, _MLCore_severity, "f").parseError === 'off') {
167
+ return null;
168
+ }
169
+ // Default severity is 'error'
170
+ const severity = __classPrivateFieldGet(this, _MLCore_severity, "f").parseError === true || __classPrivateFieldGet(this, _MLCore_severity, "f").parseError == null
171
+ ? 'error'
172
+ : __classPrivateFieldGet(this, _MLCore_severity, "f").parseError;
173
+ return {
174
+ ruleId: 'parse-error',
175
+ severity,
176
+ message,
177
+ line,
178
+ col,
179
+ raw,
180
+ };
181
+ }
170
182
  _parse() {
171
183
  try {
172
184
  __classPrivateFieldSet(this, _MLCore_ast, __classPrivateFieldGet(this, _MLCore_parser, "f").parse(__classPrivateFieldGet(this, _MLCore_sourceCode, "f"), __classPrivateFieldGet(this, _MLCore_parserOptions, "f")), "f");
@@ -183,4 +195,4 @@ export class MLCore {
183
195
  }
184
196
  }
185
197
  }
186
- _MLCore_ast = new WeakMap(), _MLCore_document = new WeakMap(), _MLCore_filename = new WeakMap(), _MLCore_locale = new WeakMap(), _MLCore_parser = new WeakMap(), _MLCore_parserOptions = new WeakMap(), _MLCore_pretenders = new WeakMap(), _MLCore_rules = new WeakMap(), _MLCore_ruleset = new WeakMap(), _MLCore_schemas = new WeakMap(), _MLCore_sourceCode = new WeakMap(), _MLCore_configErrors = new WeakMap();
198
+ _MLCore_ast = new WeakMap(), _MLCore_document = new WeakMap(), _MLCore_filename = new WeakMap(), _MLCore_locale = new WeakMap(), _MLCore_parser = new WeakMap(), _MLCore_parserOptions = new WeakMap(), _MLCore_severity = new WeakMap(), _MLCore_pretenders = new WeakMap(), _MLCore_rules = new WeakMap(), _MLCore_ruleset = new WeakMap(), _MLCore_schemas = new WeakMap(), _MLCore_sourceCode = new WeakMap(), _MLCore_configErrors = new WeakMap();
package/lib/types.d.ts CHANGED
@@ -2,7 +2,7 @@ import type { AnyMLRule } from './ml-rule/index.js';
2
2
  import type { Ruleset } from './ruleset/index.js';
3
3
  import type { LocaleSet } from '@markuplint/i18n';
4
4
  import type { MLParser, ParserOptions } from '@markuplint/ml-ast';
5
- import type { Pretender } from '@markuplint/ml-config';
5
+ import type { Pretender, SeverityOptions } 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 = {
@@ -12,6 +12,7 @@ export type MLFabric = {
12
12
  readonly locale: LocaleSet;
13
13
  readonly schemas: MLSchema;
14
14
  readonly parserOptions: ParserOptions;
15
+ readonly severity: SeverityOptions;
15
16
  readonly pretenders: readonly Pretender[];
16
17
  readonly configErrors?: readonly Readonly<Error>[];
17
18
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@markuplint/ml-core",
3
- "version": "4.9.0",
3
+ "version": "4.10.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>",
@@ -28,20 +28,20 @@
28
28
  "./lib/configs.js": "./lib/configs.browser.js"
29
29
  },
30
30
  "dependencies": {
31
- "@markuplint/config-presets": "4.5.6",
32
- "@markuplint/html-parser": "4.6.7",
33
- "@markuplint/html-spec": "4.9.1",
34
- "@markuplint/i18n": "4.5.3",
35
- "@markuplint/ml-ast": "4.4.4",
36
- "@markuplint/ml-config": "4.7.4",
37
- "@markuplint/ml-spec": "4.7.0",
38
- "@markuplint/parser-utils": "4.6.7",
39
- "@markuplint/selector": "4.6.7",
40
- "@markuplint/shared": "4.4.5",
31
+ "@markuplint/config-presets": "4.5.8",
32
+ "@markuplint/html-parser": "4.6.9",
33
+ "@markuplint/html-spec": "4.9.3",
34
+ "@markuplint/i18n": "4.5.5",
35
+ "@markuplint/ml-ast": "4.4.6",
36
+ "@markuplint/ml-config": "4.8.1",
37
+ "@markuplint/ml-spec": "4.7.2",
38
+ "@markuplint/parser-utils": "4.7.0",
39
+ "@markuplint/selector": "4.6.9",
40
+ "@markuplint/shared": "4.4.7",
41
41
  "@types/debug": "4.1.12",
42
42
  "debug": "4.3.7",
43
43
  "is-plain-object": "5.0.0",
44
44
  "type-fest": "4.26.1"
45
45
  },
46
- "gitHead": "05d2eabfcc41b67847c24049f12dd2b9f5ca6485"
46
+ "gitHead": "c8c82d36c2e48d191091cbc22ca1b99ed0704b9f"
47
47
  }