markuplint 3.0.0-dev.25 → 3.0.0-dev.300

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 (65) hide show
  1. package/README.md +10 -6
  2. package/bin/markuplint.mjs +3 -0
  3. package/lib/api/index.d.ts +2 -2
  4. package/lib/api/index.js +2 -10
  5. package/lib/api/lint.d.ts +3 -3
  6. package/lib/api/lint.js +5 -10
  7. package/lib/api/ml-engine.d.ts +15 -9
  8. package/lib/api/ml-engine.js +135 -102
  9. package/lib/api/types.d.ts +30 -34
  10. package/lib/api/types.js +1 -2
  11. package/lib/api/v1.d.ts +12 -12
  12. package/lib/api/v1.js +13 -24
  13. package/lib/cli/bootstrap.d.ts +15 -7
  14. package/lib/cli/bootstrap.js +19 -11
  15. package/lib/cli/command.d.ts +3 -3
  16. package/lib/cli/command.js +27 -26
  17. package/lib/cli/create-rule/index.js +56 -42
  18. package/lib/cli/index.js +27 -31
  19. package/lib/cli/init/create-config.d.ts +4 -0
  20. package/lib/cli/init/create-config.js +90 -0
  21. package/lib/cli/init/get-default-rules.d.ts +3 -0
  22. package/lib/cli/init/get-default-rules.js +52 -0
  23. package/lib/cli/init/index.js +43 -231
  24. package/lib/cli/init/install-module.d.ts +3 -1
  25. package/lib/cli/init/install-module.js +22 -17
  26. package/lib/cli/init/types.d.ts +8 -0
  27. package/lib/cli/init/types.js +1 -0
  28. package/lib/cli/output.d.ts +2 -2
  29. package/lib/cli/output.js +13 -15
  30. package/lib/cli/prompt.d.ts +9 -9
  31. package/lib/cli/prompt.js +15 -25
  32. package/lib/cli/search/index.d.ts +2 -2
  33. package/lib/cli/search/index.js +7 -10
  34. package/lib/debug.js +8 -13
  35. package/lib/get-json-module.d.ts +1 -0
  36. package/lib/get-json-module.js +10 -0
  37. package/lib/global-settings.d.ts +1 -1
  38. package/lib/global-settings.js +2 -7
  39. package/lib/i18n.js +9 -15
  40. package/lib/index.d.ts +7 -5
  41. package/lib/index.js +6 -10
  42. package/lib/reporter/github-reporter.d.ts +2 -0
  43. package/lib/reporter/github-reporter.js +19 -0
  44. package/lib/reporter/index.d.ts +3 -2
  45. package/lib/reporter/index.js +3 -5
  46. package/lib/reporter/simple-reporter.d.ts +2 -2
  47. package/lib/reporter/simple-reporter.js +12 -17
  48. package/lib/reporter/standard-reporter.d.ts +2 -2
  49. package/lib/reporter/standard-reporter.js +18 -23
  50. package/lib/testing-tool/index.d.ts +10 -10
  51. package/lib/testing-tool/index.js +17 -25
  52. package/lib/types.d.ts +6 -7
  53. package/lib/types.js +1 -2
  54. package/lib/util.d.ts +0 -2
  55. package/lib/util.js +21 -37
  56. package/lib/v1.d.ts +1 -1
  57. package/lib/v1.js +1 -5
  58. package/lib/version.d.ts +1 -0
  59. package/lib/version.js +3 -0
  60. package/package.json +43 -31
  61. package/bin/markuplint +0 -3
  62. package/media/screenshot01.png +0 -0
  63. package/test/plugin001.js +0 -24
  64. package/tsconfig.test.json +0 -3
  65. package/tsconfig.tsbuildinfo +0 -1
