markuplint 3.5.0 → 3.6.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
@@ -47,7 +47,7 @@ Add a command to the `scripts` option on `package.json`:
47
47
  ```json
48
48
  {
49
49
  "scripts": {
50
- "html:lint": "markuplint **/*.html"
50
+ "lint:html": "markuplint **/*.html"
51
51
  }
52
52
  }
53
53
  ```
@@ -57,9 +57,9 @@ If you want to change the target path, you can change it for your project.
57
57
  Execute the script:
58
58
 
59
59
  ```
60
- $ npm run html:lint
60
+ $ npm run lint:html
61
61
  # or
62
- $ yarn html:lint
62
+ $ yarn lint:html
63
63
  ```
64
64
 
65
65
  ### Command line options
@@ -5,27 +5,27 @@ import type { PlainData } from '@markuplint/ml-config';
5
5
  import type { Document, RuleConfigValue } from '@markuplint/ml-core';
6
6
  import { StrictEventEmitter } from 'strict-event-emitter';
7
7
  type MLEngineOptions = {
8
- readonly debug?: boolean;
9
- readonly watch?: boolean;
8
+ readonly debug?: boolean;
9
+ readonly watch?: boolean;
10
10
  };
11
11
  export default class MLEngine extends StrictEventEmitter<MLEngineEventMap> {
12
- #private;
13
- static toMLFile(target: Target): Promise<MLFile | undefined>;
14
- constructor(file: Readonly<MLFile>, options?: APIOptions & MLEngineOptions);
15
- get document(): Document<RuleConfigValue, PlainData> | null;
16
- close(): Promise<void>;
17
- exec(): Promise<MLResultInfo | null>;
18
- setCode(code: string): Promise<void>;
19
- watchMode(enable: boolean): void;
20
- private createCore;
21
- private i18n;
22
- private onChange;
23
- private provide;
24
- private resolveConfig;
25
- private resolveParser;
26
- private resolveRules;
27
- private resolveRuleset;
28
- private resolveSchemas;
29
- private setup;
12
+ #private;
13
+ static toMLFile(target: Target): Promise<MLFile | undefined>;
14
+ constructor(file: Readonly<MLFile>, options?: APIOptions & MLEngineOptions);
15
+ get document(): Document<RuleConfigValue, PlainData> | null;
16
+ close(): Promise<void>;
17
+ exec(): Promise<MLResultInfo | null>;
18
+ setCode(code: string): Promise<void>;
19
+ watchMode(enable: boolean): void;
20
+ private createCore;
21
+ private i18n;
22
+ private onChange;
23
+ private provide;
24
+ private resolveConfig;
25
+ private resolveParser;
26
+ private resolveRules;
27
+ private resolveRuleset;
28
+ private resolveSchemas;
29
+ private setup;
30
30
  }
31
31
  export {};
@@ -79,7 +79,7 @@ class MLEngine extends strict_event_emitter_1.StrictEventEmitter {
79
79
  fixedCode,
80
80
  };
81
81
  }
82
- const debugMap = ('debugMap' in core.document && core.document.debugMap()) || null;
82
+ const debugMap = 'debugMap' in core.document ? core.document.debugMap() : null;
83
83
  this.emit('lint', tslib_1.__classPrivateFieldGet(this, _MLEngine_file, "f").path, sourceCode, violations, fixedCode, debugMap);
84
84
  log('exec: end');
