markuplint 3.15.0 → 4.0.0-alpha.10

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/LICENSE +1 -1
  2. package/README.md +4 -2
  3. package/bin/markuplint.mjs +3 -0
  4. package/lib/api/index.d.ts +2 -2
  5. package/lib/api/index.js +2 -10
  6. package/lib/api/lint.d.ts +2 -2
  7. package/lib/api/lint.js +5 -10
  8. package/lib/api/ml-engine.d.ts +28 -23
  9. package/lib/api/ml-engine.js +123 -103
  10. package/lib/api/types.d.ts +32 -32
  11. package/lib/api/types.js +1 -2
  12. package/lib/api/v1.d.ts +43 -43
  13. package/lib/api/v1.js +12 -20
  14. package/lib/cli/bootstrap.d.ts +65 -63
  15. package/lib/cli/bootstrap.js +12 -11
  16. package/lib/cli/command.d.ts +3 -7
  17. package/lib/cli/command.js +26 -34
  18. package/lib/cli/index.js +59 -71
  19. package/lib/cli/init/create-config.d.ts +2 -6
  20. package/lib/cli/init/create-config.js +14 -12
  21. package/lib/cli/init/get-default-rules.d.ts +3 -3
  22. package/lib/cli/init/get-default-rules.js +12 -53
  23. package/lib/cli/init/index.js +28 -37
  24. package/lib/cli/init/select-modules.d.ts +2 -0
  25. package/lib/cli/init/select-modules.js +10 -0
  26. package/lib/cli/init/types.d.ts +4 -15
  27. package/lib/cli/init/types.js +1 -2
  28. package/lib/cli/output.d.ts +2 -2
  29. package/lib/cli/output.js +8 -14
  30. package/lib/cli/search/index.d.ts +2 -2
  31. package/lib/cli/search/index.js +10 -14
  32. package/lib/debug.js +9 -13
  33. package/lib/get-json-module.d.ts +1 -0
  34. package/lib/get-json-module.js +10 -0
  35. package/lib/global-settings.d.ts +1 -1
  36. package/lib/global-settings.js +2 -7
  37. package/lib/i18n.js +8 -15
  38. package/lib/index.d.ts +7 -5
  39. package/lib/index.js +6 -10
  40. package/lib/reporter/github-reporter.d.ts +1 -1
  41. package/lib/reporter/github-reporter.js +7 -9
  42. package/lib/reporter/index.d.ts +3 -3
  43. package/lib/reporter/index.js +3 -6
  44. package/lib/reporter/simple-reporter.d.ts +2 -2
  45. package/lib/reporter/simple-reporter.js +11 -16
  46. package/lib/reporter/standard-reporter.d.ts +2 -2
  47. package/lib/reporter/standard-reporter.js +37 -28
  48. package/lib/testing-tool/index.d.ts +23 -41
  49. package/lib/testing-tool/index.js +41 -47
  50. package/lib/types.d.ts +17 -17
  51. package/lib/types.js +1 -2
  52. package/lib/v1.d.ts +1 -1
  53. package/lib/v1.js +1 -5
  54. package/lib/version.d.ts +1 -0
  55. package/lib/version.js +3 -0
  56. package/package.json +26 -34
  57. package/bin/markuplint +0 -3
  58. package/lib/cli/create-rule/index.d.ts +0 -1
  59. package/lib/cli/create-rule/index.js +0 -85
  60. package/lib/cli/init/install-module.d.ts +0 -7
  61. package/lib/cli/init/install-module.js +0 -80
  62. package/lib/cli/prompt.d.ts +0 -23
  63. package/lib/cli/prompt.js +0 -77
  64. package/lib/util.d.ts +0 -17
  65. package/lib/util.js +0 -88
package/lib/api/types.js CHANGED
@@ -1,2 +1 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
1
+ export {};
package/lib/api/v1.d.ts CHANGED
@@ -6,46 +6,46 @@ import type { MLRule } from '@markuplint/ml-core';
6
6
  * @returns
7
7
  */
