@huangjunsen/encode-fe-lint 1.0.6 → 1.0.8

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 (77) hide show
  1. package/lib/actions/init.d.ts +3 -3
  2. package/lib/actions/init.js +168 -223
  3. package/lib/actions/scan.d.ts +3 -3
  4. package/lib/actions/scan.js +63 -137
  5. package/lib/actions/update.d.ts +2 -2
  6. package/lib/actions/update.js +51 -112
  7. package/lib/cli.d.ts +2 -2
  8. package/lib/cli.js +152 -230
  9. package/lib/config/_editorconfig.ejs +13 -13
  10. package/lib/config/_eslintignore.ejs +9 -9
  11. package/lib/config/_eslintrc.js.ejs +21 -3
  12. package/lib/config/_markdownlint.json.ejs +1 -1
  13. package/lib/config/_markdownlintignore.ejs +5 -5
  14. package/lib/config/_prettierrc.js.ejs +3 -8
  15. package/lib/config/_stylelintignore.ejs +5 -5
  16. package/lib/config/_stylelintrc.js.ejs +5 -5
  17. package/lib/config/_vscode/extensions.json.ejs +7 -7
  18. package/lib/config/_vscode/settings.json.ejs +55 -54
  19. package/lib/config/commitlint.config.js.ejs +3 -3
  20. package/lib/config/encode-fe-lint.config.js.ejs +6 -6
  21. package/lib/config/eslint.config.mjs.ejs +5 -0
  22. package/lib/index.d.ts +5 -5
  23. package/lib/index.js +36 -93
  24. package/lib/lints/eslint/doEslint.d.ts +6 -6
  25. package/lib/lints/eslint/doEslint.js +44 -80
  26. package/lib/lints/eslint/formatESLintResults.d.ts +3 -3
  27. package/lib/lints/eslint/formatESLintResults.js +28 -39
  28. package/lib/lints/eslint/getESLintConfig.d.ts +3 -3
  29. package/lib/lints/eslint/getESLintConfig.js +43 -67
  30. package/lib/lints/eslint/getESLintConfigType.d.ts +2 -2
  31. package/lib/lints/eslint/getESLintConfigType.js +23 -26
  32. package/lib/lints/eslint/index.d.ts +3 -3
  33. package/lib/lints/eslint/index.js +19 -19
  34. package/lib/lints/index.d.ts +4 -4
  35. package/lib/lints/index.js +20 -20
  36. package/lib/lints/markdownlint/doMarkdownlint.d.ts +6 -6
  37. package/lib/lints/markdownlint/doMarkdownlint.js +52 -119
  38. package/lib/lints/markdownlint/formatMarkdownlintResults.d.ts +3 -3
  39. package/lib/lints/markdownlint/formatMarkdownlintResults.js +35 -39
  40. package/lib/lints/markdownlint/getMarkdownlintConfig.d.ts +7 -7
  41. package/lib/lints/markdownlint/getMarkdownlintConfig.js +31 -31
  42. package/lib/lints/markdownlint/index.d.ts +3 -3
  43. package/lib/lints/markdownlint/index.js +19 -19
  44. package/lib/lints/prettier/doPrettier.d.ts +4 -4
  45. package/lib/lints/prettier/doPrettier.js +32 -106
  46. package/lib/lints/prettier/index.d.ts +1 -1
  47. package/lib/lints/prettier/index.js +17 -17
  48. package/lib/lints/stylelint/doStylelint.d.ts +5 -5
  49. package/lib/lints/stylelint/doStylelint.js +31 -86
  50. package/lib/lints/stylelint/formatStylelintResults.d.ts +3 -3
  51. package/lib/lints/stylelint/formatStylelintResults.js +38 -39
  52. package/lib/lints/stylelint/getStylelintConfig.d.ts +3 -3
  53. package/lib/lints/stylelint/getStylelintConfig.js +37 -36
  54. package/lib/lints/stylelint/getStylelintDocUrl.d.ts +1 -1
  55. package/lib/lints/stylelint/getStylelintDocUrl.js +13 -13
  56. package/lib/lints/stylelint/index.d.ts +3 -3
  57. package/lib/lints/stylelint/index.js +19 -19
  58. package/lib/types/index.d.ts +73 -73
  59. package/lib/types/index.js +2 -2
  60. package/lib/utils/conflict-resolve.d.ts +3 -3
  61. package/lib/utils/conflict-resolve.js +95 -175
  62. package/lib/utils/constants.d.ts +18 -18
  63. package/lib/utils/constants.js +104 -133
  64. package/lib/utils/generate-template.d.ts +2 -2
  65. package/lib/utils/generate-template.js +53 -99
  66. package/lib/utils/git.d.ts +3 -3
  67. package/lib/utils/git.js +44 -105
  68. package/lib/utils/log.d.ts +8 -8
  69. package/lib/utils/log.js +25 -25
  70. package/lib/utils/npm-type.d.ts +2 -2
  71. package/lib/utils/npm-type.js +10 -10
  72. package/lib/utils/print-report.d.ts +3 -3
  73. package/lib/utils/print-report.js +86 -109
  74. package/package.json +18 -14
  75. package/LICENSE +0 -21
  76. package/lib/utils/update.d.ts +0 -2
  77. package/lib/utils/update.js +0 -112
