markuplint 3.7.0 → 3.9.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.
package/README.md CHANGED
@@ -74,7 +74,7 @@ Usage
74
74
  Options
75
75
  --config, -c FILE_PATH A configuration file path.
76
76
  --fix, Fix HTML.
77
- --format, -f FORMAT Output format. Support "JSON", "Simple" and "Standard". Default: "Standard".
77
+ --format, -f FORMAT Output format. Support "JSON", "Simple", "GitHub" and "Standard". Default: "Standard".
78
78
  --no-search-config No search a configure file automatically.
79
79
  --ignore-ext Evaluate files that are received even though the type of extension.
80
80
  --no-import-preset-rules No import preset rules.
@@ -3,12 +3,12 @@ import type { MLResultInfo } from '../types';
3
3
  import type { MLFile, Target } from '@markuplint/file-resolver';
4
4
  import type { PlainData } from '@markuplint/ml-config';
5
5
  import type { Document, RuleConfigValue } from '@markuplint/ml-core';
6
- import { StrictEventEmitter } from 'strict-event-emitter';
6
+ import { Emitter } from 'strict-event-emitter';
7
7
  type MLEngineOptions = {
8
8
  readonly debug?: boolean;
9
9
  readonly watch?: boolean;
10
10
  };
11
- export default class MLEngine extends StrictEventEmitter<MLEngineEventMap> {
11
+ export default class MLEngine extends Emitter<MLEngineEventMap> {
12
12
  #private;
13
13
  static toMLFile(target: Target): Promise<MLFile | undefined>;
14
14
  constructor(file: Readonly<MLFile>, options?: APIOptions & MLEngineOptions);
@@ -11,7 +11,7 @@ const i18n_1 = require("../i18n");
11
11
  const log = debug_1.log.extend('ml-engine');
12
12
  const fileLog = log.extend('file');
13
13
  const configLog = log.extend('config');
14
- class MLEngine extends strict_event_emitter_1.StrictEventEmitter {
14
+ class MLEngine extends strict_event_emitter_1.Emitter {
15
15
  static async toMLFile(target) {
16
16
  const files = await (0, file_resolver_1.resolveFiles)([target]);
17
17
  return files[0];
@@ -18,23 +18,23 @@ export type APIOptions = {
18
18
  readonly autoLoad?: boolean;
19
19
  };
20
20
  export type MLEngineEventMap = {
21
- log: (phase: string, message: string) => void;
22
- config: (filePath: string, config: ConfigSet, message?: string) => void;
23
- exclude: (filePath: string, setting: string, message?: string) => void;
24
- parser: (filePath: string, parser: string, message?: string) => void;
25
- ruleset: (filePath: string, ruleset: Ruleset, message?: string) => void;
26
- schemas: (filePath: string, schemas: MLSchema, message?: string) => void;
27
- rules: (filePath: string, rules: readonly Readonly<AnyMLRule>[], message?: string) => void;
28
- i18n: (filePath: string, locale: LocaleSet, message?: string) => void;
29
- code: (filePath: string, sourceCode: string, message?: string) => void;
30
- lint: (
21
+ log: [phase: string, message: string];
22
+ config: [filePath: string, config: ConfigSet, message?: string];
23
+ exclude: [filePath: string, setting: string, message?: string];
24
+ parser: [filePath: string, parser: string, message?: string];
25
+ ruleset: [filePath: string, ruleset: Ruleset, message?: string];
26
+ schemas: [filePath: string, schemas: MLSchema, message?: string];
27
+ rules: [filePath: string, rules: readonly Readonly<AnyMLRule>[], message?: string];
28
+ i18n: [filePath: string, locale: LocaleSet, message?: string];
29
+ code: [filePath: string, sourceCode: string, message?: string];
30
+ lint: [
31
31
  filePath: string,
32
32
  sourceCode: string,
33
33
  violations: readonly Violation[],
34
34
  fixedCode: string,
35
35
  debug: readonly string[] | null,
36
36
  message?: string,
37
- ) => void;
38
- 'lint-error': (filePath: string, sourceCode: string, error: Readonly<Error>) => void;
39
- 'config-errors': (filePath: string, errors: readonly Readonly<Error>[]) => void;
37
+ ];
38
+ 'lint-error': [filePath: string, sourceCode: string, error: Readonly<Error>];
39
+ 'config-errors': [filePath: string, errors: readonly Readonly<Error>[]];
40
40
  };
@@ -1,58 +1,65 @@
1
1
  import type { ReadonlyDeep } from 'type-fest';
2
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" 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--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';
3
+ 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\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
4
  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
- verbose: {
43
- type: 'boolean';
44
- default: false;
45
- };
46
- init: {
47
- type: 'boolean';
48
- default: false;
49
- };
50
- createRule: {
51
- type: 'boolean';
52
- default: false;
53
- };
54
- search: {
55
- type: 'string';
56
- };
5
+ config: {
6
+ type: "string";
7
+ alias: string;
8
+ };
9
+ fix: {
10
+ type: "boolean";
11
+ default: false;
12
+ };
13
+ format: {
14
+ type: "string";
15
+ alias: string;
16
+ };
17
+ searchConfig: {
18
+ type: "boolean";
19
+ default: true;
20
+ };
21
+ ignoreExt: {
22
+ type: "boolean";
23
+ default: false;
24
+ };
25
+ importPresetRules: {
26
+ type: "boolean";
27
+ default: true;
28
+ };
29
+ locale: {
30
+ type: "string";
31
+ };
32
+ color: {
33
+ type: "boolean";
34
+ default: true;
35
+ };
36
+ problemOnly: {
37
+ type: "boolean";
38
+ alias: string;
39
+ default: false;
40
+ };
41
+ allowWarnings: {
42
+ type: "boolean";
43
+ default: false;
44
+ };
45
+ allowEmptyInput: {
46
+ type: "boolean";
47
+ default: true;
48
+ };
49
+ verbose: {
50
+ type: "boolean";
51
+ default: false;
52
+ };
53
+ init: {
54
+ type: "boolean";
55
+ default: false;
56
+ };
57
+ createRule: {
58
+ type: "boolean";
59
+ default: false;
60
+ };
61
+ search: {
62
+ type: "string";
63
+ };
57
64
  }>;
58
65
  export type CLIOptions = ReadonlyDeep<typeof cli.flags>;
@@ -11,13 +11,15 @@ Usage
11
11
  Options
12
12
  --config, -c FILE_PATH A configuration file path.
13
13
  --fix, Fix HTML.
14
- --format, -f FORMAT Output format. Support "JSON", "Simple" and "Standard". Default: "Standard".
14
+ --format, -f FORMAT Output format. Support "JSON", "Simple", "GitHub" and "Standard". Default: "Standard".
15
15
  --no-search-config No search a configure file automatically.
16
16
  --ignore-ext Evaluate files that are received even though the type of extension.
17
17
  --no-import-preset-rules No import preset rules.
18
18
  --locale Locale of the message of violation. Default is an OS setting.
19
19
  --no-color, Output no color.
20
20
  --problem-only, -p Output only problems, without passeds.
21
+ --allow-warnings Return status code 0 even if there are warnings.
22
+ --allow-empty-input Return status code 1 even if there are no input files.
21
23
  --verbose Output with detailed information.
22
24
 
23
25
  --init Initialize settings interactively.
@@ -69,6 +71,15 @@ exports.cli = (0, meow_1.default)(exports.help, {
69
71
  alias: 'p',
70
72
  default: false,
71
73
  },
74
+ allowWarnings: {
75
+ type: 'boolean',
76
+ // TODO: It will be changed to `true` in the next major version.
77
+ default: false,
78
+ },
79
+ allowEmptyInput: {
80
+ type: 'boolean',
81
+ default: true,
82
+ },
72
83
  verbose: {
73
84
  type: 'boolean',
74
85
  default: false,
@@ -18,6 +18,11 @@ async function command(files, options, apiOptions) {
18
18
  const importPresetRules = options.importPresetRules;
19
19
  const verbose = options.verbose;
20
20
  const fileList = await (0, file_resolver_1.resolveFiles)(files);
21
+ if (fileList.length === 0 && !options.allowEmptyInput) {
22
+ process.stderr.write('Markuplint: No target files.\n');
23
+ // Error
24
+ return true;
25
+ }
21
26
  if (debug_1.log.enabled) {
22
27
  (0, debug_1.log)('File list: %O', fileList.map(f => f.path));
23
28
  (0, debug_1.log)('Config: %s', configFile !== null && configFile !== void 0 ? configFile : 'N/A');
@@ -41,7 +46,9 @@ async function command(files, options, apiOptions) {
41
46
  if (!result) {
42
47
  continue;
43
48
  }
44
- if (!hasError && result.violations.length > 0) {
49
+ const errorCount = result.violations.filter(v => v.severity === 'error').length;
50
+ const warningCount = result.violations.filter(v => v.severity === 'warning').length;
51
+ if (!hasError && (errorCount > 0 || (warningCount > 0 && !options.allowWarnings))) {
45
52
  hasError = true;
46
53
  }
47
54
  if (fix) {
package/lib/cli/index.js CHANGED
@@ -44,7 +44,6 @@ const search_1 = tslib_1.__importDefault(require("./search"));
44
44
  }
45
45
  const hasError = await (0, command_1.command)(files, bootstrap_1.cli.flags).catch(err => {
46
46
  throw err;
47
- // process.exit(1);
48
47
  });
49
48
  process.exit(hasError ? 1 : 0);
50
49
  }
package/lib/cli/output.js CHANGED
@@ -16,6 +16,10 @@ function output(results, options) {
16
16
  out = (0, reporter_1.simpleReporter)(results, options);
17
17
  break;
18
18
  }
19
+ case 'github': {
20
+ out = (0, reporter_1.githubReporter)(results);
21
+ break;
22
+ }
19
23
  default: {
20
24
  out = (0, reporter_1.standardReporter)(results, options);
21
25
  }
@@ -0,0 +1,2 @@
1
+ import type { MLResultInfo } from '../types';
2
+ export declare function githubReporter(results: MLResultInfo): string[];
@@ -0,0 +1,23 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.githubReporter = void 0;
4
+ const util_1 = require("../util");
5
+ function githubReporter(results) {
6
+ const out = [];
7
+ for (const violation of results.violations) {
8
+ const command = severityToCommand(violation.severity);
9
+ const meg = (0, util_1.messageToString)(violation.message, violation.reason);
10
+ out.push(`::${command} file=${results.filePath},line=${violation.line},col=${violation.col}::${meg} (${violation.ruleId})`);
11
+ }
12
+ return out;
13
+ }
14
+ exports.githubReporter = githubReporter;
15
+ function severityToCommand(severity) {
16
+ switch (severity) {
17
+ case 'info':
18
+ return 'notice';
19
+ case 'error':
20
+ case 'warning':
21
+ return severity;
22
+ }
23
+ }
@@ -1,2 +1,3 @@
1
1
  export * from './standard-reporter';
2
2
  export * from './simple-reporter';
3
+ export * from './github-reporter';
@@ -3,3 +3,4 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const tslib_1 = require("tslib");
4
4
  tslib_1.__exportStar(require("./standard-reporter"), exports);
5
5
  tslib_1.__exportStar(require("./simple-reporter"), exports);
6
+ tslib_1.__exportStar(require("./github-reporter"), exports);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "markuplint",
3
- "version": "3.7.0",
3
+ "version": "3.9.0",
4
4
  "description": "An HTML linter for all markup developers",
5
5
  "author": "Yusuke Hirao",
6
6
  "license": "MIT",
@@ -19,26 +19,23 @@
19
19
  "dev": "tsc --build --watch",
20
20
  "clean": "tsc --build --clean"
21
21
  },
22
- "devDependencies": {
22
+ "dependencies": {
23
+ "@markuplint/create-rule-helper": "3.9.0",
24
+ "@markuplint/file-resolver": "3.9.0",
25
+ "@markuplint/html-parser": "3.7.0",
26
+ "@markuplint/html-spec": "3.8.0",
27
+ "@markuplint/i18n": "3.8.0",
28
+ "@markuplint/ml-ast": "3.1.0",
29
+ "@markuplint/ml-config": "3.8.0",
30
+ "@markuplint/ml-core": "3.9.0",
31
+ "@markuplint/ml-spec": "3.8.0",
32
+ "@markuplint/rules": "3.9.0",
33
+ "@markuplint/shared": "3.6.0",
23
34
  "@types/cli-color": "^2.0.2",
24
35
  "@types/debug": "^4.1.7",
25
36
  "@types/has-yarn": "^1.0.1",
26
37
  "@types/meow": "^6.0.0",
27
38
  "@types/uuid": "^9.0.0",
28
- "execa": "5"
29
- },
30
- "dependencies": {
31
- "@markuplint/create-rule-helper": "3.7.0",
32
- "@markuplint/file-resolver": "3.7.0",
33
- "@markuplint/html-parser": "3.6.1",
34
- "@markuplint/html-spec": "3.6.1",
35
- "@markuplint/i18n": "3.7.0",
36
- "@markuplint/ml-ast": "3.1.0",
37
- "@markuplint/ml-config": "3.6.1",
38
- "@markuplint/ml-core": "3.7.0",
39
- "@markuplint/ml-spec": "3.6.1",
40
- "@markuplint/rules": "3.7.0",
41
- "@markuplint/shared": "3.5.0",
42
39
  "chokidar": "^3.5.3",
43
40
  "cli-color": "^2.0.3",
44
41
  "debug": "^4.3.4",
@@ -51,11 +48,11 @@
51
48
  "meow": "9",
52
49
  "node-fetch": "2",
53
50
  "os-locale": "5",
54
- "strict-event-emitter": "^0.2.8",
51
+ "strict-event-emitter": "^0.5.0",
55
52
  "strip-ansi": "6",
56
53
  "tslib": "^2.4.1",
57
- "type-fest": "^3.6.1",
54
+ "type-fest": "^3.8.0",
58
55
  "uuid": "^9.0.0"
59
56
  },
60
- "gitHead": "884e8dbf60ec2a350761d5cda3cdc0725881b9dc"
57
+ "gitHead": "adc6e432cccba7cfad0dc8bf9f92e5aaf1107359"
61
58
  }