markuplint 2.0.0 → 2.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (66) hide show
  1. package/lib/api/index.d.mts +2 -0
  2. package/lib/api/index.mjs +2 -0
  3. package/lib/api/lint.d.mts +4 -0
  4. package/lib/api/lint.mjs +15 -0
  5. package/lib/api/ml-engine.d.mts +27 -0
  6. package/lib/api/ml-engine.d.ts +18 -18
  7. package/lib/api/ml-engine.mjs +232 -0
  8. package/lib/api/types.d.mts +43 -0
  9. package/lib/api/types.d.ts +32 -39
  10. package/lib/api/types.mjs +1 -0
  11. package/lib/api/v1.d.mts +51 -0
  12. package/lib/api/v1.d.ts +43 -43
  13. package/lib/api/v1.mjs +39 -0
  14. package/lib/cli/bootstrap.d.mts +52 -0
  15. package/lib/cli/bootstrap.d.ts +49 -50
  16. package/lib/cli/bootstrap.mjs +81 -0
  17. package/lib/cli/command.d.mts +3 -0
  18. package/lib/cli/command.mjs +50 -0
  19. package/lib/cli/create-rule/index.d.mts +1 -0
  20. package/lib/cli/create-rule/index.mjs +51 -0
  21. package/lib/cli/index.d.mts +1 -0
  22. package/lib/cli/index.mjs +64 -0
  23. package/lib/cli/index.spec.d.mts +1 -0
  24. package/lib/cli/index.spec.mjs +48 -0
  25. package/lib/cli/init/index.d.mts +1 -0
  26. package/lib/cli/init/index.mjs +266 -0
  27. package/lib/cli/init/install-module.d.mts +5 -0
  28. package/lib/cli/init/install-module.d.ts +2 -2
  29. package/lib/cli/init/install-module.mjs +61 -0
  30. package/lib/cli/output.d.mts +3 -0
  31. package/lib/cli/output.mjs +31 -0
  32. package/lib/cli/prompt.d.mts +18 -0
  33. package/lib/cli/prompt.d.ts +12 -17
  34. package/lib/cli/prompt.mjs +68 -0
  35. package/lib/debug.d.mts +3 -0
  36. package/lib/debug.mjs +10 -0
  37. package/lib/global-settings.d.mts +5 -0
  38. package/lib/global-settings.d.ts +1 -1
  39. package/lib/global-settings.mjs +10 -0
  40. package/lib/i18n.d.mts +6 -0
  41. package/lib/i18n.d.ts +4 -4
  42. package/lib/i18n.mjs +19 -0
  43. package/lib/index.d.mts +8 -0
  44. package/lib/index.mjs +8 -0
  45. package/lib/reporter/index.d.mts +2 -0
  46. package/lib/reporter/index.mjs +2 -0
  47. package/lib/reporter/simple-reporter.d.mts +3 -0
  48. package/lib/reporter/simple-reporter.mjs +30 -0
  49. package/lib/reporter/standard-reporter.d.mts +3 -0
  50. package/lib/reporter/standard-reporter.mjs +43 -0
  51. package/lib/testing-tool/index.d.mts +35 -0
  52. package/lib/testing-tool/index.d.ts +25 -43
  53. package/lib/testing-tool/index.mjs +83 -0
  54. package/lib/types.d.mts +27 -0
  55. package/lib/types.d.ts +17 -17
  56. package/lib/types.mjs +1 -0
  57. package/lib/util.d.mts +19 -0
  58. package/lib/util.d.ts +3 -3
  59. package/lib/util.mjs +73 -0
  60. package/lib/v1.d.mts +4 -0
  61. package/lib/v1.mjs +4 -0
  62. package/package.json +4 -4
  63. package/lib/cli/head.d.ts +0 -1
  64. package/lib/cli/head.js +0 -31
  65. package/lib/reporter/utils.d.ts +0 -6
  66. package/lib/reporter/utils.js +0 -40
