markuplint 3.13.0 → 4.0.0-alpha.2
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/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 +2 -2
- package/lib/api/lint.js +5 -10
- package/lib/api/ml-engine.d.ts +7 -2
- package/lib/api/ml-engine.js +99 -99
- package/lib/api/types.js +1 -2
- package/lib/api/v1.d.ts +1 -1
- package/lib/api/v1.js +12 -20
- package/lib/cli/bootstrap.d.ts +4 -5
- package/lib/cli/bootstrap.js +7 -10
- package/lib/cli/command.d.ts +2 -2
- package/lib/cli/command.js +19 -25
- package/lib/cli/create-rule/index.js +26 -32
- package/lib/cli/index.js +26 -29
- package/lib/cli/init/create-config.d.ts +1 -1
- package/lib/cli/init/create-config.js +3 -8
- package/lib/cli/init/get-default-rules.d.ts +1 -1
- package/lib/cli/init/get-default-rules.js +8 -13
- package/lib/cli/init/index.js +30 -34
- package/lib/cli/init/install-module.d.ts +1 -1
- package/lib/cli/init/install-module.js +12 -18
- package/lib/cli/init/types.js +1 -2
- package/lib/cli/output.d.ts +2 -2
- package/lib/cli/output.js +8 -14
- package/lib/cli/prompt.js +15 -25
- package/lib/cli/search/index.d.ts +1 -1
- package/lib/cli/search/index.js +7 -11
- 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.js +2 -7
- package/lib/i18n.js +8 -15
- package/lib/index.d.ts +6 -5
- package/lib/index.js +6 -10
- package/lib/reporter/github-reporter.d.ts +1 -1
- package/lib/reporter/github-reporter.js +3 -7
- package/lib/reporter/index.d.ts +3 -3
- package/lib/reporter/index.js +3 -6
- package/lib/reporter/simple-reporter.d.ts +2 -2
- package/lib/reporter/simple-reporter.js +11 -16
- package/lib/reporter/standard-reporter.d.ts +2 -2
- package/lib/reporter/standard-reporter.js +17 -23
- package/lib/testing-tool/index.js +17 -25
- package/lib/types.js +1 -2
- package/lib/util.js +21 -33
- 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 +34 -26
- package/bin/markuplint +0 -3
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';
|
|
1
|
+
import type { CLIOptions } from '../bootstrap.js';
|
|
2
2
|
export default function (files: readonly string[], options: CLIOptions, selectors: string): Promise<void>;
|
package/lib/cli/search/index.js
CHANGED
|
@@ -1,25 +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
|
-
var _a;
|
|
21
18
|
return {
|
|
22
|
-
file:
|
|
19
|
+
file: document.filename ?? '_NO_FILE_',
|
|
23
20
|
line: node.startLine,
|
|
24
21
|
col: node.startCol,
|
|
25
22
|
};
|
|
@@ -38,4 +35,3 @@ async function default_1(files, options, selectors) {
|
|
|
38
35
|
process.stdout.write(`${loc.file}:${loc.line}:${loc.col}\n`);
|
|
39
36
|
});
|
|
40
37
|
}
|
|
41
|
-
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.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,26 +1,19 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
exports.i18n = void 0;
|
|
4
|
-
const tslib_1 = require("tslib");
|
|
5
|
-
const os_locale_1 = tslib_1.__importDefault(require("os-locale"));
|
|
1
|
+
import { osLocale } from 'os-locale';
|
|
2
|
+
import { getJsonModule } from './get-json-module.js';
|
|
6
3
|
let cachedLocale = null;
|
|
7
4
|
async function getLocale() {
|
|
8
5
|
if (!cachedLocale) {
|
|
9
|
-
cachedLocale = await (
|
|
6
|
+
cachedLocale = await osLocale({ spawn: true });
|
|
10
7
|
}
|
|
11
8
|
return cachedLocale;
|
|
12
9
|
}
|
|
13
|
-
async function i18n(locale) {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
const
|
|
17
|
-
const
|
|
18
|
-
const localeSet = loadLocaleSet !== null && loadLocaleSet !== void 0 ? loadLocaleSet :
|
|
19
|
-
// @ts-ignore
|
|
20
|
-
(await Promise.resolve().then(() => tslib_1.__importStar(require('@markuplint/i18n/locales/en'))));
|
|
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');
|
|
21
15
|
return {
|
|
22
16
|
...localeSet,
|
|
23
17
|
locale: loadLocaleSet ? langCode : 'en',
|
|
24
18
|
};
|
|
25
19
|
}
|
|
26
|
-
exports.i18n = i18n;
|
package/lib/index.d.ts
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
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 * from './i18n.js';
|
|
3
|
+
export * from './testing-tool/index.js';
|
|
4
|
+
export * from './types.js';
|
|
5
|
+
export { version } from './version.js';
|
|
5
6
|
/**
|
|
6
7
|
* @deprecated
|
|
7
8
|
*/
|
|
8
|
-
export * from './v1';
|
|
9
|
+
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';
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import type { MLResultInfo } from '../types';
|
|
1
|
+
import type { MLResultInfo } from '../types.js';
|
|
2
2
|
export declare function githubReporter(results: MLResultInfo): string[];
|
|
@@ -1,17 +1,13 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
exports.githubReporter = void 0;
|
|
4
|
-
const util_1 = require("../util");
|
|
5
|
-
function githubReporter(results) {
|
|
1
|
+
import { messageToString } from '../util.js';
|
|
2
|
+
export function githubReporter(results) {
|
|
6
3
|
const out = [];
|
|
7
4
|
for (const violation of results.violations) {
|
|
8
5
|
const command = severityToCommand(violation.severity);
|
|
9
|
-
const meg =
|
|
6
|
+
const meg = messageToString(violation.message, violation.reason);
|
|
10
7
|
out.push(`::${command} file=${results.filePath},line=${violation.line},col=${violation.col}::${meg} (${violation.ruleId})`);
|
|
11
8
|
}
|
|
12
9
|
return out;
|
|
13
10
|
}
|
|
14
|
-
exports.githubReporter = githubReporter;
|
|
15
11
|
function severityToCommand(severity) {
|
|
16
12
|
switch (severity) {
|
|
17
13
|
case 'info':
|
package/lib/reporter/index.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export * from './standard-reporter';
|
|
2
|
-
export * from './simple-reporter';
|
|
3
|
-
export * from './github-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,6 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
tslib_1.__exportStar(require("./standard-reporter"), exports);
|
|
5
|
-
tslib_1.__exportStar(require("./simple-reporter"), exports);
|
|
6
|
-
tslib_1.__exportStar(require("./github-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
18
|
if (results.violations.length > 0) {
|
|
23
|
-
out.push(`<${
|
|
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,13 +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) {
|
|
10
|
-
var _a, _b, _c;
|
|
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) {
|
|
11
6
|
const sizes = {
|
|
12
7
|
line: 0,
|
|
13
8
|
col: 0,
|
|
@@ -16,34 +11,33 @@ function standardReporter(results, options) {
|
|
|
16
11
|
for (const violation of results.violations) {
|
|
17
12
|
sizes.line = Math.max(sizes.line, violation.line.toString(10).length);
|
|
18
13
|
sizes.col = Math.max(sizes.col, violation.col.toString(10).length);
|
|
19
|
-
const meg =
|
|
20
|
-
sizes.meg = Math.max(sizes.meg,
|
|
14
|
+
const meg = messageToString(violation.message, violation.reason);
|
|
15
|
+
sizes.meg = Math.max(sizes.meg, w(meg));
|
|
21
16
|
}
|
|
22
17
|
const out = [];
|
|
23
18
|
if (results.violations.length > 0) {
|
|
24
19
|
const lines = results.sourceCode.split(/\r?\n/g);
|
|
25
20
|
for (const violation of results.violations) {
|
|
26
|
-
const prev =
|
|
27
|
-
const line =
|
|
28
|
-
const next =
|
|
21
|
+
const prev = lines[violation.line - 2] ?? '';
|
|
22
|
+
const line = lines[violation.line - 1] ?? '';
|
|
23
|
+
const next = lines[violation.line - 0] ?? '';
|
|
29
24
|
const before = line.substring(0, violation.col - 1);
|
|
30
25
|
const after = line.substring(violation.col - 1 + violation.raw.length);
|
|
31
26
|
const logger = violation.severity === 'error' ? loggerError : loggerWarning;
|
|
32
|
-
const meg =
|
|
33
|
-
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}`)}`)}`);
|
|
34
29
|
if (violation.line - 1 > 0) {
|
|
35
|
-
out.push(` ${
|
|
30
|
+
out.push(` ${c.cyan(p(violation.line - 1, sizes.col, true))}: ${space(prev)}`);
|
|
36
31
|
}
|
|
37
|
-
out.push(` ${
|
|
32
|
+
out.push(` ${c.cyan(p(violation.line, sizes.col, true))}: ${space(before)}${c.bgRed(violation.raw)}${space(after)}`);
|
|
38
33
|
if (!options.color) {
|
|
39
|
-
out.push(` ${
|
|
34
|
+
out.push(` ${invisibleSpace(before)}${'^'.repeat(violation.raw.length)}${invisibleSpace(after)}`);
|
|
40
35
|
}
|
|
41
|
-
out.push(` ${
|
|
36
|
+
out.push(` ${c.cyan(p(violation.line + 1, sizes.col, true))}: ${space(next)}`);
|
|
42
37
|
}
|
|
43
38
|
}
|
|
44
39
|
else if (!options.problemOnly) {
|
|
45
|
-
out.push(`<${
|
|
40
|
+
out.push(`<${markuplint}> ${c.green('passed')} ${c.underline(results.filePath)}`);
|
|
46
41
|
}
|
|
47
42
|
return out;
|
|
48
43
|
}
|
|
49
|
-
exports.standardReporter = standardReporter;
|
|
@@ -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.js
CHANGED
|
@@ -1,2 +1 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
1
|
+
export {};
|
package/lib/util.js
CHANGED
|
@@ -1,32 +1,28 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
exports.messageToString = exports.invisibleSpace = exports.space = exports.w = exports.p = exports.head = exports.error = exports.write = exports.markuplint = exports.uuid = void 0;
|
|
4
|
-
const tslib_1 = require("tslib");
|
|
5
|
-
const cli_color_1 = tslib_1.__importDefault(require("cli-color"));
|
|
1
|
+
import module from 'node:module';
|
|
2
|
+
import c from 'cli-color';
|
|
6
3
|
// @ts-ignore
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
4
|
+
import eastasianwidth from 'eastasianwidth';
|
|
5
|
+
import stripAnsi from 'strip-ansi';
|
|
6
|
+
import { v4 } from 'uuid';
|
|
7
|
+
const require = module.createRequire(import.meta.url);
|
|
8
|
+
export function uuid() {
|
|
9
|
+
return v4();
|
|
12
10
|
}
|
|
13
|
-
exports.uuid = uuid;
|
|
14
11
|
/**
|
|
15
12
|
* Brand color (xTerm color)
|
|
16
13
|
*
|
|
17
14
|
* @see http://www.calmar.ws/vim/256-xterm-24bit-rgb-color-chart.html
|
|
18
15
|
*/
|
|
19
16
|
const PRIMARY_COLOR = 33;
|
|
20
|
-
const logo = `/${
|
|
21
|
-
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
17
|
+
const logo = `/${c.xterm(PRIMARY_COLOR)('✔')}\\`;
|
|
22
18
|
const version = require('../package.json').version;
|
|
23
|
-
const eaw =
|
|
19
|
+
const eaw = eastasianwidth;
|
|
24
20
|
const box = (lines, { width = 40, padding = 1, center = false, noColor = false }) => {
|
|
25
21
|
const bt = `┌${'─'.repeat(width - 2)}┐`;
|
|
26
22
|
const pd = `│${' '.repeat(width - 2)}│`;
|
|
27
23
|
const bb = `└${'─'.repeat(width - 2)}┘`;
|
|
28
24
|
const texts = lines.map(line => {
|
|
29
|
-
const nc = (
|
|
25
|
+
const nc = stripAnsi(line);
|
|
30
26
|
const length = nc.length;
|
|
31
27
|
const pad = width - 2 - 1 - length;
|
|
32
28
|
const pad2 = Math.floor(pad / 2);
|
|
@@ -39,50 +35,42 @@ const box = (lines, { width = 40, padding = 1, center = false, noColor = false }
|
|
|
39
35
|
const result = [bt, pd, ...texts, pd, bb];
|
|
40
36
|
return result.join('\n');
|
|
41
37
|
};
|
|
42
|
-
|
|
43
|
-
function write(message) {
|
|
38
|
+
export const markuplint = `markup${c.xterm(PRIMARY_COLOR)('lint')}`;
|
|
39
|
+
export function write(message) {
|
|
44
40
|
process.stdout.write(message + '\n');
|
|
45
41
|
}
|
|
46
|
-
exports.write = write;
|
|
47
42
|
write.break = () => process.stdout.write('\n');
|
|
48
|
-
function error(message) {
|
|
43
|
+
export function error(message) {
|
|
49
44
|
process.stderr.write(message + '\n');
|
|
50
45
|
}
|
|
51
|
-
exports.error = error;
|
|
52
46
|
error.exit = () => process.exit(1);
|
|
53
|
-
const head = (method, noColor) => box([`${logo} ${
|
|
47
|
+
export const head = (method, noColor) => box([`${logo} ${markuplint}`, c.blackBright(`v${version}`), '', c.bold(method)], {
|
|
54
48
|
center: true,
|
|
55
49
|
noColor,
|
|
56
50
|
});
|
|
57
|
-
|
|
58
|
-
function p(s, pad, start = false) {
|
|
51
|
+
export function p(s, pad, start = false) {
|
|
59
52
|
const l = w(`${s}`.trim());
|
|
60
53
|
const d = pad - l;
|
|
61
54
|
const _ = ' '.repeat(d < 0 ? 0 : d);
|
|
62
55
|
return start ? `${_}${s}` : `${s}${_}`;
|
|
63
56
|
}
|
|
64
|
-
|
|
65
|
-
function w(s) {
|
|
57
|
+
export function w(s) {
|
|
66
58
|
return s.replace(/./g, _ => '0'.repeat(eaw.characterLength(_))).length;
|
|
67
59
|
}
|
|
68
|
-
|
|
69
|
-
function space(str) {
|
|
60
|
+
export function space(str) {
|
|
70
61
|
return str
|
|
71
62
|
.replace(/\s+/g, $0 => {
|
|
72
|
-
return
|
|
63
|
+
return c.xterm(8)($0);
|
|
73
64
|
})
|
|
74
65
|
.replace(/ /g, $0 => '•')
|
|
75
66
|
.replace(/\t/g, $0 => '→ ');
|
|
76
67
|
}
|
|
77
|
-
|
|
78
|
-
function invisibleSpace(str) {
|
|
68
|
+
export function invisibleSpace(str) {
|
|
79
69
|
return str.replace(/\t/g, $0 => ' ').replace(/./g, $0 => ' ');
|
|
80
70
|
}
|
|
81
|
-
|
|
82
|
-
function messageToString(message, reason) {
|
|
71
|
+
export function messageToString(message, reason) {
|
|
83
72
|
if (!reason) {
|
|
84
73
|
return message;
|
|
85
74
|
}
|
|
86
75
|
return `${message} / ${reason}`;
|
|
87
76
|
}
|
|
88
|
-
exports.messageToString = messageToString;
|
package/lib/v1.d.ts
CHANGED