@@ -1,67 +1,43 @@
1
- "use strict";
2
- var __read = (this && this.__read) || function (o, n) {
3
- var m = typeof Symbol === "function" && o[Symbol.iterator];
4
- if (!m) return o;
5
- var i = m.call(o), r, ar = [], e;
6
- try {
7
- while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
8
- }
9
- catch (error) { e = { error: error }; }
10
- finally {
11
- try {
12
- if (r && !r.done && (m = i["return"])) m.call(i);
13
- }
14
- finally { if (e) throw e.error; }
15
- }
16
- return ar;
17
- };
18
- var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
19
- if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
20
- if (ar || !(i in from)) {
21
- if (!ar) ar = Array.prototype.slice.call(from, 0, i);
22
- ar[i] = from[i];
23
- }
24
- }
25
- return to.concat(ar || Array.prototype.slice.call(from));
26
- };
27
- var __importDefault = (this && this.__importDefault) || function (mod) {
28
- return (mod && mod.__esModule) ? mod : { "default": mod };
29
- };
30
- Object.defineProperty(exports, "__esModule", { value: true });
31
- exports.getESLintConfig = void 0;
32
- var fs_extra_1 = __importDefault(require("fs-extra"));
33
- var glob_1 = __importDefault(require("glob"));
34
- var path_1 = __importDefault(require("path"));
35
- var constants_1 = require("../../utils/constants");
36
- var getESLintConfigType_1 = require("./getESLintConfigType");
37
- function getESLintConfig(opts, pkg, config) {
38
- var cwd = opts.cwd, fix = opts.fix, ignore = opts.ignore;
39
- var lintConfig = {
40
- cwd: cwd,
41
- fix: fix,
42
- ignore: ignore,
43
- extensions: constants_1.ESLINT_FILE_EXT,
44
- errorOnUnmatchedPattern: false,
45
- };
46
- if (config.eslintOptions) {
47
- Object.assign(lintConfig, config.eslintOptions);
48
- }
49
- else {
50
- var lintConfigFiles = glob_1.default.sync('.eslintrc?(.@(js|yaml|yml|json))', { cwd: cwd });
51
- if (lintConfigFiles.length === 0 && !pkg.eslintConfig) {
52
- lintConfig.resolvePluginsRelativeTo = path_1.default.resolve(__dirname, '../../');
53
- lintConfig.useEslintrc = false;
54
- lintConfig.baseConfig = {
55
- extends: __spreadArray([
56
- (0, getESLintConfigType_1.getESLintConfigType)(cwd, pkg)
57
- ], __read((config.enablePrettier ? ['prettier'] : [])), false),
58
- };
59
- }
60
- var lintIgnoreFile = path_1.default.resolve(cwd, '.eslintignore');
61
- if (!fs_extra_1.default.existsSync(lintIgnoreFile) && !pkg.eslintIgnore) {
62
- lintConfig.ignorePath = path_1.default.resolve(__dirname, '../config/_eslintignore.ejs');
63
- }
64
- }
65
- return lintConfig;
66
- }
67
- exports.getESLintConfig = getESLintConfig;
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.getESLintConfig = void 0;
7
+ const fs_extra_1 = __importDefault(require("fs-extra"));
8
+ const glob_1 = __importDefault(require("glob"));
9
+ const path_1 = __importDefault(require("path"));
10
+ const constants_1 = require("../../utils/constants");
11
+ const getESLintConfigType_1 = require("./getESLintConfigType");
12
+ function getESLintConfig(opts, pkg, config) {
13
+ const { cwd, fix, ignore } = opts;
14
+ const lintConfig = {
15
+ cwd,
16
+ fix,
17
+ ignore,
18
+ extensions: constants_1.ESLINT_FILE_EXT,
19
+ errorOnUnmatchedPattern: false,
20
+ };
21
+ if (config.eslintOptions) {
22
+ Object.assign(lintConfig, config.eslintOptions);
23
+ }
24
+ else {
25
+ const lintConfigFiles = glob_1.default.sync('.eslintrc?(.@(js|yaml|yml|json))', { cwd });
26
+ if (lintConfigFiles.length === 0 && !pkg.eslintConfig) {
27
+ lintConfig.resolvePluginsRelativeTo = path_1.default.resolve(__dirname, '../../');
28
+ lintConfig.useEslintrc = false;
29
+ lintConfig.baseConfig = {
30
+ extends: [
31
+ (0, getESLintConfigType_1.getESLintConfigType)(cwd, pkg),
32
+ ...(config.enablePrettier ? ['prettier'] : []),
33
+ ],
34
+ };
35
+ }
36
+ const lintIgnoreFile = path_1.default.resolve(cwd, '.eslintignore');
37
+ if (!fs_extra_1.default.existsSync(lintIgnoreFile) && !pkg.eslintIgnore) {
38
+ lintConfig.ignorePath = path_1.default.resolve(__dirname, '../config/_eslintignore.ejs');
39
+ }
40
+ }
41
+ return lintConfig;
42
+ }
43
+ exports.getESLintConfig = getESLintConfig;
@@ -1,2 +1,2 @@
1
- import type { PKG } from '../../types';
2
- export declare function getESLintConfigType(cwd: string, pkg: PKG): string;
1
+ import type { PKG } from '../../types';
2
+ export declare function getESLintConfigType(cwd: string, pkg: PKG): string;
@@ -1,26 +1,23 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.getESLintConfigType = void 0;
7
- var glob_1 = __importDefault(require("glob"));
8
- function getESLintConfigType(cwd, pkg) {
9
- var tsFiles = glob_1.default.sync('./!(node_modules)/**/*.@(ts|tsx)', { cwd: cwd });
10
- var reactFiles = glob_1.default.sync('./!(node_modules)/**/*.@(jsx|tsx)', { cwd: cwd });
11
- var vueFiles = glob_1.default.sync('./!(node_modules)/**/*.vue', { cwd: cwd });
12
- var dependencies = Object.keys(pkg.dependencies || {});
13
- var language = tsFiles.length > 0 ? 'typescript' : '';
14
- var dsl = '';
15
- if (reactFiles.length > 0 || dependencies.some(function (name) { return /^react(-|$)/.test(name); })) {
16
- dsl = 'react';
17
- }
18
- else if (vueFiles.length > 0 || dependencies.some(function (name) { return /^vue(-|$)/.test(name); })) {
19
- dsl = 'vue';
20
- }
21
- else if (dependencies.some(function (name) { return /^rax(-|$)/.test(name); })) {
22
- dsl = 'rax';
23
- }
24
- return ('@huangjunsen/eslint-config/' + "".concat(language, "/").concat(dsl).replace(/\/$/, '/index').replace(/^\//, ''));
25
- }
26
- exports.getESLintConfigType = getESLintConfigType;
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.getESLintConfigType = void 0;
7
+ const glob_1 = __importDefault(require("glob"));
8
+ function getESLintConfigType(cwd, pkg) {
9
+ const tsFiles = glob_1.default.sync('./!(node_modules)/**/*.@(ts|tsx)', { cwd });
10
+ const reactFiles = glob_1.default.sync('./!(node_modules)/**/*.@(jsx|tsx)', { cwd });
11
+ const vueFiles = glob_1.default.sync('./!(node_modules)/**/*.vue', { cwd });
12
+ const dependencies = Object.keys(pkg.dependencies || {});
13
+ const language = tsFiles.length > 0 ? 'typescript' : '';
14
+ let dsl = '';
15
+ if (reactFiles.length > 0 || dependencies.some((name) => /^react(-|$)/.test(name))) {
16
+ dsl = 'react';
17
+ }
18
+ else if (vueFiles.length > 0 || dependencies.some((name) => /^vue(-|$)/.test(name))) {
19
+ dsl = 'vue';
20
+ }
21
+ return ('@huangjunsen/eslint-config/' + `${language}/${dsl}`.replace(/\/$/, '/index').replace(/^\//, ''));
22
+ }
23
+ exports.getESLintConfigType = getESLintConfigType;
@@ -1,3 +1,3 @@
1
- export * from './getESLintConfig';
2
- export * from './formatESLintResults';
3
- export * from './doEslint';
1
+ export * from './getESLintConfig';
2
+ export * from './formatESLintResults';
3
+ export * from './doEslint';
@@ -1,19 +1,19 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
- };
16
- Object.defineProperty(exports, "__esModule", { value: true });
17
- __exportStar(require("./getESLintConfig"), exports);
18
- __exportStar(require("./formatESLintResults"), exports);
19
- __exportStar(require("./doEslint"), exports);
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./getESLintConfig"), exports);
18
+ __exportStar(require("./formatESLintResults"), exports);
19
+ __exportStar(require("./doEslint"), exports);
@@ -1,4 +1,4 @@
1
- export * from './eslint';
2
- export * from './markdownlint';
3
- export * from './stylelint';
4
- export * from './prettier';
1
+ export * from './eslint';
2
+ export * from './markdownlint';
3
+ export * from './stylelint';
4
+ export * from './prettier';
@@ -1,20 +1,20 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
- };
16
- Object.defineProperty(exports, "__esModule", { value: true });
17
- __exportStar(require("./eslint"), exports);
18
- __exportStar(require("./markdownlint"), exports);
19
- __exportStar(require("./stylelint"), exports);
20
- __exportStar(require("./prettier"), exports);
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./eslint"), exports);
18
+ __exportStar(require("./markdownlint"), exports);
19
+ __exportStar(require("./stylelint"), exports);
20
+ __exportStar(require("./prettier"), exports);
@@ -1,6 +1,6 @@
1
- import { Config, PKG, ScanOptions } from '../../types';
2
- export interface DoMarkdownlintOptions extends ScanOptions {
3
- pkg: PKG;
4
- config?: Config;
5
- }
6
- export declare function doMarkdownlint(options: DoMarkdownlintOptions): Promise<import("../../types").ScanResult[]>;
1
+ import { Config, PKG, ScanOptions } from '../../types';
2
+ export interface DoMarkdownlintOptions extends ScanOptions {
3
+ pkg: PKG;
4
+ config?: Config;
5
+ }
6
+ export declare function doMarkdownlint(options: DoMarkdownlintOptions): Promise<import("../../types").ScanResult[]>;
@@ -1,119 +1,52 @@
1
- "use strict";
2
- var __assign = (this && this.__assign) || function () {
3
- __assign = Object.assign || function(t) {
4
- for (var s, i = 1, n = arguments.length; i < n; i++) {
5
- s = arguments[i];
6
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
7
- t[p] = s[p];
8
- }
9
- return t;
10
- };
11
- return __assign.apply(this, arguments);
12
- };
13
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
14
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
15
- return new (P || (P = Promise))(function (resolve, reject) {
16
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
17
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
18
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
19
- step((generator = generator.apply(thisArg, _arguments || [])).next());
20
- });
21
- };
22
- var __generator = (this && this.__generator) || function (thisArg, body) {
23
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
24
- return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
25
- function verb(n) { return function (v) { return step([n, v]); }; }
26
- function step(op) {
27
- if (f) throw new TypeError("Generator is already executing.");
28
- while (g && (g = 0, op[0] && (_ = 0)), _) try {
29
- if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
30
- if (y = 0, t) op = [op[0] & 2, t.value];
31
- switch (op[0]) {
32
- case 0: case 1: t = op; break;
33
- case 4: _.label++; return { value: op[1], done: false };
34
- case 5: _.label++; y = op[1]; op = [0]; continue;
35
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
36
- default:
37
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
38
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
39
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
40
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
41
- if (t[2]) _.ops.pop();
42
- _.trys.pop(); continue;
43
- }
44
- op = body.call(thisArg, _);
45
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
46
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
47
- }
48
- };
49
- var __importDefault = (this && this.__importDefault) || function (mod) {
50
- return (mod && mod.__esModule) ? mod : { "default": mod };
51
- };
52
- Object.defineProperty(exports, "__esModule", { value: true });
53
- exports.doMarkdownlint = void 0;
54
- var fast_glob_1 = __importDefault(require("fast-glob"));
55
- var fs_extra_1 = require("fs-extra");
56
- var markdownlint_1 = __importDefault(require("markdownlint"));
57
- var markdownlint_rule_helpers_1 = __importDefault(require("markdownlint-rule-helpers"));
58
- var path_1 = require("path");
59
- var constants_1 = require("../../utils/constants");
60
- var formatMarkdownlintResults_1 = require("./formatMarkdownlintResults");
61
- var getMarkdownlintConfig_1 = require("./getMarkdownlintConfig");
62
- function doMarkdownlint(options) {
63
- return __awaiter(this, void 0, void 0, function () {
64
- var files, pattern, results, file;
65
- return __generator(this, function (_a) {
66
- switch (_a.label) {
67
- case 0:
68
- if (!options.files) return [3, 1];
69
- files = options.files.filter(function (name) { return constants_1.MARKDOWN_LINT_FILE_EXT.includes((0, path_1.extname)(name)); });
70
- return [3, 3];
71
- case 1:
72
- pattern = (0, path_1.join)(options.include, "**/*.{".concat(constants_1.MARKDOWN_LINT_FILE_EXT.map(function (t) { return t.replace(/^\./, ''); }).join(','), "}"));
73
- return [4, (0, fast_glob_1.default)(pattern, {
74
- cwd: options.cwd,
75
- ignore: constants_1.MARKDOWN_LINT_IGNORE_PATTERN,
76
- })];
77
- case 2:
78
- files = _a.sent();
79
- _a.label = 3;
80
- case 3: return [4, markdownlint_1.default.promises.markdownlint(__assign(__assign({}, (0, getMarkdownlintConfig_1.getMarkdownlintConfig)(options, options.pkg, options.config)), { files: files }))];
81
- case 4:
82
- results = _a.sent();
83
- if (!options.fix) return [3, 6];
84
- return [4, Promise.all(Object.keys(results).map(function (filename) { return formatMarkdownFile(filename, results[filename]); }))];
85
- case 5:
86
- _a.sent();
87
- for (file in results) {
88
- if (!Object.prototype.hasOwnProperty.call(results, file))
89
- continue;
90
- }
91
- _a.label = 6;
92
- case 6: return [2, (0, formatMarkdownlintResults_1.formatMarkdownlintResults)(results, options.quiet)];
93
- }
94
- });
95
- });
96
- }
97
- exports.doMarkdownlint = doMarkdownlint;
98
- function formatMarkdownFile(filename, errors) {
99
- return __awaiter(this, void 0, void 0, function () {
100
- var fixes, originalText, fixedText;
101
- return __generator(this, function (_a) {
102
- switch (_a.label) {
103
- case 0:
104
- fixes = errors === null || errors === void 0 ? void 0 : errors.filter(function (error) { return error.fixInfo; });
105
- if (!((fixes === null || fixes === void 0 ? void 0 : fixes.length) > 0)) return [3, 3];
106
- return [4, (0, fs_extra_1.readFile)(filename, 'utf8')];
107
- case 1:
108
- originalText = _a.sent();
109
- fixedText = markdownlint_rule_helpers_1.default.applyFixes(originalText, fixes);
110
- if (!(originalText !== fixedText)) return [3, 3];
111
- return [4, (0, fs_extra_1.writeFile)(filename, fixedText, 'utf8')];
112
- case 2:
113
- _a.sent();
114
- return [2, errors.filter(function (error) { return !error.fixInfo; })];
115
- case 3: return [2, errors];
116
- }
117
- });
118
- });
119
- }
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.doMarkdownlint = void 0;
7
+ const fast_glob_1 = __importDefault(require("fast-glob"));
8
+ const fs_extra_1 = require("fs-extra");
9
+ const markdownlint_1 = __importDefault(require("markdownlint"));
10
+ const markdownlint_rule_helpers_1 = __importDefault(require("markdownlint-rule-helpers"));
11
+ const path_1 = require("path");
12
+ const constants_1 = require("../../utils/constants");
13
+ const formatMarkdownlintResults_1 = require("./formatMarkdownlintResults");
14
+ const getMarkdownlintConfig_1 = require("./getMarkdownlintConfig");
15
+ async function doMarkdownlint(options) {
16
+ let files;
17
+ if (options.files) {
18
+ files = options.files.filter((name) => constants_1.MARKDOWN_LINT_FILE_EXT.includes((0, path_1.extname)(name)));
19
+ }
20
+ else {
21
+ const pattern = (0, path_1.join)(options.include, `**/*.{${constants_1.MARKDOWN_LINT_FILE_EXT.map((t) => t.replace(/^\./, '')).join(',')}}`);
22
+ files = await (0, fast_glob_1.default)(pattern, {
23
+ cwd: options.cwd,
24
+ ignore: constants_1.MARKDOWN_LINT_IGNORE_PATTERN,
25
+ });
26
+ }
27
+ const results = await markdownlint_1.default.promises.markdownlint({
28
+ ...(0, getMarkdownlintConfig_1.getMarkdownlintConfig)(options, options.pkg, options.config),
29
+ files,
30
+ });
31
+ if (options.fix) {
32
+ await Promise.all(Object.keys(results).map((filename) => formatMarkdownFile(filename, results[filename])));
33
+ for (const file in results) {
34
+ if (!Object.prototype.hasOwnProperty.call(results, file))
35
+ continue;
36
+ }
37
+ }
38
+ return (0, formatMarkdownlintResults_1.formatMarkdownlintResults)(results, options.quiet);
39
+ }
40
+ exports.doMarkdownlint = doMarkdownlint;
41
+ async function formatMarkdownFile(filename, errors) {
42
+ const fixes = errors?.filter((error) => error.fixInfo);
43
+ if (fixes?.length > 0) {
44
+ const originalText = await (0, fs_extra_1.readFile)(filename, 'utf8');
45
+ const fixedText = markdownlint_rule_helpers_1.default.applyFixes(originalText, fixes);
46
+ if (originalText !== fixedText) {
47
+ await (0, fs_extra_1.writeFile)(filename, fixedText, 'utf8');
48
+ return errors.filter((error) => !error.fixInfo);
49
+ }
50
+ }
51
+ return errors;
52
+ }
@@ -1,3 +1,3 @@
1
- import markdownlint from 'markdownlint';
2
- import type { ScanResult } from '../../types';
3
- export declare function formatMarkdownlintResults(results: markdownlint.LintResults, quiet: boolean): ScanResult[];
1
+ import markdownlint from 'markdownlint';
2
+ import type { ScanResult } from '../../types';
3
+ export declare function formatMarkdownlintResults(results: markdownlint.LintResults, quiet: boolean): ScanResult[];
@@ -1,39 +1,35 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.formatMarkdownlintResults = void 0;
4
- function formatMarkdownlintResults(results, quiet) {
5
- var parsedResults = [];
6
- var _loop_1 = function (file) {
7
- if (!Object.prototype.hasOwnProperty.call(results, file) || quiet)
8
- return "continue";
9
- var warningCount = 0;
10
- var fixableWarningCount = 0;
11
- var messages = results[file].map(function (_a) {
12
- var lineNumber = _a.lineNumber, ruleNames = _a.ruleNames, ruleDescription = _a.ruleDescription, ruleInformation = _a.ruleInformation, errorRange = _a.errorRange, fixInfo = _a.fixInfo;
13
- if (fixInfo)
14
- fixableWarningCount++;
15
- warningCount++;
16
- return {
17
- line: lineNumber,
18
- column: Array.isArray(errorRange) ? errorRange[0] : 1,
19
- rule: ruleNames[0],
20
- url: ruleInformation,
21
- message: ruleDescription,
22
- errored: false,
23
- };
24
- });
25
- parsedResults.push({
26
- filePath: file,
27
- messages: messages,
28
- errorCount: 0,
29
- warningCount: warningCount,
30
- fixableErrorCount: 0,
31
- fixableWarningCount: fixableWarningCount,
32
- });
33
- };
34
- for (var file in results) {
35
- _loop_1(file);
36
- }
37
- return parsedResults;
38
- }
39
- exports.formatMarkdownlintResults = formatMarkdownlintResults;
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.formatMarkdownlintResults = void 0;
4
+ function formatMarkdownlintResults(results, quiet) {
5
+ const parsedResults = [];
6
+ for (const file in results) {
7
+ if (!Object.prototype.hasOwnProperty.call(results, file) || quiet)
8
+ continue;
9
+ let warningCount = 0;
10
+ let fixableWarningCount = 0;
11
+ const messages = results[file].map(({ lineNumber, ruleNames, ruleDescription, ruleInformation, errorRange, fixInfo }) => {
12
+ if (fixInfo)
13
+ fixableWarningCount++;
14
+ warningCount++;
15
+ return {
16
+ line: lineNumber,
17
+ column: Array.isArray(errorRange) ? errorRange[0] : 1,
18
+ rule: ruleNames[0],
19
+ url: ruleInformation,
20
+ message: ruleDescription,
21
+ errored: false,
22
+ };
23
+ });
24
+ parsedResults.push({
25
+ filePath: file,
26
+ messages,
27
+ errorCount: 0,
28
+ warningCount,
29
+ fixableErrorCount: 0,
30
+ fixableWarningCount,
31
+ });
32
+ }
33
+ return parsedResults;
34
+ }
35
+ exports.formatMarkdownlintResults = formatMarkdownlintResults;
@@ -1,7 +1,7 @@
1
- import markdownLint from 'markdownlint';
2
- import type { ScanOptions, PKG, Config } from '../../types';
3
- type LintOptions = markdownLint.Options & {
4
- fix?: boolean;
5
- };
6
- export declare function getMarkdownlintConfig(opts: ScanOptions, pkg: PKG, config: Config): LintOptions;
7
- export {};
1
+ import markdownLint from 'markdownlint';
2
+ import type { ScanOptions, PKG, Config } from '../../types';
3
+ type LintOptions = markdownLint.Options & {
4
+ fix?: boolean;
5
+ };
6
+ export declare function getMarkdownlintConfig(opts: ScanOptions, pkg: PKG, config: Config): LintOptions;
7
+ export {};
@@ -1,31 +1,31 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.getMarkdownlintConfig = void 0;
7
- var path_1 = __importDefault(require("path"));
8
- var glob_1 = __importDefault(require("glob"));
9
- var markdownlint_1 = __importDefault(require("markdownlint"));
10
- var markdownlint_config_1 = __importDefault(require("@huangjunsen/markdownlint-config"));
11
- function getMarkdownlintConfig(opts, pkg, config) {
12
- var cwd = opts.cwd;
13
- var lintConfig = {
14
- fix: Boolean(opts.fix),
15
- resultVersion: 3,
16
- };
17
- if (config.markdownlintOptions) {
18
- Object.assign(lintConfig, config.markdownlintOptions);
19
- }
20
- else {
21
- var lintConfigFiles = glob_1.default.sync('.markdownlint(.@(yaml|yml|json))', { cwd: cwd });
22
- if (lintConfigFiles.length === 0) {
23
- lintConfig.config = markdownlint_config_1.default;
24
- }
25
- else {
26
- lintConfig.config = markdownlint_1.default.readConfigSync(path_1.default.resolve(cwd, lintConfigFiles[0]));
27
- }
28
- }
29
- return lintConfig;
30
- }
31
- exports.getMarkdownlintConfig = getMarkdownlintConfig;
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.getMarkdownlintConfig = void 0;
7
+ const path_1 = __importDefault(require("path"));
8
+ const glob_1 = __importDefault(require("glob"));
9
+ const markdownlint_1 = __importDefault(require("markdownlint"));
10
+ const markdownlint_config_1 = __importDefault(require("@huangjunsen/markdownlint-config"));
11
+ function getMarkdownlintConfig(opts, pkg, config) {
12
+ const { cwd } = opts;
13
+ const lintConfig = {
14
+ fix: Boolean(opts.fix),
15
+ resultVersion: 3,
16
+ };
17
+ if (config.markdownlintOptions) {
18
+ Object.assign(lintConfig, config.markdownlintOptions);
19
+ }
20
+ else {
21
+ const lintConfigFiles = glob_1.default.sync('.markdownlint(.@(yaml|yml|json))', { cwd });
22
+ if (lintConfigFiles.length === 0) {
23
+ lintConfig.config = markdownlint_config_1.default;
24
+ }
25
+ else {
26
+ lintConfig.config = markdownlint_1.default.readConfigSync(path_1.default.resolve(cwd, lintConfigFiles[0]));
27
+ }
28
+ }
29
+ return lintConfig;
30
+ }
31
+ exports.getMarkdownlintConfig = getMarkdownlintConfig;
@@ -1,3 +1,3 @@
1
- export * from './getMarkdownlintConfig';
2
- export * from './formatMarkdownlintResults';
3
- export * from './doMarkdownlint';
1
+ export * from './getMarkdownlintConfig';
2
+ export * from './formatMarkdownlintResults';
3
+ export * from './doMarkdownlint';