package/lib/cli/prompt.js CHANGED
@@ -1,26 +1,20 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.confirmSequence = exports.confirm = exports.input = exports.multiSelect = exports.select = void 0;
4
- const tslib_1 = require("tslib");
5
- const cli_color_1 = tslib_1.__importDefault(require("cli-color"));
6
- const enquirer_1 = require("enquirer");
7
- async function select(question) {
8
- const res = await (0, enquirer_1.prompt)({
1
+ import c from 'cli-color';
2
+ import Enquirer from 'enquirer';
3
+ export async function select(question) {
4
+ const res = await Enquirer.prompt({
9
5
  ...question,
10
6
  name: '__Q__',
11
7
  type: 'select',
12
8
  result(resName) {
13
- var _a;
14
9
  // @ts-ignore
15
- return (_a = this.options.choices.find(c => c.name === resName)) === null || _a === void 0 ? void 0 : _a.value;
10
+ return this.options.choices.find(c => c.name === resName)?.value;
16
11
  },
17
12
  });
18
13
  // @ts-ignore
19
14
  return res['__Q__'];
20
15
  }
21
- exports.select = select;
22
- async function multiSelect(question) {
23
- const res = await (0, enquirer_1.prompt)({
16
+ export async function multiSelect(question) {
17
+ const res = await Enquirer.prompt({
24
18
  ...question,
25
19
  name: '__Q__',
26
20
  type: 'multiselect',
@@ -35,11 +29,10 @@ async function multiSelect(question) {
35
29
  // @ts-ignore
36
30
  return res['__Q__'];
37
31
  }
38
- exports.multiSelect = multiSelect;
39
- async function input(question, validation) {
32
+ export async function input(question, validation) {
40
33
  // eslint-disable-next-line no-constant-condition
41
34
  while (true) {
42
- const _res = await (0, enquirer_1.prompt)({
35
+ const _res = await Enquirer.prompt({
43
36
  message: question,
44
37
  name: '__Q__',
45
38
  type: 'input',
@@ -47,26 +40,24 @@ async function input(question, validation) {
47
40
  // @ts-ignore
48
41
  const res = _res['__Q__'];
49
42
  if (validation && !validation.test(res)) {
50
- process.stdout.write(cli_color_1.default.yellow('Oops! The name that you type is an invalid format.\n'));
43
+ process.stdout.write(c.yellow('Oops! The name that you type is an invalid format.\n'));
51
44
  continue;
52
45
  }
53
46
  return res;
54
47
  }
55
48
  }
56
- exports.input = input;
57
- async function confirm(question, options) {
58
- const res = await (0, enquirer_1.prompt)({
49
+ export async function confirm(question, options) {
50
+ const res = await Enquirer.prompt({
59
51
  message: question,
60
52
  name: '__Q__',
61
53
  type: 'confirm',
62
- initial: !!(options === null || options === void 0 ? void 0 : options.initial),
54
+ initial: !!options?.initial,
63
55
  });
64
56
  // @ts-ignore
65
57
  return !!res['__Q__'];
66
58
  }
67
- exports.confirm = confirm;
68
- async function confirmSequence(questions) {
69
- const res = await (0, enquirer_1.prompt)(questions.map(question => {
59
+ export async function confirmSequence(questions) {
60
+ const res = await Enquirer.prompt(questions.map(question => {
70
61
  return {
71
62
  ...question,
72
63
  type: 'confirm',
@@ -74,4 +65,3 @@ async function confirmSequence(questions) {
74
65
  }));
75
66
  return res;
76
67
  }
77
- exports.confirmSequence = confirmSequence;
@@ -1,2 +1,2 @@
1
- import type { CLIOptions } from '../bootstrap';
2
- export default function (files: string[], options: CLIOptions, selectors: string): Promise<void>;
1
+ import type { CLIOptions } from '../bootstrap.js';
2
+ export default function (files: readonly string[], options: CLIOptions, selectors: string): Promise<void>;
@@ -1,24 +1,22 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const ml_core_1 = require("@markuplint/ml-core");
4
- const command_1 = require("../command");
5
- async function default_1(files, options, selectors) {
1
+ import { createRule, MLRule } from '@markuplint/ml-core';
2
+ import { command } from '../command.js';
3
+ export default async function (files, options, selectors) {
6
4
  const name = '__CLI_SEARCH__';
7
5
  const locations = [];
8
- await (0, command_1.command)(files, {
6
+ await command(files, {
9
7
  ...options,
10
8
  problemOnly: true,
11
9
  importPresetRules: false,
12
10
  }, {
13
11
  rules: [
14
- new ml_core_1.MLRule({
12
+ new MLRule({
15
13
  name,
16
- ...(0, ml_core_1.createRule)({
14
+ ...createRule({
17
15
  verify({ document }) {
18
16
  const nodes = document.querySelectorAll(selectors);
19
17
  locations.push(...Array.from(nodes).map(node => {
20
18
  return {
21
- file: document.filename || '_NO_FILE_',
19
+ file: document.filename ?? '_NO_FILE_',
22
20
  line: node.startLine,
23
21
  col: node.startCol,
24
22
  };
@@ -37,4 +35,3 @@ async function default_1(files, options, selectors) {
37
35
  process.stdout.write(`${loc.file}:${loc.line}:${loc.col}\n`);
38
36
  });
39
37
  }
40
- exports.default = default_1;
package/lib/debug.js CHANGED
@@ -1,15 +1,10 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.verbosely = exports.log = void 0;
4
- const tslib_1 = require("tslib");
5
- const ml_core_1 = require("@markuplint/ml-core");
6
- const debug_1 = tslib_1.__importDefault(require("debug"));
7
- exports.log = (0, debug_1.default)('markuplint-cli');
8
- function verbosely() {
9
- if (!exports.log.enabled) {
10
- debug_1.default.enable(`${exports.log.namespace}*`);
11
- (0, exports.log)(`Debug enable: ${exports.log.namespace}`);
1
+ import { enableDebug } from '@markuplint/ml-core';
2
+ import debug from 'debug';
3
+ export const log = debug('markuplint-cli');
4
+ export function verbosely() {
5
+ if (!log.enabled) {
6
+ debug.enable(`${log.namespace}*`);
7
+ log(`Debug enable: ${log.namespace}`);
12
8
  }
13
- (0, ml_core_1.enableDebug)();
9
+ enableDebug();
14
10
  }
15
- exports.verbosely = verbosely;
@@ -0,0 +1 @@
1
+ export declare function getJsonModule<T extends {}>(modulePath: string): T | null;
@@ -0,0 +1,10 @@
1
+ import { createRequire } from 'node:module';
2
+ const require = createRequire(import.meta.url);
3
+ export function getJsonModule(modulePath) {
4
+ try {
5
+ return require(modulePath);
6
+ }
7
+ catch (_) {
8
+ return null;
9
+ }
10
+ }
@@ -1,5 +1,5 @@
1
1
  export type GlobalSettings = {
2
- locale: string;
2
+ readonly locale: string;
3
3
  };
4
4
  export declare function setGlobal(settings: Partial<GlobalSettings>): void;
5
5
  export declare function getGlobal(): Readonly<Partial<GlobalSettings>>;
@@ -1,15 +1,10 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getGlobal = exports.setGlobal = void 0;
4
1
  let globalSettings = {};
5
- function setGlobal(settings) {
2
+ export function setGlobal(settings) {
6
3
  globalSettings = {
7
4
  ...globalSettings,
8
5
  ...settings,
9
6
  };
10
7
  }
11
- exports.setGlobal = setGlobal;
12
- function getGlobal() {
8
+ export function getGlobal() {
13
9
  return globalSettings;
14
10
  }
15
- exports.getGlobal = getGlobal;
package/lib/i18n.js CHANGED
@@ -1,25 +1,19 @@
1
- "use strict";
2
- var _a;
3
- Object.defineProperty(exports, "__esModule", { value: true });
4
- exports.i18n = void 0;
5
- const tslib_1 = require("tslib");
6
- const os_locale_1 = tslib_1.__importDefault(require("os-locale"));
1
+ import { osLocale } from 'os-locale';
2
+ import { getJsonModule } from './get-json-module.js';
7
3
  let cachedLocale = null;
8
4
  async function getLocale() {
9
5
  if (!cachedLocale) {
10
- cachedLocale = await (0, os_locale_1.default)({ spawn: true });
6
+ cachedLocale = await osLocale({ spawn: true });
11
7
  }
12
8
  return cachedLocale;
13
9
  }
14
- async function i18n(locale) {
15
- locale = locale || (await getLocale()) || 'en';
16
- const langCode = locale.split('-')[0];
17
- const localeSet = langCode
18
- ? await (_a = `@markuplint/i18n/locales/${langCode}`, Promise.resolve().then(() => tslib_1.__importStar(require(_a)))).catch(() => null)
19
- : null;
10
+ export async function i18n(locale) {
11
+ locale = locale ?? (await getLocale()) ?? 'en';
12
+ const langCode = locale.split('-')[0] ?? locale;
13
+ const loadLocaleSet = getJsonModule(`@markuplint/i18n/locales/${langCode}.json`);
14
+ const localeSet = loadLocaleSet ?? getJsonModule('@markuplint/i18n/locales/en.json');
20
15
  return {
21
- locale: langCode,
22
16
  ...localeSet,
17
+ locale: loadLocaleSet ? langCode : 'en',
23
18
  };
24
19
  }
25
- exports.i18n = i18n;
package/lib/index.d.ts CHANGED
@@ -1,8 +1,10 @@
1
- export { MLEngine } from './api';
2
- export * from './i18n';
3
- export * from './testing-tool';
4
- export * from './types';
1
+ export { MLEngine, FromCodeOptions } from './api/index.js';
2
+ export { MLEngineEventMap } from './api/types.js';
3
+ export * from './i18n.js';
4
+ export * from './testing-tool/index.js';
5
+ export * from './types.js';
6
+ export { version } from './version.js';
5
7
  /**
6
8
  * @deprecated
7
9
  */
8
- export * from './v1';
10
+ export * from './v1.js';
package/lib/index.js CHANGED
@@ -1,13 +1,9 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.MLEngine = void 0;
4
- const tslib_1 = require("tslib");
5
- var api_1 = require("./api");
6
- Object.defineProperty(exports, "MLEngine", { enumerable: true, get: function () { return api_1.MLEngine; } });
7
- tslib_1.__exportStar(require("./i18n"), exports);
8
- tslib_1.__exportStar(require("./testing-tool"), exports);
9
- tslib_1.__exportStar(require("./types"), exports);
1
+ export { MLEngine } from './api/index.js';
2
+ export * from './i18n.js';
3
+ export * from './testing-tool/index.js';
4
+ export * from './types.js';
5
+ export { version } from './version.js';
10
6
  /**
11
7
  * @deprecated
12
8
  */
13
- tslib_1.__exportStar(require("./v1"), exports);
9
+ export * from './v1.js';
@@ -0,0 +1,2 @@
1
+ import type { MLResultInfo } from '../types.js';
2
+ export declare function githubReporter(results: MLResultInfo): string[];
@@ -0,0 +1,19 @@
1
+ import { messageToString } from '../util.js';
2
+ export function githubReporter(results) {
3
+ const out = [];
4
+ for (const violation of results.violations) {
5
+ const command = severityToCommand(violation.severity);
6
+ const meg = messageToString(violation.message, violation.reason);
7
+ out.push(`::${command} file=${results.filePath},line=${violation.line},col=${violation.col}::${meg} (${violation.ruleId})`);
8
+ }
9
+ return out;
10
+ }
11
+ function severityToCommand(severity) {
12
+ switch (severity) {
13
+ case 'info':
14
+ return 'notice';
15
+ case 'error':
16
+ case 'warning':
17
+ return severity;
18
+ }
19
+ }
@@ -1,2 +1,3 @@
1
- export * from './standard-reporter';
2
- export * from './simple-reporter';
1
+ export * from './standard-reporter.js';
2
+ export * from './simple-reporter.js';
3
+ export * from './github-reporter.js';
@@ -1,5 +1,3 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const tslib_1 = require("tslib");
4
- tslib_1.__exportStar(require("./standard-reporter"), exports);
5
- tslib_1.__exportStar(require("./simple-reporter"), exports);
1
+ export * from './standard-reporter.js';
2
+ export * from './simple-reporter.js';
3
+ export * from './github-reporter.js';
@@ -1,3 +1,3 @@
1
- import type { CLIOptions } from '../cli/bootstrap';
2
- import type { MLResultInfo } from '../types';
1
+ import type { CLIOptions } from '../cli/bootstrap.js';
2
+ import type { MLResultInfo } from '../types.js';
3
3
  export declare function simpleReporter(results: MLResultInfo, options: CLIOptions): string[];
@@ -1,12 +1,8 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.simpleReporter = void 0;
4
- const tslib_1 = require("tslib");
5
- const cli_color_1 = tslib_1.__importDefault(require("cli-color"));
6
- const util_1 = require("../util");
7
- const loggerError = cli_color_1.default.red;
8
- const loggerWarning = cli_color_1.default.xterm(208);
9
- function simpleReporter(results, options) {
1
+ import c from 'cli-color';
2
+ import { markuplint, messageToString, p, w } from '../util.js';
3
+ const loggerError = c.red;
4
+ const loggerWarning = c.xterm(208);
5
+ export function simpleReporter(results, options) {
10
6
  const sizes = {
11
7
  line: 0,
12
8
  col: 0,
@@ -15,21 +11,20 @@ function simpleReporter(results, options) {
15
11
  for (const violation of results.violations) {
16
12
  sizes.line = Math.max(sizes.line, violation.line.toString(10).length);
17
13
  sizes.col = Math.max(sizes.col, violation.col.toString(10).length);
18
- const meg = (0, util_1.messageToString)(violation.message, violation.reason);
19
- sizes.meg = Math.max(sizes.meg, (0, util_1.w)(meg));
14
+ const meg = messageToString(violation.message, violation.reason);
15
+ sizes.meg = Math.max(sizes.meg, w(meg));
20
16
  }
21
17
  const out = [];
22
- if (results.violations.length) {
23
- out.push(`<${util_1.markuplint}> ${cli_color_1.default.underline(results.filePath)}: ${loggerError('✗')}`);
18
+ if (results.violations.length > 0) {
19
+ out.push(`<${markuplint}> ${c.underline(results.filePath)}: ${loggerError('✗')}`);
24
20
  for (const violation of results.violations) {
25
21
  const s = violation.severity === 'error' ? loggerError('✖') : loggerWarning('⚠️');
26
- const meg = (0, util_1.messageToString)(violation.message, violation.reason);
27
- out.push(` ${cli_color_1.default.cyan(`${(0, util_1.p)(violation.line, sizes.line, true)}:${(0, util_1.p)(violation.col, sizes.col)}`)} ${s} ${(0, util_1.p)(meg, sizes.meg)} ${cli_color_1.default.xterm(8)(violation.ruleId)} `);
22
+ const meg = messageToString(violation.message, violation.reason);
23
+ out.push(` ${c.cyan(`${p(violation.line, sizes.line, true)}:${p(violation.col, sizes.col)}`)} ${s} ${p(meg, sizes.meg)} ${c.xterm(8)(violation.ruleId)} `);
28
24
  }
29
25
  }
30
26
  else if (!options.problemOnly) {
31
- out.push(`<${util_1.markuplint}> ${cli_color_1.default.underline(results.filePath)}: ${cli_color_1.default.green('✓')}`);
27
+ out.push(`<${markuplint}> ${c.underline(results.filePath)}: ${c.green('✓')}`);
32
28
  }
33
29
  return out;
34
30
  }
35
- exports.simpleReporter = simpleReporter;
@@ -1,3 +1,3 @@
1
- import type { CLIOptions } from '../cli/bootstrap';
2
- import type { MLResultInfo } from '../types';
1
+ import type { CLIOptions } from '../cli/bootstrap.js';
2
+ import type { MLResultInfo } from '../types.js';
3
3
  export declare function standardReporter(results: MLResultInfo, options: CLIOptions): string[];
@@ -1,12 +1,8 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.standardReporter = void 0;
4
- const tslib_1 = require("tslib");
5
- const cli_color_1 = tslib_1.__importDefault(require("cli-color"));
6
- const util_1 = require("../util");
7
- const loggerError = cli_color_1.default.red;
8
- const loggerWarning = cli_color_1.default.xterm(208);
9
- function standardReporter(results, options) {
1
+ import c from 'cli-color';
2
+ import { invisibleSpace, markuplint, messageToString, p, space, w } from '../util.js';
3
+ const loggerError = c.red;
4
+ const loggerWarning = c.xterm(208);
5
+ export function standardReporter(results, options) {
10
6
  const sizes = {
11
7
  line: 0,
12
8
  col: 0,
@@ -15,34 +11,33 @@ function standardReporter(results, options) {
15
11
  for (const violation of results.violations) {
16
12
  sizes.line = Math.max(sizes.line, violation.line.toString(10).length);
17
13
  sizes.col = Math.max(sizes.col, violation.col.toString(10).length);
18
- const meg = (0, util_1.messageToString)(violation.message, violation.reason);
19
- sizes.meg = Math.max(sizes.meg, (0, util_1.w)(meg));
14
+ const meg = messageToString(violation.message, violation.reason);
15
+ sizes.meg = Math.max(sizes.meg, w(meg));
20
16
  }
21
17
  const out = [];
22
- if (results.violations.length) {
18
+ if (results.violations.length > 0) {
23
19
  const lines = results.sourceCode.split(/\r?\n/g);
24
20
  for (const violation of results.violations) {
25
- const prev = lines[violation.line - 2] || '';
26
- const line = lines[violation.line - 1] || '';
27
- const next = lines[violation.line - 0] || '';
21
+ const prev = lines[violation.line - 2] ?? '';
22
+ const line = lines[violation.line - 1] ?? '';
23
+ const next = lines[violation.line - 0] ?? '';
28
24
  const before = line.substring(0, violation.col - 1);
29
25
  const after = line.substring(violation.col - 1 + violation.raw.length);
30
26
  const logger = violation.severity === 'error' ? loggerError : loggerWarning;
31
- const meg = (0, util_1.messageToString)(violation.message, violation.reason);
32
- out.push(`<${util_1.markuplint}> ${logger(`${violation.severity}: ${meg} (${violation.ruleId}) ${cli_color_1.default.underline(`${results.filePath}:${violation.line}:${violation.col}`)}`)}`);
27
+ const meg = messageToString(violation.message, violation.reason);
28
+ out.push(`<${markuplint}> ${logger(`${violation.severity}: ${meg} (${violation.ruleId}) ${c.underline(`${results.filePath}:${violation.line}:${violation.col}`)}`)}`);
33
29
  if (violation.line - 1 > 0) {
34
- out.push(` ${cli_color_1.default.cyan((0, util_1.p)(violation.line - 1, sizes.col, true))}: ${(0, util_1.space)(prev)}`);
30
+ out.push(` ${c.cyan(p(violation.line - 1, sizes.col, true))}: ${space(prev)}`);
35
31
  }
36
- out.push(` ${cli_color_1.default.cyan((0, util_1.p)(violation.line, sizes.col, true))}: ${(0, util_1.space)(before)}${cli_color_1.default.bgRed(violation.raw)}${(0, util_1.space)(after)}`);
32
+ out.push(` ${c.cyan(p(violation.line, sizes.col, true))}: ${space(before)}${c.bgRed(violation.raw)}${space(after)}`);
37
33
  if (!options.color) {
38
- out.push(` ${(0, util_1.invisibleSpace)(before)}${'^'.repeat(violation.raw.length)}${(0, util_1.invisibleSpace)(after)}`);
34
+ out.push(` ${invisibleSpace(before)}${'^'.repeat(violation.raw.length)}${invisibleSpace(after)}`);
39
35
  }
40
- out.push(` ${cli_color_1.default.cyan((0, util_1.p)(violation.line + 1, sizes.col, true))}: ${(0, util_1.space)(next)}`);
36
+ out.push(` ${c.cyan(p(violation.line + 1, sizes.col, true))}: ${space(next)}`);
41
37
  }
42
38
  }
43
39
  else if (!options.problemOnly) {
44
- out.push(`<${util_1.markuplint}> ${cli_color_1.default.green('passed')} ${cli_color_1.default.underline(results.filePath)}`);
40
+ out.push(`<${markuplint}> ${c.green('passed')} ${c.underline(results.filePath)}`);
45
41
  }
46
42
  return out;
47
43
  }
48
- exports.standardReporter = standardReporter;
@@ -1,23 +1,23 @@
1
1
  import type { Target } from '@markuplint/file-resolver';
2
- import type { Config, RuleConfigValue, Rule, RegexSelector } from '@markuplint/ml-config';
2
+ import type { Config, RuleConfigValue, Rule, RegexSelector, PlainData } from '@markuplint/ml-config';
3
3
  import type { AnyMLRule, RuleSeed } from '@markuplint/ml-core';
4
- export declare function mlTest(sourceCode: string, config: Config, rules?: AnyMLRule[], locale?: string, fix?: boolean): Promise<{
5
- violations: import("@markuplint/ml-config").Violation[];
4
+ export declare function mlTest(sourceCode: string, config: Config, rules?: readonly Readonly<AnyMLRule>[], locale?: string, fix?: boolean): Promise<{
5
+ violations: readonly import("@markuplint/ml-config").Violation[];
6
6
  fixedCode: string;
7
7
  }>;
8
- export declare function mlRuleTest<T extends RuleConfigValue, O = null>(rule: RuleSeed<T, O>, sourceCode: string, config?: Omit<Config, 'rules' | 'nodeRules' | 'childNodeRules'> & {
8
+ export declare function mlRuleTest<T extends RuleConfigValue, O extends PlainData>(rule: Readonly<RuleSeed<T, O>>, sourceCode: string, config?: Omit<Config, 'rules' | 'nodeRules' | 'childNodeRules'> & {
9
9
  rule?: Rule<T, Partial<O>>;
10
10
  nodeRule?: NodeRule<T, Partial<O>>[];
11
11
  childNodeRule?: ChildNodeRule<T, Partial<O>>[];
12
12
  }, fix?: boolean, locale?: string): Promise<{
13
- violations: import("@markuplint/ml-config").Violation[];
13
+ violations: readonly import("@markuplint/ml-config").Violation[];
14
14
  fixedCode: string;
15
15
  }>;
16
- export declare function mlTestFile(target: Target, config?: Config, rules?: AnyMLRule[], locale?: string, fix?: boolean): Promise<{
17
- violations: import("@markuplint/ml-config").Violation[];
18
- fixedCode: string;
16
+ export declare function mlTestFile(target: Target, config?: Config, rules?: readonly Readonly<AnyMLRule>[], locale?: string, fix?: boolean): Promise<{
17
+ violations: readonly import("@markuplint/ml-config").Violation[];
18
+ fixedCode: string | undefined;
19
19
  }>;
20
- export interface NodeRule<T extends RuleConfigValue, O = void> {
20
+ export interface NodeRule<T extends RuleConfigValue, O extends PlainData = undefined> {
21
21
  selector?: string;
22
22
  regexSelector?: RegexSelector;
23
23
  categories?: string[];
@@ -25,7 +25,7 @@ export interface NodeRule<T extends RuleConfigValue, O = void> {
25
25
  obsolete?: boolean;
26
26
  rule?: Rule<T, O>;
27
27
  }
28
- export interface ChildNodeRule<T extends RuleConfigValue, O = void> {
28
+ export interface ChildNodeRule<T extends RuleConfigValue, O extends PlainData = undefined> {
29
29
  selector?: string;
30
30
  regexSelector?: RegexSelector;
31
31
  inheritance?: boolean;
@@ -1,16 +1,12 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.mlTestFile = exports.mlRuleTest = exports.mlTest = void 0;
4
- const ml_core_1 = require("@markuplint/ml-core");
5
- const api_1 = require("../api");
6
- const global_settings_1 = require("../global-settings");
7
- async function mlTest(sourceCode, config, rules, locale = 'en', fix = false) {
8
- var _a, _b;
9
- const global = (0, global_settings_1.getGlobal)();
10
- const results = await (0, api_1.lint)([{ sourceCode }], {
1
+ import { MLRule } from '@markuplint/ml-core';
2
+ import { lint } from '../api/index.js';
3
+ import { getGlobal } from '../global-settings.js';
4
+ export async function mlTest(sourceCode, config, rules, locale = 'en', fix = false) {
5
+ const global = getGlobal();
6
+ const results = await lint([{ sourceCode }], {
11
7
  config,
12
8
  rules,
13
- locale: locale !== null && locale !== void 0 ? locale : global.locale,
9
+ locale: locale ?? global.locale,
14
10
  fix,
15
11
  ignoreExt: true,
16
12
  autoLoad: true,
@@ -18,12 +14,11 @@ async function mlTest(sourceCode, config, rules, locale = 'en', fix = false) {
18
14
  });
19
15
  const result = results[0];
20
16
  return {
21
- violations: (_a = result === null || result === void 0 ? void 0 : result.violations) !== null && _a !== void 0 ? _a : [],
22
- fixedCode: (_b = result === null || result === void 0 ? void 0 : result.fixedCode) !== null && _b !== void 0 ? _b : sourceCode,
17
+ violations: result?.violations ?? [],
18
+ fixedCode: result?.fixedCode ?? sourceCode,
23
19
  };
24
20
  }
25
- exports.mlTest = mlTest;
26
- async function mlRuleTest(rule, sourceCode, config = { rule: true }, fix = false, locale = 'en') {
21
+ export async function mlRuleTest(rule, sourceCode, config = { rule: true }, fix = false, locale = 'en') {
27
22
  const _config = {
28
23
  ...config,
29
24
  rules: config.rule !== undefined
@@ -57,7 +52,7 @@ async function mlRuleTest(rule, sourceCode, config = { rule: true }, fix = false
57
52
  : undefined,
58
53
  };
59
54
  const res = await mlTest(sourceCode, _config, [
60
- new ml_core_1.MLRule({
55
+ new MLRule({
61
56
  name: '<current-rule>',
62
57
  ...rule,
63
58
  }),
@@ -68,14 +63,12 @@ async function mlRuleTest(rule, sourceCode, config = { rule: true }, fix = false
68
63
  });
69
64
  return res;
70
65
  }
71
- exports.mlRuleTest = mlRuleTest;
72
- async function mlTestFile(target, config, rules, locale, fix = false) {
73
- var _a, _b;
74
- const global = (0, global_settings_1.getGlobal)();
75
- const results = await (0, api_1.lint)([target], {
66
+ export async function mlTestFile(target, config, rules, locale, fix = false) {
67
+ const global = getGlobal();
68
+ const results = await lint([target], {
76
69
  config,
77
70
  rules,
78
- locale: locale !== null && locale !== void 0 ? locale : global.locale,
71
+ locale: locale ?? global.locale,
79
72
  fix,
80
73
  ignoreExt: true,
81
74
  noSearchConfig: !!config,
@@ -84,8 +77,7 @@ async function mlTestFile(target, config, rules, locale, fix = false) {
84
77
  });
85
78
  const result = results[0];
86
79
  return {
87
- violations: (_a = result === null || result === void 0 ? void 0 : result.violations) !== null && _a !== void 0 ? _a : [],
88
- fixedCode: (_b = result === null || result === void 0 ? void 0 : result.fixedCode) !== null && _b !== void 0 ? _b : result === null || result === void 0 ? void 0 : result.sourceCode,
80
+ violations: result?.violations ?? [],
81
+ fixedCode: result?.fixedCode ?? result?.sourceCode,
89
82
  };
90
83
  }
91
- exports.mlTestFile = mlTestFile;
package/lib/types.d.ts CHANGED
@@ -1,10 +1,10 @@
1
- import type { Config, Violation } from '@markuplint/ml-config';
1
+ import type { Config, PlainData, RuleConfigValue, Violation } from '@markuplint/ml-config';
2
2
  import type { Document, Ruleset } from '@markuplint/ml-core';
3
3
  export interface MLResultInfo {
4
- violations: Violation[];
5
- filePath: string;
6
- sourceCode: string;
7
- fixedCode: string;
4
+ readonly violations: readonly Violation[];
5
+ readonly filePath: string;
6
+ readonly sourceCode: string;
7
+ readonly fixedCode: string;
8
8
  }
9
9
  /**
10
10
  * @deprecated
@@ -14,7 +14,7 @@ export interface MLResultInfo_v1 {
14
14
  filePath: string;
15
15
  sourceCode: string;
16
16
  fixedCode: string;
17
- document: Document<any, unknown> | null;
17
+ document: Document<RuleConfigValue, PlainData> | null;
18
18
  parser: string;
19
19
  locale?: string;
20
20
  ruleset: Ruleset;
@@ -24,4 +24,3 @@ export interface MLResultInfo_v1 {
24
24
  error: string[];
25
25
  };
26
26
  }
27
- export type Nullable<T> = T | null | undefined;
package/lib/types.js CHANGED
@@ -1,2 +1 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
1
+ export {};
package/lib/util.d.ts CHANGED
@@ -1,5 +1,3 @@
1
- import type { Nullable } from './types';
2
- export declare function nonNullableFilter<T>(item: Nullable<T>): item is T;
3
1
  export declare function uuid(): string;
4
2
  export declare const markuplint: string;
5
3
  export declare function write(message: string): void;