@@ -0,0 +1,43 @@
1
+ import c from 'cli-color';
2
+ import { invisibleSpace, markuplint, messageToString, p, space, w } from '../util.mjs';
3
+ const loggerError = c.red;
4
+ const loggerWarning = c.xterm(208);
5
+ export function standardReporter(results, options) {
6
+ const sizes = {
7
+ line: 0,
8
+ col: 0,
9
+ meg: 0,
10
+ };
11
+ for (const violation of results.violations) {
12
+ sizes.line = Math.max(sizes.line, violation.line.toString(10).length);
13
+ sizes.col = Math.max(sizes.col, violation.col.toString(10).length);
14
+ const meg = messageToString(violation.message, violation.reason);
15
+ sizes.meg = Math.max(sizes.meg, w(meg));
16
+ }
17
+ const out = [];
18
+ if (results.violations.length) {
19
+ const lines = results.sourceCode.split(/\r?\n/g);
20
+ for (const violation of results.violations) {
21
+ const prev = lines[violation.line - 2] || '';
22
+ const line = lines[violation.line - 1] || '';
23
+ const next = lines[violation.line - 0] || '';
24
+ const before = line.substring(0, violation.col - 1);
25
+ const after = line.substring(violation.col - 1 + violation.raw.length);
26
+ const logger = violation.severity === 'error' ? loggerError : loggerWarning;
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}`)}`)}`);
29
+ if (violation.line - 1 > 0) {
30
+ out.push(` ${c.cyan(p(violation.line - 1, sizes.col, true))}: ${space(prev)}`);
31
+ }
32
+ out.push(` ${c.cyan(p(violation.line, sizes.col, true))}: ${space(before)}${c.bgRed(violation.raw)}${space(after)}`);
33
+ if (!options.color) {
34
+ out.push(` ${invisibleSpace(before)}${'^'.repeat(violation.raw.length)}${invisibleSpace(after)}`);
35
+ }
36
+ out.push(` ${c.cyan(p(violation.line + 1, sizes.col, true))}: ${space(next)}`);
37
+ }
38
+ }
39
+ else if (!options.problemOnly) {
40
+ out.push(`<${markuplint}> ${c.green('passed')} ${c.underline(results.filePath)}`);
41
+ }
42
+ return out;
43
+ }
@@ -0,0 +1,35 @@
1
+ import type { Target } from '@markuplint/file-resolver';
2
+ import type { Config, RuleConfigValue, Rule, RegexSelector } from '@markuplint/ml-config';
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[];
6
+ fixedCode: string;
7
+ }>;
8
+ export declare function mlRuleTest<T extends RuleConfigValue, O = null>(rule: RuleSeed<T, O>, sourceCode: string, config?: Omit<Config, 'rules' | 'nodeRules' | 'childNodeRules'> & {
9
+ rule?: Rule<T, O>;
10
+ nodeRule?: NodeRule<T, O>[];
11
+ childNodeRule?: ChildNodeRule<T, O>[];
12
+ }, fix?: boolean, locale?: string): Promise<{
13
+ violations: import("@markuplint/ml-config").Violation[];
14
+ fixedCode: string;
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;
19
+ }>;
20
+ export interface NodeRule<T extends RuleConfigValue, O = void> {
21
+ tagName?: string;
22
+ selector?: string;
23
+ regexSelector?: RegexSelector;
24
+ categories?: string[];
25
+ roles?: string[];
26
+ obsolete?: boolean;
27
+ rule?: Rule<T, O>;
28
+ }
29
+ export interface ChildNodeRule<T extends RuleConfigValue, O = void> {
30
+ tagName?: string;
31
+ selector?: string;
32
+ regexSelector?: RegexSelector;
33
+ inheritance?: boolean;
34
+ rule?: Rule<T, O>;
35
+ }
@@ -1,53 +1,35 @@
1
1
  import type { Target } from '@markuplint/file-resolver';
2
2
  import type { Config, RuleConfigValue, Rule, RegexSelector } from '@markuplint/ml-config';
3
3
  import type { AnyMLRule, RuleSeed } from '@markuplint/ml-core';
4
- export declare function mlTest(
5
- sourceCode: string,
6
- config: Config,
7
- rules?: AnyMLRule[],
8
- locale?: string,
9
- fix?: boolean,
10
- ): Promise<{
11
- violations: import('@markuplint/ml-config').Violation[];
12
- fixedCode: string;
4
+ export declare function mlTest(sourceCode: string, config: Config, rules?: AnyMLRule[], locale?: string, fix?: boolean): Promise<{
5
+ violations: import("@markuplint/ml-config").Violation[];
6
+ fixedCode: string;
13
7
  }>;
14
- export declare function mlRuleTest<T extends RuleConfigValue, O = null>(
15
- rule: RuleSeed<T, O>,
16
- sourceCode: string,
17
- config?: Omit<Config, 'rules' | 'nodeRules' | 'childNodeRules'> & {
18
- rule?: Rule<T, O>;
19
- nodeRule?: NodeRule<T, O>[];
20
- childNodeRule?: ChildNodeRule<T, O>[];
21
- },
22
- fix?: boolean,
23
- locale?: string,
24
- ): Promise<{
25
- violations: import('@markuplint/ml-config').Violation[];
26
- fixedCode: string;
8
+ export declare function mlRuleTest<T extends RuleConfigValue, O = null>(rule: RuleSeed<T, O>, sourceCode: string, config?: Omit<Config, 'rules' | 'nodeRules' | 'childNodeRules'> & {
9
+ rule?: Rule<T, O>;
10
+ nodeRule?: NodeRule<T, O>[];
11
+ childNodeRule?: ChildNodeRule<T, O>[];
12
+ }, fix?: boolean, locale?: string): Promise<{
13
+ violations: import("@markuplint/ml-config").Violation[];
14
+ fixedCode: string;
27
15
  }>;
28
- export declare function mlTestFile(
29
- target: Target,
30
- config?: Config,
31
- rules?: AnyMLRule[],
32
- locale?: string,
33
- fix?: boolean,
34
- ): Promise<{
35
- violations: import('@markuplint/ml-config').Violation[];
36
- fixedCode: string;
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;
37
19
  }>;
38
20
  export interface NodeRule<T extends RuleConfigValue, O = void> {
39
- tagName?: string;
40
- selector?: string;
41
- regexSelector?: RegexSelector;
42
- categories?: string[];
43
- roles?: string[];
44
- obsolete?: boolean;
45
- rule?: Rule<T, O>;
21
+ tagName?: string;
22
+ selector?: string;
23
+ regexSelector?: RegexSelector;
24
+ categories?: string[];
25
+ roles?: string[];
26
+ obsolete?: boolean;
27
+ rule?: Rule<T, O>;
46
28
  }
47
29
  export interface ChildNodeRule<T extends RuleConfigValue, O = void> {
48
- tagName?: string;
49
- selector?: string;
50
- regexSelector?: RegexSelector;
51
- inheritance?: boolean;
52
- rule?: Rule<T, O>;
30
+ tagName?: string;
31
+ selector?: string;
32
+ regexSelector?: RegexSelector;
33
+ inheritance?: boolean;
34
+ rule?: Rule<T, O>;
53
35
  }
@@ -0,0 +1,83 @@
1
+ import { MLRule } from '@markuplint/ml-core';
2
+ import { lint } from '../api/index.mjs';
3
+ import { getGlobal } from '../global-settings.mjs';
4
+ export async function mlTest(sourceCode, config, rules, locale = 'en', fix = false) {
5
+ const global = getGlobal();
6
+ const results = await lint([{ sourceCode }], {
7
+ config,
8
+ rules,
9
+ locale: locale ?? global.locale,
10
+ fix,
11
+ ignoreExt: true,
12
+ autoLoad: true,
13
+ importPresetRules: !rules,
14
+ });
15
+ const result = results[0];
16
+ return {
17
+ violations: result?.violations ?? [],
18
+ fixedCode: result?.fixedCode ?? sourceCode,
19
+ };
20
+ }
21
+ export async function mlRuleTest(rule, sourceCode, config = { rule: true }, fix = false, locale = 'en') {
22
+ const _config = {
23
+ ...config,
24
+ rules: config.rule !== undefined
25
+ ? {
26
+ '<current-rule>': config.rule,
27
+ }
28
+ : config.rule === undefined && config.nodeRule === undefined && config.childNodeRule === undefined
29
+ ? {
30
+ '<current-rule>': true,
31
+ }
32
+ : undefined,
33
+ nodeRules: config.nodeRule !== undefined
34
+ ? config.nodeRule.map(nodeConfig => ({
35
+ ...nodeConfig,
36
+ rules: nodeConfig.rule !== undefined
37
+ ? {
38
+ '<current-rule>': nodeConfig.rule,
39
+ }
40
+ : undefined,
41
+ }))
42
+ : undefined,
43
+ childNodeRules: config.childNodeRule !== undefined
44
+ ? config.childNodeRule.map(childNodeConfig => ({
45
+ ...childNodeConfig,
46
+ rules: childNodeConfig.rule !== undefined
47
+ ? {
48
+ '<current-rule>': childNodeConfig.rule,
49
+ }
50
+ : undefined,
51
+ }))
52
+ : undefined,
53
+ };
54
+ const res = await mlTest(sourceCode, _config, [
55
+ new MLRule({
56
+ name: '<current-rule>',
57
+ ...rule,
58
+ }),
59
+ ], locale, fix);
60
+ res.violations.map(v => {
61
+ // @ts-ignore
62
+ delete v.ruleId;
63
+ });
64
+ return res;
65
+ }
66
+ export async function mlTestFile(target, config, rules, locale, fix = false) {
67
+ const global = getGlobal();
68
+ const results = await lint([target], {
69
+ config,
70
+ rules,
71
+ locale: locale ?? global.locale,
72
+ fix,
73
+ ignoreExt: true,
74
+ noSearchConfig: !!config,
75
+ autoLoad: true,
76
+ importPresetRules: !rules,
77
+ });
78
+ const result = results[0];
79
+ return {
80
+ violations: result?.violations ?? [],
81
+ fixedCode: result?.fixedCode ?? result?.sourceCode,
82
+ };
83
+ }
@@ -0,0 +1,27 @@
1
+ import type { Config, Violation } from '@markuplint/ml-config';
2
+ import type { Document, Ruleset } from '@markuplint/ml-core';
3
+ export interface MLResultInfo {
4
+ violations: Violation[];
5
+ filePath: string;
6
+ sourceCode: string;
7
+ fixedCode: string;
8
+ }
9
+ /**
10
+ * @deprecated
11
+ */
12
+ export interface MLResultInfo_v1 {
13
+ results: Violation[];
14
+ filePath: string;
15
+ sourceCode: string;
16
+ fixedCode: string;
17
+ document: Document<any, unknown> | null;
18
+ parser: string;
19
+ locale?: string;
20
+ ruleset: Ruleset;
21
+ configSet: {
22
+ config: Config;
23
+ files: string[];
24
+ error: string[];
25
+ };
26
+ }
27
+ export declare type Nullable<T> = T | null | undefined;
package/lib/types.d.ts CHANGED
@@ -1,27 +1,27 @@
1
1
  import type { Config, 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
+ violations: Violation[];
5
+ filePath: string;
6
+ sourceCode: string;
7
+ fixedCode: string;
8
8
  }
9
9
  /**
10
10
  * @deprecated
11
11
  */
12
12
  export interface MLResultInfo_v1 {
13
- results: Violation[];
14
- filePath: string;
15
- sourceCode: string;
16
- fixedCode: string;
17
- document: Document<any, unknown> | null;
18
- parser: string;
19
- locale?: string;
20
- ruleset: Ruleset;
21
- configSet: {
22
- config: Config;
23
- files: string[];
24
- error: string[];
25
- };
13
+ results: Violation[];
14
+ filePath: string;
15
+ sourceCode: string;
16
+ fixedCode: string;
17
+ document: Document<any, unknown> | null;
18
+ parser: string;
19
+ locale?: string;
20
+ ruleset: Ruleset;
21
+ configSet: {
22
+ config: Config;
23
+ files: string[];
24
+ error: string[];
25
+ };
26
26
  }
27
27
  export declare type Nullable<T> = T | null | undefined;
package/lib/types.mjs ADDED
@@ -0,0 +1 @@
1
+ export {};
package/lib/util.d.mts ADDED
@@ -0,0 +1,19 @@
1
+ import type { Nullable } from './types.mjs';
2
+ export declare function nonNullableFilter<T>(item: Nullable<T>): item is T;
3
+ export declare function uuid(): string;
4
+ export declare const markuplint: string;
5
+ export declare function write(message: string): void;
6
+ export declare namespace write {
7
+ var _a: () => boolean;
8
+ export { _a as break };
9
+ }
10
+ export declare function error(message: string): void;
11
+ export declare namespace error {
12
+ var exit: () => never;
13
+ }
14
+ export declare const head: (method: string, noColor?: boolean | undefined) => string;
15
+ export declare function p(s: number | string, pad: number, start?: boolean): string;
16
+ export declare function w(s: string): number;
17
+ export declare function space(str: string): string;
18
+ export declare function invisibleSpace(str: string): string;
19
+ export declare function messageToString(message: string, reason?: string): string;
package/lib/util.d.ts CHANGED
@@ -4,12 +4,12 @@ export declare function uuid(): string;
4
4
  export declare const markuplint: string;
5
5
  export declare function write(message: string): void;
6
6
  export declare namespace write {
7
- var _a: () => boolean;
8
- export { _a as break };
7
+ var _a: () => boolean;
8
+ export { _a as break };
9
9
  }
10
10
  export declare function error(message: string): void;
11
11
  export declare namespace error {
12
- var exit: () => never;
12
+ var exit: () => never;
13
13
  }
14
14
  export declare const head: (method: string, noColor?: boolean | undefined) => string;
15
15
  export declare function p(s: number | string, pad: number, start?: boolean): string;
package/lib/util.mjs ADDED
@@ -0,0 +1,73 @@
1
+ import { createRequire } from 'module';
2
+ import c from 'cli-color';
3
+ // @ts-ignore
4
+ import eastasianwidth from 'eastasianwidth';
5
+ import stripAnsi from 'strip-ansi';
6
+ import { v4 } from 'uuid';
7
+ const require = createRequire(import.meta.url);
8
+ export function nonNullableFilter(item) {
9
+ return !!item;
10
+ }
11
+ export function uuid() {
12
+ return v4();
13
+ }
14
+ const logo = `<${c.xterm(39)('✔')}>`;
15
+ const version = require('../package.json').version;
16
+ const eaw = eastasianwidth;
17
+ const box = (lines, { width = 40, padding = 1, center = false, noColor = false }) => {
18
+ const bt = `┌${'─'.repeat(width - 2)}┐`;
19
+ const pd = `│${' '.repeat(width - 2)}│`;
20
+ const bb = `└${'─'.repeat(width - 2)}┘`;
21
+ const texts = lines.map(line => {
22
+ const nc = stripAnsi(line);
23
+ const length = nc.length;
24
+ const pad = width - 2 - 1 - length;
25
+ const pad2 = Math.floor(pad / 2);
26
+ const padD = pad % 2;
27
+ const padl = center ? pad2 : 0;
28
+ const padr = center ? pad2 + padD : pad;
29
+ const text = noColor ? nc : line;
30
+ return `│ ${' '.repeat(padl)}${text}${' '.repeat(padr)}│`;
31
+ });
32
+ const result = [bt, pd, ...texts, pd, bb];
33
+ return result.join('\n');
34
+ };
35
+ export const markuplint = `markup${c.xterm(39)('lint')}`;
36
+ export function write(message) {
37
+ process.stdout.write(message + '\n');
38
+ }
39
+ write.break = () => process.stdout.write('\n');
40
+ export function error(message) {
41
+ process.stderr.write(message + '\n');
42
+ }
43
+ error.exit = () => process.exit(1);
44
+ export const head = (method, noColor) => box([`${logo} ${markuplint}`, c.blackBright(`v${version}`), '', c.bold(method)], {
45
+ center: true,
46
+ noColor,
47
+ });
48
+ export function p(s, pad, start = false) {
49
+ const l = w(`${s}`.trim());
50
+ const d = pad - l;
51
+ const _ = ' '.repeat(d < 0 ? 0 : d);
52
+ return start ? `${_}${s}` : `${s}${_}`;
53
+ }
54
+ export function w(s) {
55
+ return s.replace(/./g, _ => '0'.repeat(eaw.characterLength(_))).length;
56
+ }
57
+ export function space(str) {
58
+ return str
59
+ .replace(/\s+/g, $0 => {
60
+ return c.xterm(8)($0);
61
+ })
62
+ .replace(/ /g, $0 => '•')
63
+ .replace(/\t/g, $0 => '→ ');
64
+ }
65
+ export function invisibleSpace(str) {
66
+ return str.replace(/\t/g, $0 => ' ').replace(/./g, $0 => ' ');
67
+ }
68
+ export function messageToString(message, reason) {
69
+ if (!reason) {
70
+ return message;
71
+ }
72
+ return `${message} / ${reason}`;
73
+ }
package/lib/v1.d.mts ADDED
@@ -0,0 +1,4 @@
1
+ /**
2
+ * @deprecated
3
+ */
4
+ export { lint_v1 as exec } from './api/v1.mjs';
package/lib/v1.mjs ADDED
@@ -0,0 +1,4 @@
1
+ /**
2
+ * @deprecated
3
+ */
4
+ export { lint_v1 as exec } from './api/v1.mjs';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "markuplint",
3
- "version": "2.0.0",
3
+ "version": "2.1.0",
4
4
  "description": "A Linter for All Markup Languages.",
5
5
  "author": "Yusuke Hirao",
6
6
  "license": "MIT",
@@ -28,13 +28,13 @@
28
28
  "@markuplint/create-rule-helper": "2.0.0",
29
29
  "@markuplint/file-resolver": "2.0.0",
30
30
  "@markuplint/html-parser": "2.0.0",
31
- "@markuplint/html-spec": "2.0.0",
31
+ "@markuplint/html-spec": "^2.1.0",
32
32
  "@markuplint/i18n": "2.0.0",
33
33
  "@markuplint/ml-ast": "2.0.0",
34
34
  "@markuplint/ml-config": "2.0.0",
35
35
  "@markuplint/ml-core": "2.0.0",
36
36
  "@markuplint/ml-spec": "2.0.0",
37
- "@markuplint/rules": "2.0.0",
37
+ "@markuplint/rules": "^2.1.0",
38
38
  "chokidar": "^3.5.3",
39
39
  "cli-color": "^2.0.1",
40
40
  "debug": "^4.3.3",
@@ -50,5 +50,5 @@
50
50
  "tslib": "^2.3.1",
51
51
  "uuid": "^8.3.2"
52
52
  },
53
- "gitHead": "de81fc514acdf472f87184e3499e9364258f9b66"
53
+ "gitHead": "37c0b6e00b612ce8d31549ce6b99c2f20ac242c7"
54
54
  }
package/lib/cli/head.d.ts DELETED
@@ -1 +0,0 @@
1
- export declare const head: string;
package/lib/cli/head.js DELETED
@@ -1,31 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.head = void 0;
4
- const tslib_1 = require("tslib");
5
- const cli_color_1 = (0, tslib_1.__importDefault)(require("cli-color"));
6
- const strip_ansi_1 = (0, tslib_1.__importDefault)(require("strip-ansi"));
7
- const logo = `<${cli_color_1.default.xterm(39)('✔')}>`;
8
- const markuplint = `markup${cli_color_1.default.xterm(39)('lint')}`;
9
- // eslint-disable-next-line @typescript-eslint/no-var-requires
10
- const version = require('../../package.json').version;
11
- const box = (lines, { width = 40, padding = 1, center = false, noColor = false }) => {
12
- const bt = `┌${'─'.repeat(width - 2)}┐`;
13
- const pd = `│${' '.repeat(width - 2)}│`;
14
- const bb = `└${'─'.repeat(width - 2)}┘`;
15
- const texts = lines.map(line => {
16
- const nc = (0, strip_ansi_1.default)(line);
17
- const length = nc.length;
18
- const pad = width - 2 - 1 - length;
19
- const pad2 = Math.floor(pad / 2);
20
- const padD = pad % 2;
21
- const padl = center ? pad2 : 0;
22
- const padr = center ? pad2 + padD : pad;
23
- const text = noColor ? nc : line;
24
- return `│ ${' '.repeat(padl)}${text}${' '.repeat(padr)}│`;
25
- });
26
- const result = [bt, pd, ...texts, pd, bb];
27
- return result.join('\n');
28
- };
29
- exports.head = box([`${logo} ${markuplint}`, cli_color_1.default.blackBright(`v${version}`), '', cli_color_1.default.bold('Initialization')], {
30
- center: true,
31
- });
@@ -1,6 +0,0 @@
1
- export declare const markuplint: string;
2
- export declare function p(s: number | string, pad: number, start?: boolean): string;
3
- export declare function w(s: string): number;
4
- export declare function space(str: string): string;
5
- export declare function invisibleSpace(str: string): string;
6
- export declare function messageToString(message: string, reason?: string): string;
@@ -1,40 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.messageToString = exports.invisibleSpace = exports.space = exports.w = exports.p = exports.markuplint = void 0;
4
- const tslib_1 = require("tslib");
5
- const cli_color_1 = (0, tslib_1.__importDefault)(require("cli-color"));
6
- // @ts-ignore
7
- const eastasianwidth_1 = (0, tslib_1.__importDefault)(require("eastasianwidth"));
8
- exports.markuplint = `markup${cli_color_1.default.xterm(39)('lint')}`;
9
- const eaw = eastasianwidth_1.default;
10
- function p(s, pad, start = false) {
11
- const l = w(`${s}`.trim());
12
- const d = pad - l;
13
- const _ = ' '.repeat(d < 0 ? 0 : d);
14
- return start ? `${_}${s}` : `${s}${_}`;
15
- }
16
- exports.p = p;
17
- function w(s) {
18
- return s.replace(/./g, _ => '0'.repeat(eaw.characterLength(_))).length;
19
- }
20
- exports.w = w;
21
- function space(str) {
22
- return str
23
- .replace(/\s+/g, $0 => {
24
- return cli_color_1.default.xterm(8)($0);
25
- })
26
- .replace(/ /g, $0 => '•')
27
- .replace(/\t/g, $0 => '→ ');
28
- }
29
- exports.space = space;
30
- function invisibleSpace(str) {
31
- return str.replace(/\t/g, $0 => ' ').replace(/./g, $0 => ' ');
32
- }
33
- exports.invisibleSpace = invisibleSpace;
34
- function messageToString(message, reason) {
35
- if (!reason) {
36
- return message;
37
- }
38
- return `${message} / ${reason}`;
39
- }
40
- exports.messageToString = messageToString;