8
8
  export declare function lint_v1(options: {
9
- /**
10
- * Glob pattern
11
- */
12
- readonly files?: string | readonly string[];
13
- /**
14
- * Target source code of evaluation
15
- */
16
- readonly sourceCodes?: string | readonly string[];
17
- /**
18
- * File names when `sourceCodes`
19
- */
20
- readonly names?: string | readonly string[];
21
- /**
22
- * Workspace path when `sourceCodes`
23
- */
24
- readonly workspace?: string;
25
- /**
26
- * Configure file or object
27
- */
28
- readonly config?: string | Config;
29
- /**
30
- * The config applied when not resolved from files or set it explicitly.
31
- */
32
- readonly defaultConfig?: Config;
33
- /**
34
- * Rules (default: `@markuplint/rules`)
35
- */
36
- readonly rules?: readonly Readonly<MLRule<RuleConfigValue, PlainData>>[];
37
- /**
38
- * Auto resolve rules
39
- *
40
- * Auto importing form *node_modules* when set `@markuplint/rule-{RULE_NAME}` or `markuplint-rule-{RULE_NAME}` in config rules
41
- */
42
- readonly rulesAutoResolve?: boolean;
43
- /**
44
- * Auto fix
45
- */
46
- readonly fix?: boolean;
47
- /**
48
- * Locale
49
- */
50
- readonly locale?: string;
51
- }): Promise<import('..').MLResultInfo[]>;
9
+ /**
10
+ * Glob pattern
11
+ */
12
+ readonly files?: string | readonly string[];
13
+ /**
14
+ * Target source code of evaluation
15
+ */
16
+ readonly sourceCodes?: string | readonly string[];
17
+ /**
18
+ * File names when `sourceCodes`
19
+ */
20
+ readonly names?: string | readonly string[];
21
+ /**
22
+ * Workspace path when `sourceCodes`
23
+ */
24
+ readonly workspace?: string;
25
+ /**
26
+ * Configure file or object
27
+ */
28
+ readonly config?: string | Config;
29
+ /**
30
+ * The config applied when not resolved from files or set it explicitly.
31
+ */
32
+ readonly defaultConfig?: Config;
33
+ /**
34
+ * Rules (default: `@markuplint/rules`)
35
+ */
36
+ readonly rules?: readonly Readonly<MLRule<RuleConfigValue, PlainData>>[];
37
+ /**
38
+ * Auto resolve rules
39
+ *
40
+ * Auto importing form *node_modules* when set `@markuplint/rule-{RULE_NAME}` or `markuplint-rule-{RULE_NAME}` in config rules
41
+ */
42
+ readonly rulesAutoResolve?: boolean;
43
+ /**
44
+ * Auto fix
45
+ */
46
+ readonly fix?: boolean;
47
+ /**
48
+ * Locale
49
+ */
50
+ readonly locale?: string;
51
+ }): Promise<import("../types.js").MLResultInfo[]>;
package/lib/api/v1.js CHANGED
@@ -1,27 +1,20 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.lint_v1 = void 0;
4
- const shared_1 = require("@markuplint/shared");
5
- const lint_1 = require("./lint");
1
+ import { toNoEmptyStringArrayFromStringOrArray } from '@markuplint/shared';
2
+ import { lint } from './lint.js';
6
3
  /**
7
4
  * @deprecated
8
5
  * @param options
9
6
  * @returns
10
7
  */