85
85
  return {
@@ -150,7 +150,7 @@ class MLEngine extends strict_event_emitter_1.StrictEventEmitter {
150
150
  await this.exec();
151
151
  }
152
152
  async provide(cache = true) {
153
- var _a, _b, _c;
153
+ var _a, _b, _c, _d;
154
154
  const configSet = await this.resolveConfig(cache);
155
155
  fileLog('Fetched Config files: %O', configSet.files);
156
156
  fileLog('Resolved Config: %O', configSet.config);
@@ -162,7 +162,7 @@ class MLEngine extends strict_event_emitter_1.StrictEventEmitter {
162
162
  return null;
163
163
  }
164
164
  // Exclude
165
- const excludeFiles = configSet.config.excludeFiles || [];
165
+ const excludeFiles = (_a = configSet.config.excludeFiles) !== null && _a !== void 0 ? _a : [];
166
166
  for (const excludeFile of excludeFiles) {
167
167
  if (tslib_1.__classPrivateFieldGet(this, _MLEngine_file, "f").matches(excludeFile)) {
168
168
  this.emit('exclude', tslib_1.__classPrivateFieldGet(this, _MLEngine_file, "f").path, excludeFile);
@@ -171,7 +171,7 @@ class MLEngine extends strict_event_emitter_1.StrictEventEmitter {
171
171
  }
172
172
  }
173
173
  const { parser, parserOptions, matched } = await this.resolveParser(configSet);
174
- const checkingExt = !((_a = tslib_1.__classPrivateFieldGet(this, _MLEngine_options, "f")) === null || _a === void 0 ? void 0 : _a.ignoreExt);
174
+ const checkingExt = !((_b = tslib_1.__classPrivateFieldGet(this, _MLEngine_options, "f")) === null || _b === void 0 ? void 0 : _b.ignoreExt);
175
175
  if (checkingExt && !matched) {
176
176
  this.emit('log', 'ext-unmatched', `Avoided linting because a file is unmatched by the extension: ${tslib_1.__classPrivateFieldGet(this, _MLEngine_file, "f").path}`);
177
177
  fileLog('Avoided linting because a file is unmatched by the extension: %s', tslib_1.__classPrivateFieldGet(this, _MLEngine_file, "f").path);
@@ -181,7 +181,7 @@ class MLEngine extends strict_event_emitter_1.StrictEventEmitter {
181
181
  fileLog('Resolved ruleset: %O', ruleset);
182
182
  const schemas = await this.resolveSchemas(configSet);
183
183
  if (fileLog.enabled) {
184
- if (schemas[0].cites.length) {
184
+ if (schemas[0].cites.length > 0) {
185
185
  const [, ...additionalSpecs] = schemas;
186
186
  fileLog('Resolved schemas: HTML Standard');
187
187
  for (const additionalSpec of additionalSpecs) {
@@ -194,14 +194,14 @@ class MLEngine extends strict_event_emitter_1.StrictEventEmitter {
194
194
  }
195
195
  const rules = await this.resolveRules(configSet.plugins, ruleset);
196
196
  fileLog('Resolved rules: %O', rules);
197
- const locale = await (0, i18n_1.i18n)((_b = tslib_1.__classPrivateFieldGet(this, _MLEngine_options, "f")) === null || _b === void 0 ? void 0 : _b.locale);
197
+ const locale = await (0, i18n_1.i18n)((_c = tslib_1.__classPrivateFieldGet(this, _MLEngine_options, "f")) === null || _c === void 0 ? void 0 : _c.locale);
198
198
  if (fileLog.enabled) {
199
199
  fileLog('Loaded %d rules: %O', rules.length, rules.map(r => r.name));
200
200
  }
201
201
  return {
202
202
  parser,
203
203
  parserOptions,
204
- pretenders: (_c = configSet.config.pretenders) !== null && _c !== void 0 ? _c : [],
204
+ pretenders: (_d = configSet.config.pretenders) !== null && _d !== void 0 ? _d : [],
205
205
  ruleset,
206
206
  schemas,
207
207
  rules,
@@ -210,16 +210,16 @@ class MLEngine extends strict_event_emitter_1.StrictEventEmitter {
210
210
  };
211
211
  }
212
212
  async resolveConfig(cache) {
213
- var _a, _b, _c, _d, _e, _f;
213
+ var _a, _b, _c, _d, _e, _f, _g;
214
214
  const defaultConfigKey = ((_a = tslib_1.__classPrivateFieldGet(this, _MLEngine_options, "f")) === null || _a === void 0 ? void 0 : _a.defaultConfig) && tslib_1.__classPrivateFieldGet(this, _MLEngine_configProvider, "f").set((_b = tslib_1.__classPrivateFieldGet(this, _MLEngine_options, "f")) === null || _b === void 0 ? void 0 : _b.defaultConfig);
215
215
  configLog('defaultConfigKey: %s', defaultConfigKey !== null && defaultConfigKey !== void 0 ? defaultConfigKey : 'N/A');
216
216
  this.emit('log', 'defaultConfigKey', defaultConfigKey !== null && defaultConfigKey !== void 0 ? defaultConfigKey : 'N/A');
217
217
  const configFilePathsFromTarget = ((_c = tslib_1.__classPrivateFieldGet(this, _MLEngine_options, "f")) === null || _c === void 0 ? void 0 : _c.noSearchConfig)
218
218
  ? defaultConfigKey !== null && defaultConfigKey !== void 0 ? defaultConfigKey : null
219
- : (await tslib_1.__classPrivateFieldGet(this, _MLEngine_configProvider, "f").search(tslib_1.__classPrivateFieldGet(this, _MLEngine_file, "f"))) || defaultConfigKey;
219
+ : (_d = (await tslib_1.__classPrivateFieldGet(this, _MLEngine_configProvider, "f").search(tslib_1.__classPrivateFieldGet(this, _MLEngine_file, "f")))) !== null && _d !== void 0 ? _d : defaultConfigKey;
220
220
  configLog('configFilePathsFromTarget: %s', configFilePathsFromTarget !== null && configFilePathsFromTarget !== void 0 ? configFilePathsFromTarget : 'N/A');
221
221
  this.emit('log', 'configFilePathsFromTarget', configFilePathsFromTarget !== null && configFilePathsFromTarget !== void 0 ? configFilePathsFromTarget : 'N/A');
222
- const configKey = ((_d = tslib_1.__classPrivateFieldGet(this, _MLEngine_options, "f")) === null || _d === void 0 ? void 0 : _d.config) && tslib_1.__classPrivateFieldGet(this, _MLEngine_configProvider, "f").set(tslib_1.__classPrivateFieldGet(this, _MLEngine_options, "f").config);
222
+ const configKey = ((_e = tslib_1.__classPrivateFieldGet(this, _MLEngine_options, "f")) === null || _e === void 0 ? void 0 : _e.config) && tslib_1.__classPrivateFieldGet(this, _MLEngine_configProvider, "f").set(tslib_1.__classPrivateFieldGet(this, _MLEngine_options, "f").config);
223
223
  configLog('option.config: %s', configKey !== null && configKey !== void 0 ? configKey : 'N/A');
224
224
  this.emit('log', 'option.config', configFilePathsFromTarget !== null && configFilePathsFromTarget !== void 0 ? configFilePathsFromTarget : 'N/A');
225
225
  let defaultRecommended = null;
@@ -230,9 +230,9 @@ class MLEngine extends strict_event_emitter_1.StrictEventEmitter {
230
230
  }
231
231
  configLog('defaultRecommended: %s', defaultRecommended !== null && defaultRecommended !== void 0 ? defaultRecommended : 'N/A');
232
232
  this.emit('log', 'defaultRecommended', defaultRecommended !== null && defaultRecommended !== void 0 ? defaultRecommended : 'N/A');
233
- const configSet = await tslib_1.__classPrivateFieldGet(this, _MLEngine_configProvider, "f").resolve(tslib_1.__classPrivateFieldGet(this, _MLEngine_file, "f"), [configFilePathsFromTarget, (_e = tslib_1.__classPrivateFieldGet(this, _MLEngine_options, "f")) === null || _e === void 0 ? void 0 : _e.configFile, configKey, defaultRecommended], cache);
233
+ const configSet = await tslib_1.__classPrivateFieldGet(this, _MLEngine_configProvider, "f").resolve(tslib_1.__classPrivateFieldGet(this, _MLEngine_file, "f"), [configFilePathsFromTarget, (_f = tslib_1.__classPrivateFieldGet(this, _MLEngine_options, "f")) === null || _f === void 0 ? void 0 : _f.configFile, configKey, defaultRecommended], cache);
234
234
  this.emit('config', tslib_1.__classPrivateFieldGet(this, _MLEngine_file, "f").path, configSet);
235
- if ((_f = tslib_1.__classPrivateFieldGet(this, _MLEngine_options, "f")) === null || _f === void 0 ? void 0 : _f.watch) {
235
+ if ((_g = tslib_1.__classPrivateFieldGet(this, _MLEngine_options, "f")) === null || _g === void 0 ? void 0 : _g.watch) {
236
236
  // It doesn't watch the main HTML file because it may is watched and managed by a language server or text editor or more.
237
237
  tslib_1.__classPrivateFieldGet(this, _MLEngine_watcher, "f").add(Array.from(configSet.files));
238
238
  }
@@ -3,31 +3,38 @@ import type { LocaleSet } from '@markuplint/i18n';
3
3
  import type { Config, Violation } from '@markuplint/ml-config';
4
4
  import type { AnyMLRule, MLSchema, Ruleset } from '@markuplint/ml-core';
5
5
  export type APIOptions = {
6
- readonly configFile?: string;
7
- readonly config?: Config;
8
- readonly defaultConfig?: Config;
9
- readonly noSearchConfig?: boolean;
10
- readonly locale?: string;
11
- readonly fix?: boolean;
12
- readonly ignoreExt?: boolean;
13
- readonly rules?: readonly Readonly<AnyMLRule>[];
14
- readonly importPresetRules?: boolean;
15
- /**
16
- * @deprecated
17
- */
18
- readonly autoLoad?: boolean;
6
+ readonly configFile?: string;
7
+ readonly config?: Config;
8
+ readonly defaultConfig?: Config;
9
+ readonly noSearchConfig?: boolean;
10
+ readonly locale?: string;
11
+ readonly fix?: boolean;
12
+ readonly ignoreExt?: boolean;
13
+ readonly rules?: readonly Readonly<AnyMLRule>[];
14
+ readonly importPresetRules?: boolean;
15
+ /**
16
+ * @deprecated
17
+ */
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: (filePath: string, sourceCode: string, violations: readonly Violation[], fixedCode: string, debug: readonly string[] | null, message?: string) => void;
31
- 'lint-error': (filePath: string, sourceCode: string, error: Readonly<Error>) => void;
32
- 'config-errors': (filePath: string, errors: readonly Readonly<Error>[]) => void;
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: (
31
+ filePath: string,
32
+ sourceCode: string,
33
+ violations: readonly Violation[],
34
+ fixedCode: string,
35
+ debug: readonly string[] | null,
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;
33
40
  };
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('..').MLResultInfo[]>;
package/lib/api/v1.js CHANGED
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.lint_v1 = void 0;
4
+ const shared_1 = require("@markuplint/shared");
4
5
  const lint_1 = require("./lint");
5
6
  /**
6
7
  * @deprecated
@@ -9,12 +10,8 @@ const lint_1 = require("./lint");
9
10
  */
10
11
  async function lint_v1(options) {
11
12
  var _a;
12
- const filePathList = options.files ? (Array.isArray(options.files) ? options.files : [options.files]) : [];
13
- const codes = options.sourceCodes
14
- ? Array.isArray(options.sourceCodes)
15
- ? options.sourceCodes
16
- : [options.sourceCodes]
17
- : [];
13
+ const filePathList = (0, shared_1.toNoEmptyStringArrayFromStringOrArray)(options.files);
14
+ const codes = (0, shared_1.toNoEmptyStringArrayFromStringOrArray)(options.sourceCodes);
18
15
  const files = [
19
16
  ...filePathList,
20
17
  ...codes.map((code, i) => {
@@ -37,7 +34,7 @@ async function lint_v1(options) {
37
34
  const result = await (0, lint_1.lint)(files, {
38
35
  config,
39
36
  configFile,
40
- noSearchConfig: !options.files,
37
+ noSearchConfig: filePathList.length === 0,
41
38
  rules: options.rules,
42
39
  autoLoad: (_a = options.rulesAutoResolve) !== null && _a !== void 0 ? _a : true,
43
40
  locale: options.locale,
@@ -1,57 +1,58 @@
1
1
  import type { ReadonlyDeep } from 'type-fest';
2
2
  import meow from 'meow';
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\" 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 =
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';
4
5
  export declare const cli: meow.Result<{
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
- verbose: {
42
- type: "boolean";
43
- default: false;
44
- };
45
- init: {
46
- type: "boolean";
47
- default: false;
48
- };
49
- createRule: {
50
- type: "boolean";
51
- default: false;
52
- };
53
- search: {
54
- type: "string";
55
- };
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
+ };
56
57
  }>;
57
58
  export type CLIOptions = ReadonlyDeep<typeof cli.flags>;
@@ -1,4 +1,8 @@
1
1
  import type { CLIOptions } from './bootstrap';
2
2
  import type { APIOptions } from '../api/types';
3
3
  import type { Target } from '@markuplint/file-resolver';
4
- export declare function command(files: readonly Readonly<Target>[], options: CLIOptions, apiOptions?: APIOptions): Promise<boolean>;
4
+ export declare function command(
5
+ files: readonly Readonly<Target>[],
6
+ options: CLIOptions,
7
+ apiOptions?: APIOptions,
8
+ ): Promise<boolean>;
@@ -20,7 +20,7 @@ async function command(files, options, apiOptions) {
20
20
  const fileList = await (0, file_resolver_1.resolveFiles)(files);
21
21
  if (debug_1.log.enabled) {
22
22
  (0, debug_1.log)('File list: %O', fileList.map(f => f.path));
23
- (0, debug_1.log)('Config: %s', configFile || 'N/A');
23
+ (0, debug_1.log)('Config: %s', configFile !== null && configFile !== void 0 ? configFile : 'N/A');
24
24
  (0, debug_1.log)('Fix option: %s', fix);
25
25
  }
26
26
  const format = (_a = options.format) === null || _a === void 0 ? void 0 : _a.toLowerCase().trim();
@@ -41,7 +41,7 @@ async function command(files, options, apiOptions) {
41
41
  if (!result) {
42
42
  continue;
43
43
  }
44
- if (!hasError && result.violations.length) {
44
+ if (!hasError && result.violations.length > 0) {
45
45
  hasError = true;
46
46
  }
47
47
  if (fix) {
@@ -69,10 +69,10 @@ async function createRule() {
69
69
  for (const file of result.files) {
70
70
  output(pluginName || 'core', file.test ? '🖍 ' : (_a = icons[file.name]) !== null && _a !== void 0 ? _a : '🛡 ', file.fileName, (0, node_path_1.resolve)(file.destDir, file.fileName + file.ext));
71
71
  }
72
- if (result.dependencies.length) {
72
+ if (result.dependencies.length > 0) {
73
73
  await (0, install_module_1.installModule)(result.dependencies);
74
74
  }
75
- if (result.devDependencies.length) {
75
+ if (result.devDependencies.length > 0) {
76
76
  await (0, install_module_1.installModule)(result.devDependencies, true);
77
77
  }
78
78
  }
package/lib/cli/index.js CHANGED
@@ -34,7 +34,7 @@ const search_1 = tslib_1.__importDefault(require("./search"));
34
34
  return;
35
35
  }
36
36
  const files = bootstrap_1.cli.input;
37
- if (files.length) {
37
+ if (files.length > 0) {
38
38
  if (bootstrap_1.cli.flags.search) {
39
39
  await (0, search_1.default)(files, bootstrap_1.cli.flags, bootstrap_1.cli.flags.search).catch(err => {
40
40
  process.stderr.write(err + '\n');
@@ -1,4 +1,8 @@
1
1
  import type { DefaultRules, Langs, RuleSettingMode } from './types';
2
2
  import type { Config } from '@markuplint/ml-config';
3
3
  export declare const langs: Record<Langs, string>;
4
- export declare function createConfig(langs: readonly Langs[], mode: RuleSettingMode, defaultRules: DefaultRules): Config;
4
+ export declare function createConfig(
5
+ langs: readonly Langs[],
6
+ mode: RuleSettingMode,
7
+ defaultRules: DefaultRules,
8
+ ): Config;
@@ -30,6 +30,7 @@ exports.langs = {
30
30
  liquid: 'liquid (Shopify)',
31
31
  };
32
32
  function createConfig(langs, mode, defaultRules) {
33
+ var _a;
33
34
  let config = {};
34
35
  const parser = { ...config.parser };
35
36
  for (const lang of langs) {
@@ -57,7 +58,7 @@ function createConfig(langs, mode, defaultRules) {
57
58
  };
58
59
  }
59
60
  }
60
- if (Object.keys(parser).length) {
61
+ if (Object.keys(parser).length > 0) {
61
62
  config.parser = parser;
62
63
  }
63
64
  const rules = { ...config.rules };
@@ -74,7 +75,7 @@ function createConfig(langs, mode, defaultRules) {
74
75
  }
75
76
  }
76
77
  else if (mode === 'recommended') {
77
- config.extends = [...(config.extends || []), 'markuplint:recommended'];
78
+ config.extends = [...((_a = config.extends) !== null && _a !== void 0 ? _a : []), 'markuplint:recommended'];
78
79
  }
79
80
  else {
80
81
  const ruleNames = Object.keys(defaultRules);
@@ -86,7 +87,7 @@ function createConfig(langs, mode, defaultRules) {
86
87
  rules[ruleName] = rule.defaultValue;
87
88
  }
88
89
  }
89
- if (Object.keys(rules).length) {
90
+ if (Object.keys(rules).length > 0) {
90
91
  config.rules = rules;
91
92
  }
92
93
  return config;
@@ -1,3 +1,3 @@
1
1
  export declare function getDefaultRules(version: string): Promise<{
2
- [x: string]: import("./types").Rule;
2
+ [x: string]: import('./types').Rule;
3
3
  }>;
@@ -1,7 +1,7 @@
1
1
  import type { Langs } from './types';
2
2
  export type InstallModuleResult = {
3
- success: boolean;
4
- alreadyExists: boolean;
3
+ success: boolean;
4
+ alreadyExists: boolean;
5
5
  };
6
6
  export declare function selectModules(selectedLangs: readonly Langs[]): string[];
7
7
  export declare function installModule(module: readonly string[], dev?: boolean): Promise<InstallModuleResult>;
@@ -32,7 +32,7 @@ async function installModule(module, dev = false) {
32
32
  catch (_) {
33
33
  // void
34
34
  }
35
- if (!uninstallMods.length) {
35
+ if (uninstallMods.length === 0) {
36
36
  return {
37
37
  success: true,
38
38
  alreadyExists: true,
@@ -1,8 +1,20 @@
1
- export type Langs = 'jsx' | 'vue' | 'svelte' | 'astro' | 'pug' | 'php' | 'smarty' | 'erb' | 'ejs' | 'mustache' | 'nunjucks' | 'liquid';
1
+ export type Langs =
2
+ | 'jsx'
3
+ | 'vue'
4
+ | 'svelte'
5
+ | 'astro'
6
+ | 'pug'
7
+ | 'php'
8
+ | 'smarty'
9
+ | 'erb'
10
+ | 'ejs'
11
+ | 'mustache'
12
+ | 'nunjucks'
13
+ | 'liquid';
2
14
  export type Category = 'validation' | 'a11y' | 'naming-convention' | 'style' | 'maintainability';
3
15
  export type RuleSettingMode = readonly Category[] | 'recommended' | 'none';
4
16
  export type DefaultRules = Readonly<Record<string, Rule>>;
5
17
  export type Rule = {
6
- readonly category: Category;
7
- readonly defaultValue: boolean | string | number;
18
+ readonly category: Category;
19
+ readonly defaultValue: boolean | string | number;
8
20
  };
package/lib/cli/output.js CHANGED
@@ -20,13 +20,13 @@ function output(results, options) {
20
20
  out = (0, reporter_1.standardReporter)(results, options);
21
21
  }
22
22
  }
23
- if (!out.length) {
23
+ if (out.length === 0) {
24
24
  return;
25
25
  }
26
26
  let msg = `${out.join('\n')}\n`;
27
27
  msg = options.color ? msg : (0, strip_ansi_1.default)(msg);
28
28
  // If it has errors, Write to `stderr` and failure and exit.
29
- if (results.violations.length) {
29
+ if (results.violations.length > 0) {
30
30
  process.stderr.write(msg);
31
31
  process.exitCode = 1;
32
32
  return;
@@ -1,18 +1,23 @@
1
1
  type SelectQuestion<T> = {
2
- readonly message: string;
3
- readonly choices: readonly {
4
- readonly name: string;
5
- readonly value: T;
6
- }[];
2
+ readonly message: string;
3
+ readonly choices: readonly {
4
+ readonly name: string;
5
+ readonly value: T;
6
+ }[];
7
7
  };
8
8
  export declare function select<T>(question: SelectQuestion<T>): Promise<T>;
9
9
  export declare function multiSelect<T>(question: SelectQuestion<T>): Promise<T[]>;
10
10
  export declare function input<T extends string = string>(question: string, validation?: Readonly<RegExp>): Promise<T>;
11
- export declare function confirm(question: string, options?: {
12
- readonly initial?: boolean;
13
- }): Promise<boolean>;
14
- export declare function confirmSequence<T extends string = string>(questions: readonly {
15
- readonly message: string;
16
- readonly name: T;
17
- }[]): Promise<Record<T, boolean>>;
11
+ export declare function confirm(
12
+ question: string,
13
+ options?: {
14
+ readonly initial?: boolean;
15
+ },
16
+ ): Promise<boolean>;
17
+ export declare function confirmSequence<T extends string = string>(
18
+ questions: readonly {
19
+ readonly message: string;
20
+ readonly name: T;
21
+ }[],
22
+ ): Promise<Record<T, boolean>>;
18
23
  export {};
@@ -17,8 +17,9 @@ async function default_1(files, options, selectors) {
17
17
  verify({ document }) {
18
18
  const nodes = document.querySelectorAll(selectors);
19
19
  locations.push(...Array.from(nodes).map(node => {
20
+ var _a;
20
21
  return {
21
- file: document.filename || '_NO_FILE_',
22
+ file: (_a = document.filename) !== null && _a !== void 0 ? _a : '_NO_FILE_',
22
23
  line: node.startLine,
23
24
  col: node.startCol,
24
25
  };
@@ -1,5 +1,5 @@
1
1
  export type GlobalSettings = {
2
- readonly locale: string;
2
+ readonly locale: string;
3
3
  };
4
4
  export declare function setGlobal(settings: Partial<GlobalSettings>): void;
5
5
  export declare function getGlobal(): Readonly<Partial<GlobalSettings>>;
package/lib/i18n.js CHANGED
@@ -11,13 +11,13 @@ async function getLocale() {
11
11
  return cachedLocale;
12
12
  }
13
13
  async function i18n(locale) {
14
- var _a;
15
- locale = locale || (await getLocale()) || 'en';
16
- const langCode = (_a = locale.split('-')[0]) !== null && _a !== void 0 ? _a : locale;
14
+ var _a, _b;
15
+ locale = (_a = locale !== null && locale !== void 0 ? locale : (await getLocale())) !== null && _a !== void 0 ? _a : 'en';
16
+ const langCode = (_b = locale.split('-')[0]) !== null && _b !== void 0 ? _b : locale;
17
17
  const loadLocaleSet = await Promise.resolve(`${`@markuplint/i18n/locales/${langCode}`}`).then(s => tslib_1.__importStar(require(s))).catch(() => null);
18
- const localeSet = loadLocaleSet ||
19
- // @ts-ignore
20
- (await Promise.resolve().then(() => tslib_1.__importStar(require('@markuplint/i18n/locales/en'))));
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'))));
21
21
  return {
22
22
  ...localeSet,
23
23
  locale: loadLocaleSet ? langCode : 'en',
@@ -19,7 +19,7 @@ function simpleReporter(results, options) {
19
19
  sizes.meg = Math.max(sizes.meg, (0, util_1.w)(meg));
20
20
  }
21
21
  const out = [];
22
- if (results.violations.length) {
22
+ if (results.violations.length > 0) {
23
23
  out.push(`<${util_1.markuplint}> ${cli_color_1.default.underline(results.filePath)}: ${loggerError('✗')}`);
24
24
  for (const violation of results.violations) {
25
25
  const s = violation.severity === 'error' ? loggerError('✖') : loggerWarning('⚠️');
@@ -7,6 +7,7 @@ const util_1 = require("../util");
7
7
  const loggerError = cli_color_1.default.red;
8
8
  const loggerWarning = cli_color_1.default.xterm(208);
9
9
  function standardReporter(results, options) {
10
+ var _a, _b, _c;
10
11
  const sizes = {
11
12
  line: 0,
12
13
  col: 0,
@@ -19,12 +20,12 @@ function standardReporter(results, options) {
19
20
  sizes.meg = Math.max(sizes.meg, (0, util_1.w)(meg));
20
21
  }
21
22
  const out = [];
22
- if (results.violations.length) {
23
+ if (results.violations.length > 0) {
23
24
  const lines = results.sourceCode.split(/\r?\n/g);
24
25
  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] || '';
26
+ const prev = (_a = lines[violation.line - 2]) !== null && _a !== void 0 ? _a : '';
27
+ const line = (_b = lines[violation.line - 1]) !== null && _b !== void 0 ? _b : '';
28
+ const next = (_c = lines[violation.line - 0]) !== null && _c !== void 0 ? _c : '';
28
29
  const before = line.substring(0, violation.col - 1);
29
30
  const after = line.substring(violation.col - 1 + violation.raw.length);
30
31
  const logger = violation.severity === 'error' ? loggerError : loggerWarning;
@@ -1,33 +1,51 @@
1
1
  import type { Target } from '@markuplint/file-resolver';
2
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?: readonly Readonly<AnyMLRule>[], locale?: string, fix?: boolean): Promise<{
5
- violations: readonly import("@markuplint/ml-config").Violation[];
6
- fixedCode: string;
4
+ export declare function mlTest(
5
+ sourceCode: string,
6
+ config: Config,
7
+ rules?: readonly Readonly<AnyMLRule>[],
8
+ locale?: string,
9
+ fix?: boolean,
10
+ ): Promise<{
11
+ violations: readonly import('@markuplint/ml-config').Violation[];
12
+ fixedCode: string;
7
13
  }>;
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
- rule?: Rule<T, Partial<O>>;
10
- nodeRule?: NodeRule<T, Partial<O>>[];
11
- childNodeRule?: ChildNodeRule<T, Partial<O>>[];
12
- }, fix?: boolean, locale?: string): Promise<{
13
- violations: readonly import("@markuplint/ml-config").Violation[];
14
- fixedCode: string;
14
+ export declare function mlRuleTest<T extends RuleConfigValue, O extends PlainData>(
15
+ rule: Readonly<RuleSeed<T, O>>,
16
+ sourceCode: string,
17
+ config?: Omit<Config, 'rules' | 'nodeRules' | 'childNodeRules'> & {
18
+ rule?: Rule<T, Partial<O>>;
19
+ nodeRule?: NodeRule<T, Partial<O>>[];
20
+ childNodeRule?: ChildNodeRule<T, Partial<O>>[];
21
+ },
22
+ fix?: boolean,
23
+ locale?: string,
24
+ ): Promise<{
25
+ violations: readonly import('@markuplint/ml-config').Violation[];
26
+ fixedCode: string;
15
27
  }>;
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;
28
+ export declare function mlTestFile(
29
+ target: Target,
30
+ config?: Config,
31
+ rules?: readonly Readonly<AnyMLRule>[],
32
+ locale?: string,
33
+ fix?: boolean,
34
+ ): Promise<{
35
+ violations: readonly import('@markuplint/ml-config').Violation[];
36
+ fixedCode: string | undefined;
19
37
  }>;
20
38
  export interface NodeRule<T extends RuleConfigValue, O extends PlainData = undefined> {
21
- selector?: string;
22
- regexSelector?: RegexSelector;
23
- categories?: string[];
24
- roles?: string[];
25
- obsolete?: boolean;
26
- rule?: Rule<T, O>;
39
+ selector?: string;
40
+ regexSelector?: RegexSelector;
41
+ categories?: string[];
42
+ roles?: string[];
43
+ obsolete?: boolean;
44
+ rule?: Rule<T, O>;
27
45
  }
28
46
  export interface ChildNodeRule<T extends RuleConfigValue, O extends PlainData = undefined> {
29
- selector?: string;
30
- regexSelector?: RegexSelector;
31
- inheritance?: boolean;
32
- rule?: Rule<T, O>;
47
+ selector?: string;
48
+ regexSelector?: RegexSelector;
49
+ inheritance?: boolean;
50
+ rule?: Rule<T, O>;
33
51
  }
package/lib/types.d.ts CHANGED
@@ -1,27 +1,26 @@
1
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
- readonly violations: readonly Violation[];
5
- readonly filePath: string;
6
- readonly sourceCode: string;
7
- readonly 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
11
11
  */
12
12
  export interface MLResultInfo_v1 {
13
- results: Violation[];
14
- filePath: string;
15
- sourceCode: string;
16
- fixedCode: string;
17
- document: Document<RuleConfigValue, PlainData> | 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<RuleConfigValue, PlainData> | 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
- export type Nullable<T> = T | null | undefined;
package/lib/util.d.ts CHANGED
@@ -1,15 +1,13 @@
1
- import type { Nullable } from './types';
2
- export declare function nonNullableFilter<T>(item: Nullable<T>): item is T;
3
1
  export declare function uuid(): string;
4
2
  export declare const markuplint: string;
5
3
  export declare function write(message: string): void;
6
4
  export declare namespace write {
7
- var _a: () => boolean;
8
- export { _a as break };
5
+ var _a: () => boolean;
6
+ export { _a as break };
9
7
  }
10
8
  export declare function error(message: string): void;
11
9
  export declare namespace error {
12
- var exit: () => never;
10
+ var exit: () => never;
13
11
  }
14
12
  export declare const head: (method: string, noColor?: boolean) => string;
15
13
  export declare function p(s: number | string, pad: number, start?: boolean): string;
package/lib/util.js CHANGED
@@ -1,16 +1,12 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.messageToString = exports.invisibleSpace = exports.space = exports.w = exports.p = exports.head = exports.error = exports.write = exports.markuplint = exports.uuid = exports.nonNullableFilter = void 0;
3
+ exports.messageToString = exports.invisibleSpace = exports.space = exports.w = exports.p = exports.head = exports.error = exports.write = exports.markuplint = exports.uuid = void 0;
4
4
  const tslib_1 = require("tslib");
5
5
  const cli_color_1 = tslib_1.__importDefault(require("cli-color"));
6
6
  // @ts-ignore
7
7
  const eastasianwidth_1 = tslib_1.__importDefault(require("eastasianwidth"));
8
8
  const strip_ansi_1 = tslib_1.__importDefault(require("strip-ansi"));
9
9
  const uuid_1 = require("uuid");
10
- function nonNullableFilter(item) {
11
- return !!item;
12
- }
13
- exports.nonNullableFilter = nonNullableFilter;
14
10
  function uuid() {
15
11
  return (0, uuid_1.v4)();
16
12
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "markuplint",
3
- "version": "3.5.0",
3
+ "version": "3.6.0",
4
4
  "description": "An HTML linter for all markup developers",
5
5
  "author": "Yusuke Hirao",
6
6
  "license": "MIT",
@@ -28,16 +28,17 @@
28
28
  "execa": "5"
29
29
  },
30
30
  "dependencies": {
31
- "@markuplint/create-rule-helper": "3.5.0",
32
- "@markuplint/file-resolver": "3.5.0",
33
- "@markuplint/html-parser": "3.5.0",
34
- "@markuplint/html-spec": "3.5.0",
35
- "@markuplint/i18n": "3.5.0",
31
+ "@markuplint/create-rule-helper": "3.6.0",
32
+ "@markuplint/file-resolver": "3.6.0",
33
+ "@markuplint/html-parser": "3.6.0",
34
+ "@markuplint/html-spec": "3.6.0",
35
+ "@markuplint/i18n": "3.6.0",
36
36
  "@markuplint/ml-ast": "3.1.0",
37
- "@markuplint/ml-config": "3.5.0",
38
- "@markuplint/ml-core": "3.5.0",
39
- "@markuplint/ml-spec": "3.5.0",
40
- "@markuplint/rules": "3.5.0",
37
+ "@markuplint/ml-config": "3.6.0",
38
+ "@markuplint/ml-core": "3.6.0",
39
+ "@markuplint/ml-spec": "3.6.0",
40
+ "@markuplint/rules": "3.6.0",
41
+ "@markuplint/shared": "3.5.0",
41
42
  "chokidar": "^3.5.3",
42
43
  "cli-color": "^2.0.3",
43
44
  "debug": "^4.3.4",
@@ -56,5 +57,5 @@
56
57
  "type-fest": "^3.6.1",
57
58
  "uuid": "^9.0.0"
58
59
  },
59
- "gitHead": "0c47b2c2722f6823a17f36edbab98486275f8ab4"
60
+ "gitHead": "715dd53d3b1064a9bcf616c1533921cad9e3b187"
60
61
  }