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.
- package/README.md +10 -6
- package/bin/markuplint.mjs +3 -0
- package/lib/api/index.d.ts +2 -2
- package/lib/api/index.js +2 -10
- package/lib/api/lint.d.ts +3 -3
- package/lib/api/lint.js +5 -10
- package/lib/api/ml-engine.d.ts +15 -9
- package/lib/api/ml-engine.js +135 -102
- package/lib/api/types.d.ts +30 -34
- package/lib/api/types.js +1 -2
- package/lib/api/v1.d.ts +12 -12
- package/lib/api/v1.js +13 -24
- package/lib/cli/bootstrap.d.ts +15 -7
- package/lib/cli/bootstrap.js +19 -11
- package/lib/cli/command.d.ts +3 -3
- package/lib/cli/command.js +27 -26
- package/lib/cli/create-rule/index.js +56 -42
- package/lib/cli/index.js +27 -31
- package/lib/cli/init/create-config.d.ts +4 -0
- package/lib/cli/init/create-config.js +90 -0
- package/lib/cli/init/get-default-rules.d.ts +3 -0
- package/lib/cli/init/get-default-rules.js +52 -0
- package/lib/cli/init/index.js +43 -231
- package/lib/cli/init/install-module.d.ts +3 -1
- package/lib/cli/init/install-module.js +22 -17
- package/lib/cli/init/types.d.ts +8 -0
- package/lib/cli/init/types.js +1 -0
- package/lib/cli/output.d.ts +2 -2
- package/lib/cli/output.js +13 -15
- package/lib/cli/prompt.d.ts +9 -9
- package/lib/cli/prompt.js +15 -25
- package/lib/cli/search/index.d.ts +2 -2
- package/lib/cli/search/index.js +7 -10
- package/lib/debug.js +8 -13
- package/lib/get-json-module.d.ts +1 -0
- package/lib/get-json-module.js +10 -0
- package/lib/global-settings.d.ts +1 -1
- package/lib/global-settings.js +2 -7
- package/lib/i18n.js +9 -15
- package/lib/index.d.ts +7 -5
- package/lib/index.js +6 -10
- package/lib/reporter/github-reporter.d.ts +2 -0
- package/lib/reporter/github-reporter.js +19 -0
- package/lib/reporter/index.d.ts +3 -2
- package/lib/reporter/index.js +3 -5
- package/lib/reporter/simple-reporter.d.ts +2 -2
- package/lib/reporter/simple-reporter.js +12 -17
- package/lib/reporter/standard-reporter.d.ts +2 -2
- package/lib/reporter/standard-reporter.js +18 -23
- package/lib/testing-tool/index.d.ts +10 -10
- package/lib/testing-tool/index.js +17 -25
- package/lib/types.d.ts +6 -7
- package/lib/types.js +1 -2
- package/lib/util.d.ts +0 -2
- package/lib/util.js +21 -37
- package/lib/v1.d.ts +1 -1
- package/lib/v1.js +1 -5
- package/lib/version.d.ts +1 -0
- package/lib/version.js +3 -0
- package/package.json +43 -31
- package/bin/markuplint +0 -3
- package/media/screenshot01.png +0 -0
- package/test/plugin001.js +0 -24
- package/tsconfig.test.json +0 -3
- package/tsconfig.tsbuildinfo +0 -1
package/lib/cli/prompt.js
CHANGED
|
@@ -1,26 +1,20 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const
|
|
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
|
|
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
|
-
|
|
22
|
-
|
|
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
|
-
|
|
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
|
|
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(
|
|
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
|
-
|
|
57
|
-
|
|
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: !!
|
|
54
|
+
initial: !!options?.initial,
|
|
63
55
|
});
|
|
64
56
|
// @ts-ignore
|
|
65
57
|
return !!res['__Q__'];
|
|
66
58
|
}
|
|
67
|
-
|
|
68
|
-
|
|
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>;
|
package/lib/cli/search/index.js
CHANGED
|
@@ -1,24 +1,22 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
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
|
|
6
|
+
await command(files, {
|
|
9
7
|
...options,
|
|
10
8
|
problemOnly: true,
|
|
11
9
|
importPresetRules: false,
|
|
12
10
|
}, {
|
|
13
11
|
rules: [
|
|
14
|
-
new
|
|
12
|
+
new MLRule({
|
|
15
13
|
name,
|
|
16
|
-
...
|
|
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
|
|
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
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
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
|
-
|
|
9
|
+
enableDebug();
|
|
14
10
|
}
|
|
15
|
-
exports.verbosely = verbosely;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function getJsonModule<T extends {}>(modulePath: string): T | null;
|
package/lib/global-settings.d.ts
CHANGED
package/lib/global-settings.js
CHANGED
|
@@ -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
|
-
|
|
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
|
-
|
|
2
|
-
|
|
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 (
|
|
6
|
+
cachedLocale = await osLocale({ spawn: true });
|
|
11
7
|
}
|
|
12
8
|
return cachedLocale;
|
|
13
9
|
}
|
|
14
|
-
async function i18n(locale) {
|
|
15
|
-
locale = locale
|
|
16
|
-
const langCode = locale.split('-')[0];
|
|
17
|
-
const
|
|
18
|
-
|
|
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
|
|
3
|
-
export * from './
|
|
4
|
-
export * from './
|
|
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
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
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
|
-
|
|
9
|
+
export * from './v1.js';
|
|
@@ -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
|
+
}
|
package/lib/reporter/index.d.ts
CHANGED
|
@@ -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';
|
package/lib/reporter/index.js
CHANGED
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
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
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const
|
|
5
|
-
|
|
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 =
|
|
19
|
-
sizes.meg = Math.max(sizes.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(`<${
|
|
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 =
|
|
27
|
-
out.push(` ${
|
|
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(`<${
|
|
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
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const
|
|
5
|
-
|
|
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 =
|
|
19
|
-
sizes.meg = Math.max(sizes.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 =
|
|
32
|
-
out.push(`<${
|
|
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(` ${
|
|
30
|
+
out.push(` ${c.cyan(p(violation.line - 1, sizes.col, true))}: ${space(prev)}`);
|
|
35
31
|
}
|
|
36
|
-
out.push(` ${
|
|
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(` ${
|
|
34
|
+
out.push(` ${invisibleSpace(before)}${'^'.repeat(violation.raw.length)}${invisibleSpace(after)}`);
|
|
39
35
|
}
|
|
40
|
-
out.push(` ${
|
|
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(`<${
|
|
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
|
|
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 =
|
|
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 =
|
|
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
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
const
|
|
6
|
-
const
|
|
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
|
|
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:
|
|
22
|
-
fixedCode:
|
|
17
|
+
violations: result?.violations ?? [],
|
|
18
|
+
fixedCode: result?.fixedCode ?? sourceCode,
|
|
23
19
|
};
|
|
24
20
|
}
|
|
25
|
-
|
|
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
|
|
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
|
-
|
|
72
|
-
|
|
73
|
-
|
|
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
|
|
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:
|
|
88
|
-
fixedCode:
|
|
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<
|
|
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
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
1
|
+
export {};
|
package/lib/util.d.ts
CHANGED