11
- async function lint_v1(options) {
12
- var _a;
13
- const filePathList = (0, shared_1.toNoEmptyStringArrayFromStringOrArray)(options.files);
14
- const codes = (0, shared_1.toNoEmptyStringArrayFromStringOrArray)(options.sourceCodes);
8
+ export async function lint_v1(options) {
9
+ const filePathList = toNoEmptyStringArrayFromStringOrArray(options.files);
10
+ const codes = toNoEmptyStringArrayFromStringOrArray(options.sourceCodes);
15
11
  const files = [
16
12
  ...filePathList,
17
- ...codes.map((code, i) => {
18
- var _a, _b;
19
- return ({
20
- sourceCode: code,
21
- name: Array.isArray(options.names) ? (_a = options.names) === null || _a === void 0 ? void 0 : _a[i] : options.names,
22
- workspace: (_b = options.workspace) === null || _b === void 0 ? void 0 : _b[i],
23
- });
24
- }),
13
+ ...codes.map((code, i) => ({
14
+ sourceCode: code,
15
+ name: Array.isArray(options.names) ? options.names?.[i] : options.names,
16
+ workspace: options.workspace?.[i],
17
+ })),
25
18
  ];
26
19
  let config;
27
20
  let configFile;
@@ -31,14 +24,13 @@ async function lint_v1(options) {
31
24
  else if (options.config) {
32
25
  config = options.config;
33
26
  }
34
- const result = await (0, lint_1.lint)(files, {
27
+ const result = await lint(files, {
35
28
  config,
36
29
  configFile,
37
30
  noSearchConfig: filePathList.length === 0,
38
31
  rules: options.rules,
39
- autoLoad: (_a = options.rulesAutoResolve) !== null && _a !== void 0 ? _a : true,
32
+ autoLoad: options.rulesAutoResolve ?? true,
40
33
  locale: options.locale,
41
34
  });
42
35
  return result;
43
36
  }
44
- exports.lint_v1 = lint_v1;
@@ -1,66 +1,68 @@
1
1
  import type { ReadonlyDeep } from 'type-fest';
2
- import meow from 'meow';
3
- export declare const help =
4
- '\nUsage\n\t$ markuplint <HTML file paths (glob format)>\n\t$ <stdout> | markuplint\n\nOptions\n\t--config, -c FILE_PATH A configuration file path.\n\t--fix, Fix HTML.\n\t--format, -f FORMAT Output format. Support "JSON", "Simple", "GitHub" and "Standard". Default: "Standard".\n\t--no-search-config No search a configure file automatically.\n\t--ignore-ext Evaluate files that are received even though the type of extension.\n\t--no-import-preset-rules No import preset rules.\n\t--locale Locale of the message of violation. Default is an OS setting.\n\t--no-color, Output no color.\n\t--problem-only, -p Output only problems, without passeds.\n\t--allow-warnings Return status code 0 even if there are warnings.\n\t--allow-empty-input Return status code 1 even if there are no input files.\n\t--verbose Output with detailed information.\n\n\t--init Initialize settings interactively.\n\t--create-rule Add the scaffold of a custom rule.\n\t--search Search lines of codes that include the target element by selectors.\n\n\t--help, -h Show help.\n\t--version, -v Show version.\n\nExamples\n\t$ markuplint verifyee.html --config path/to/.markuplintrc\n\t$ cat verifyee.html | markuplint\n';
5
- export declare const cli: meow.Result<{
6
- config: {
7
- type: 'string';
8
- alias: string;
9
- };
10
- fix: {
11
- type: 'boolean';
12
- default: false;
13
- };
14
- format: {
15
- type: 'string';
16
- alias: string;
17
- };
18
- searchConfig: {
19
- type: 'boolean';
20
- default: true;
21
- };
22
- ignoreExt: {
23
- type: 'boolean';
24
- default: false;
25
- };
26
- importPresetRules: {
27
- type: 'boolean';
28
- default: true;
29
- };
30
- locale: {
31
- type: 'string';
32
- };
33
- color: {
34
- type: 'boolean';
35
- default: true;
36
- };
37
- problemOnly: {
38
- type: 'boolean';
39
- alias: string;
40
- default: false;
41
- };
42
- allowWarnings: {
43
- type: 'boolean';
44
- default: false;
45
- };
46
- allowEmptyInput: {
47
- type: 'boolean';
48
- default: true;
49
- };
50
- verbose: {
51
- type: 'boolean';
52
- default: false;
53
- };
54
- init: {
55
- type: 'boolean';
56
- default: false;
57
- };
58
- createRule: {
59
- type: 'boolean';
60
- default: false;
61
- };
62
- search: {
63
- type: 'string';
64
- };
2
+ export declare const help = "\nUsage\n\t$ markuplint <HTML file paths (glob format)>\n\t$ <stdout> | markuplint\n\nOptions\n\t--config, -c FILE_PATH A configuration file path.\n\t--fix, Fix HTML.\n\t--format, -f FORMAT Output format. Support \"JSON\", \"Simple\", \"GitHub\" and \"Standard\". Default: \"Standard\".\n\t--no-search-config No search a configure file automatically.\n\t--ignore-ext Evaluate files that are received even though the type of extension.\n\t--no-import-preset-rules No import preset rules.\n\t--locale Locale of the message of violation. Default is an OS setting.\n\t--no-color, Output no color.\n\t--problem-only, -p Output only problems, without passeds.\n\t--allow-warnings Return status code 0 even if there are warnings.\n\t--allow-empty-input Return status code 1 even if there are no input files.\n\t--verbose Output with detailed information.\n\t--include-node-modules Include files in node_modules directory. Default: false.\n\n\t--init Initialize settings interactively.\n\t--search Search lines of codes that include the target element by selectors.\n\n\t--help, -h Show help.\n\t--version, -v Show version.\n\nExamples\n\t$ markuplint verifyee.html --config path/to/.markuplintrc\n\t$ cat verifyee.html | markuplint\n";
3
+ export declare const cli: import("meow").Result<{
4
+ config: {
5
+ type: "string";
6
+ shortFlag: string;
7
+ };
8
+ fix: {
9
+ type: "boolean";
10
+ default: false;
11
+ };
12
+ format: {
13
+ type: "string";
14
+ shortFlag: string;
15
+ };
16
+ searchConfig: {
17
+ type: "boolean";
18
+ default: true;
19
+ };
20
+ ignoreExt: {
21
+ type: "boolean";
22
+ default: false;
23
+ };
24
+ importPresetRules: {
25
+ type: "boolean";
26
+ default: true;
27
+ };
28
+ locale: {
29
+ type: "string";
30
+ };
31
+ color: {
32
+ type: "boolean";
33
+ default: true;
34
+ };
35
+ problemOnly: {
36
+ type: "boolean";
37
+ shortFlag: string;
38
+ default: false;
39
+ };
40
+ allowWarnings: {
41
+ type: "boolean";
42
+ default: false;
43
+ };
44
+ allowEmptyInput: {
45
+ type: "boolean";
46
+ default: true;
47
+ };
48
+ verbose: {
49
+ type: "boolean";
50
+ default: false;
51
+ };
52
+ init: {
53
+ type: "boolean";
54
+ default: false;
55
+ };
56
+ createRule: {
57
+ type: "boolean";
58
+ default: false;
59
+ };
60
+ search: {
61
+ type: "string";
62
+ };
63
+ includeNodeModules: {
64
+ type: "boolean";
65
+ default: false;
66
+ };
65
67
  }>;
66
68
  export type CLIOptions = ReadonlyDeep<typeof cli.flags>;
@@ -1,9 +1,5 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.cli = exports.help = void 0;
4
- const tslib_1 = require("tslib");
5
- const meow_1 = tslib_1.__importDefault(require("meow"));
6
- exports.help = `
1
+ import meow from 'meow';
2
+ export const help = `
7
3
  Usage
8
4
  $ markuplint <HTML file paths (glob format)>
9
5
  $ <stdout> | markuplint
@@ -21,9 +17,9 @@ Options
21
17
  --allow-warnings Return status code 0 even if there are warnings.
22
18
  --allow-empty-input Return status code 1 even if there are no input files.
23
19
  --verbose Output with detailed information.
20
+ --include-node-modules Include files in node_modules directory. Default: false.
24
21
 
25
22
  --init Initialize settings interactively.
26
- --create-rule Add the scaffold of a custom rule.
27
23
  --search Search lines of codes that include the target element by selectors.
28
24
 
29
25
  --help, -h Show help.
@@ -33,11 +29,12 @@ Examples
33
29
  $ markuplint verifyee.html --config path/to/.markuplintrc
34
30
  $ cat verifyee.html | markuplint
35
31
  `;
36
- exports.cli = (0, meow_1.default)(exports.help, {
32
+ export const cli = meow(help, {
33
+ importMeta: import.meta,
37
34
  flags: {
38
35
  config: {
39
36
  type: 'string',
40
- alias: 'c',
37
+ shortFlag: 'c',
41
38
  },
42
39
  fix: {
43
40
  type: 'boolean',
@@ -45,7 +42,7 @@ exports.cli = (0, meow_1.default)(exports.help, {
45
42
  },
46
43
  format: {
47
44
  type: 'string',
48
- alias: 'f',
45
+ shortFlag: 'f',
49
46
  },
50
47
  searchConfig: {
51
48
  type: 'boolean',
@@ -68,7 +65,7 @@ exports.cli = (0, meow_1.default)(exports.help, {
68
65
  },
69
66
  problemOnly: {
70
67
  type: 'boolean',
71
- alias: 'p',
68
+ shortFlag: 'p',
72
69
  default: false,
73
70
  },
74
71
  allowWarnings: {
@@ -95,5 +92,9 @@ exports.cli = (0, meow_1.default)(exports.help, {
95
92
  search: {
96
93
  type: 'string',
97
94
  },
95
+ includeNodeModules: {
96
+ type: 'boolean',
97
+ default: false,
98
+ },
98
99
  },
99
100
  });
@@ -1,8 +1,4 @@
1
- import type { CLIOptions } from './bootstrap';
2
- import type { APIOptions } from '../api/types';
1
+ import type { CLIOptions } from './bootstrap.js';
2
+ import type { APIOptions } from '../api/types.js';
3
3
  import type { Target } from '@markuplint/file-resolver';
4
- export declare function command(
5
- files: readonly Readonly<Target>[],
6
- options: CLIOptions,
7
- apiOptions?: APIOptions,
8
- ): Promise<boolean>;
4
+ export declare function command(files: readonly Readonly<Target>[], options: CLIOptions, apiOptions?: APIOptions): Promise<boolean>;
@@ -1,38 +1,34 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.command = void 0;
4
- const tslib_1 = require("tslib");
5
- const fs_1 = require("fs");
6
- const path_1 = tslib_1.__importDefault(require("path"));
7
- const file_resolver_1 = require("@markuplint/file-resolver");
8
- const api_1 = require("../api");
9
- const debug_1 = require("../debug");
10
- const output_1 = require("./output");
11
- async function command(files, options, apiOptions) {
12
- var _a;
1
+ import { promises as fs } from 'node:fs';
2
+ import path from 'node:path';
3
+ import { resolveFiles } from '@markuplint/file-resolver';
4
+ import { MLEngine } from '../api/index.js';
5
+ import { log } from '../debug.js';
6
+ import { output } from './output.js';
7
+ export async function command(files, options, apiOptions) {
13
8
  const fix = options.fix;
14
- const configFile = options.config && path_1.default.join(process.cwd(), options.config);
9
+ const configFile = options.config && path.join(process.cwd(), options.config);
15
10
  const locale = options.locale;
16
11
  const searchConfig = options.searchConfig;
17
12
  const ignoreExt = options.ignoreExt;
18
13
  const importPresetRules = options.importPresetRules;
19
14
  const verbose = options.verbose;
20
- const fileList = await (0, file_resolver_1.resolveFiles)(files);
15
+ const ignoreGlob = options.includeNodeModules ? undefined : 'node_modules/**';
16
+ const fileList = await resolveFiles(files, ignoreGlob);
21
17
  if (fileList.length === 0 && !options.allowEmptyInput) {
22
18
  process.stderr.write('Markuplint: No target files.\n');
23
19
  // Error
24
20
  return true;
25
21
  }
26
- if (debug_1.log.enabled) {
27
- (0, debug_1.log)('File list: %O', fileList.map(f => f.path));
28
- (0, debug_1.log)('Config: %s', configFile !== null && configFile !== void 0 ? configFile : 'N/A');
29
- (0, debug_1.log)('Fix option: %s', fix);
22
+ if (log.enabled) {
23
+ log('File list: %O', fileList.map(f => f.path));
24
+ log('Config: %s', configFile ?? 'N/A');
25
+ log('Fix option: %s', fix);
30
26
  }
31
- const format = (_a = options.format) === null || _a === void 0 ? void 0 : _a.toLowerCase().trim();
27
+ const format = options.format?.toLowerCase().trim();
32
28
  let hasError = false;
33
29
  const jsonOutput = [];
34
30
  for (const file of fileList) {
35
- const engine = new api_1.MLEngine(file, {
31
+ const engine = new MLEngine(file, {
36
32
  configFile,
37
33
  fix,
38
34
  locale,
@@ -52,21 +48,18 @@ async function command(files, options, apiOptions) {
52
48
  hasError = true;
53
49
  }
54
50
  if (fix) {
55
- (0, debug_1.log)('Overwrite file: %s', result.filePath);
56
- await fs_1.promises.writeFile(result.filePath, result.fixedCode, { encoding: 'utf8' });
57
- process.stdout.write(`markuplint: Fix "${result.filePath}"\n`);
51
+ log('Overwrite file: %s', result.filePath);
52
+ await fs.writeFile(result.filePath, result.fixedCode, { encoding: 'utf8' });
58
53
  }
59
- else {
60
- if (format === 'json') {
61
- jsonOutput.push(...result.violations.map(v => ({
62
- ...v,
63
- filePath: result.filePath,
64
- })));
65
- continue;
66
- }
67
- (0, debug_1.log)('Output reports');
68
- (0, output_1.output)(result, options);
54
+ if (format === 'json') {
55
+ jsonOutput.push(...result.violations.map(v => ({
56
+ ...v,
57
+ filePath: result.filePath,
58
+ })));
59
+ continue;
69
60
  }
61
+ log('Output reports');
62
+ output(result, options);
70
63
  }
71
64
  if (format === 'json') {
72
65
  process.stdout.write(JSON.stringify(jsonOutput, null, 2) + '\n');
@@ -74,4 +67,3 @@ async function command(files, options, apiOptions) {
74
67
  }
75
68
  return hasError;
76
69
  }
77
- exports.command = command;
package/lib/cli/index.js CHANGED
@@ -1,78 +1,66 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const tslib_1 = require("tslib");
4
- const get_stdin_1 = tslib_1.__importDefault(require("get-stdin"));
5
- const debug_1 = require("../debug");
6
- const bootstrap_1 = require("./bootstrap");
7
- const command_1 = require("./command");
8
- const create_rule_1 = require("./create-rule");
9
- const init_1 = require("./init");
10
- const search_1 = tslib_1.__importDefault(require("./search"));
11
- // eslint-disable-next-line @typescript-eslint/no-floating-promises
12
- (async () => {
13
- if (bootstrap_1.cli.flags.v) {
14
- bootstrap_1.cli.showVersion(); // And exit successfully.
15
- }
16
- if (bootstrap_1.cli.flags.h) {
17
- bootstrap_1.cli.showHelp(0); // And exit successfully.
18
- }
19
- if (bootstrap_1.cli.flags.verbose) {
20
- (0, debug_1.verbosely)();
21
- }
22
- if (bootstrap_1.cli.flags.init) {
23
- await (0, init_1.initialize)().catch(err => {
24
- process.stderr.write(err + '\n');
25
- process.exit(1);
26
- });
27
- return;
28
- }
29
- if (bootstrap_1.cli.flags.createRule) {
30
- await (0, create_rule_1.createRule)().catch(err => {
31
- process.stderr.write(err + '\n');
32
- process.exit(1);
33
- });
34
- return;
35
- }
36
- const files = bootstrap_1.cli.input;
37
- if (files.length > 0) {
38
- if (bootstrap_1.cli.flags.search) {
39
- await (0, search_1.default)(files, bootstrap_1.cli.flags, bootstrap_1.cli.flags.search).catch(err => {
40
- process.stderr.write(err + '\n');
41
- process.exit(1);
42
- });
43
- return;
44
- }
45
- const hasError = await (0, command_1.command)(files, bootstrap_1.cli.flags).catch(err => {
46
- throw err;
47
- });
48
- process.exit(hasError ? 1 : 0);
49
- }
50
- if (usePipe()) {
51
- (0, get_stdin_1.default)()
52
- .then(async (stdin) => {
53
- if (stdin) {
54
- const hasError = await (0, command_1.command)([{ sourceCode: stdin }], {
55
- ...bootstrap_1.cli.flags,
56
- ignoreExt: true,
57
- }).catch(err => {
58
- process.stderr.write(err + '\n');
59
- process.exit(1);
60
- });
61
- process.exit(hasError ? 1 : 0);
62
- }
63
- // result is empty
64
- bootstrap_1.cli.showHelp(1);
65
- })
66
- .catch(reason => {
67
- // eslint-disable-next-line no-console
68
- console.warn(reason);
1
+ import getStdin from 'get-stdin';
2
+ import { verbosely } from '../debug.js';
3
+ import { cli } from './bootstrap.js';
4
+ import { command } from './command.js';
5
+ import { initialize } from './init/index.js';
6
+ import { search } from './search/index.js';
7
+ /* eslint-disable unicorn/no-process-exit */
8
+ if (cli.flags.v) {
9
+ cli.showVersion(); // And exit successfully.
10
+ }
11
+ if (cli.flags.h) {
12
+ cli.showHelp(0); // And exit successfully.
13
+ }
14
+ if (cli.flags.verbose) {
15
+ verbosely();
16
+ }
17
+ if (cli.flags.init) {
18
+ await initialize().catch(error => {
19
+ process.stderr.write(error + '\n');
20
+ process.exit(1);
21
+ });
22
+ process.exit(0);
23
+ }
24
+ if (cli.flags.createRule) {
25
+ process.stderr.write("Use to run 'npx @markuplint/create-rule' instead of 'markuplint --create-rule'.\n");
26
+ process.exit(1);
27
+ }
28
+ const files = cli.input;
29
+ if (files.length > 0) {
30
+ if (cli.flags.search) {
31
+ await search(files, cli.flags, cli.flags.search).catch(error => {
32
+ process.stderr.write(error + '\n');
69
33
  process.exit(1);
70
34
  });
35
+ process.exit(0);
71
36
  }
72
- else {
73
- bootstrap_1.cli.showHelp(1);
37
+ const hasError = await command(files, cli.flags).catch(error => {
38
+ throw error;
39
+ });
40
+ process.exit(hasError ? 1 : 0);
41
+ }
42
+ if (usePipe()) {
43
+ const stdin = await getStdin().catch(error => {
44
+ // eslint-disable-next-line no-console
45
+ console.warn(error);
46
+ process.exit(1);
47
+ });
48
+ if (!stdin) {
49
+ // result is empty
50
+ cli.showHelp(1);
74
51
  }
75
- })();
52
+ const hasError = await command([{ sourceCode: stdin }], {
53
+ ...cli.flags,
54
+ ignoreExt: true,
55
+ }).catch(error => {
56
+ process.stderr.write(error + '\n');
57
+ process.exit(1);
58
+ });
59
+ process.exit(hasError ? 1 : 0);
60
+ }
61
+ // No arguments
62
+ cli.showHelp(1);
63
+ /* eslint-enable unicorn/no-process-exit */
76
64
  function usePipe() {
77
65
  return !process.stdin.isTTY && process.stdout.isTTY;
78
66
  }
@@ -1,8 +1,4 @@
1
- import type { DefaultRules, Langs, RuleSettingMode } from './types';
1
+ import type { DefaultRules, Langs, RuleSettingMode } from './types.js';
2
2
  import type { Config } from '@markuplint/ml-config';
3
3
  export declare const langs: Record<Langs, string>;
4
- export declare function createConfig(
5
- langs: readonly Langs[],
6
- mode: RuleSettingMode,
7
- defaultRules: DefaultRules,
8
- ): Config;
4
+ export declare function createConfig(langs: readonly Langs[], mode: RuleSettingMode, defaultRules: DefaultRules): Config;