@huangjunsen/encode-fe-lint 1.0.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/LICENSE +21 -0
- package/README.md +0 -0
- package/lib/actions/init.d.ts +3 -0
- package/lib/actions/init.js +223 -0
- package/lib/actions/scan.d.ts +3 -0
- package/lib/actions/scan.js +137 -0
- package/lib/actions/update.d.ts +2 -0
- package/lib/actions/update.js +112 -0
- package/lib/cli.d.ts +2 -0
- package/lib/cli.js +230 -0
- package/lib/config/_editorconfig.ejs +13 -0
- package/lib/config/_eslintignore.ejs +9 -0
- package/lib/config/_eslintrc.js.ejs +3 -0
- package/lib/config/_markdownlint.json.ejs +1 -0
- package/lib/config/_markdownlintignore.ejs +5 -0
- package/lib/config/_prettierrc.js.ejs +8 -0
- package/lib/config/_stylelintignore.ejs +5 -0
- package/lib/config/_stylelintrc.js.ejs +5 -0
- package/lib/config/_vscode/extensions.json.ejs +7 -0
- package/lib/config/_vscode/settings.json.ejs +54 -0
- package/lib/config/commitlint.config.js.ejs +3 -0
- package/lib/config/encode-fe-lint.config.js.ejs +6 -0
- package/lib/index.d.ts +5 -0
- package/lib/index.js +93 -0
- package/lib/lints/eslint/doEslint.d.ts +6 -0
- package/lib/lints/eslint/doEslint.js +80 -0
- package/lib/lints/eslint/formatESLintResults.d.ts +3 -0
- package/lib/lints/eslint/formatESLintResults.js +39 -0
- package/lib/lints/eslint/getESLintConfig.d.ts +3 -0
- package/lib/lints/eslint/getESLintConfig.js +67 -0
- package/lib/lints/eslint/getESLintConfigType.d.ts +2 -0
- package/lib/lints/eslint/getESLintConfigType.js +26 -0
- package/lib/lints/eslint/index.d.ts +3 -0
- package/lib/lints/eslint/index.js +19 -0
- package/lib/lints/index.d.ts +4 -0
- package/lib/lints/index.js +20 -0
- package/lib/lints/markdownlint/doMarkdownlint.d.ts +6 -0
- package/lib/lints/markdownlint/doMarkdownlint.js +119 -0
- package/lib/lints/markdownlint/formatMarkdownlintResults.d.ts +3 -0
- package/lib/lints/markdownlint/formatMarkdownlintResults.js +39 -0
- package/lib/lints/markdownlint/getMarkdownlintConfig.d.ts +7 -0
- package/lib/lints/markdownlint/getMarkdownlintConfig.js +31 -0
- package/lib/lints/markdownlint/index.d.ts +3 -0
- package/lib/lints/markdownlint/index.js +19 -0
- package/lib/lints/prettier/doPrettier.d.ts +4 -0
- package/lib/lints/prettier/doPrettier.js +106 -0
- package/lib/lints/prettier/index.d.ts +1 -0
- package/lib/lints/prettier/index.js +17 -0
- package/lib/lints/stylelint/doStylelint.d.ts +5 -0
- package/lib/lints/stylelint/doStylelint.js +86 -0
- package/lib/lints/stylelint/formatStylelintResults.d.ts +3 -0
- package/lib/lints/stylelint/formatStylelintResults.js +39 -0
- package/lib/lints/stylelint/getStylelintConfig.d.ts +3 -0
- package/lib/lints/stylelint/getStylelintConfig.js +36 -0
- package/lib/lints/stylelint/getStylelintDocUrl.d.ts +1 -0
- package/lib/lints/stylelint/getStylelintDocUrl.js +13 -0
- package/lib/lints/stylelint/index.d.ts +3 -0
- package/lib/lints/stylelint/index.js +19 -0
- package/lib/types/index.d.ts +73 -0
- package/lib/types/index.js +2 -0
- package/lib/utils/conflict-resolve.d.ts +3 -0
- package/lib/utils/conflict-resolve.js +175 -0
- package/lib/utils/constants.d.ts +18 -0
- package/lib/utils/constants.js +133 -0
- package/lib/utils/generate-template.d.ts +2 -0
- package/lib/utils/generate-template.js +99 -0
- package/lib/utils/git.d.ts +3 -0
- package/lib/utils/git.js +105 -0
- package/lib/utils/init.d.ts +3 -0
- package/lib/utils/init.js +223 -0
- package/lib/utils/log.d.ts +8 -0
- package/lib/utils/log.js +25 -0
- package/lib/utils/npm-type.d.ts +2 -0
- package/lib/utils/npm-type.js +10 -0
- package/lib/utils/print-report.d.ts +3 -0
- package/lib/utils/print-report.js +109 -0
- package/lib/utils/update.d.ts +2 -0
- package/lib/utils/update.js +112 -0
- package/package.json +97 -0
|
@@ -0,0 +1,67 @@
|
|
|
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;
|
|
@@ -0,0 +1,26 @@
|
|
|
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;
|
|
@@ -0,0 +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);
|
|
@@ -0,0 +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);
|
|
@@ -0,0 +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[]>;
|
|
@@ -0,0 +1,119 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
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;
|
|
@@ -0,0 +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 {};
|
|
@@ -0,0 +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;
|
|
@@ -0,0 +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("./getMarkdownlintConfig"), exports);
|
|
18
|
+
__exportStar(require("./formatMarkdownlintResults"), exports);
|
|
19
|
+
__exportStar(require("./doMarkdownlint"), exports);
|
|
@@ -0,0 +1,106 @@
|
|
|
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.doPrettier = void 0;
|
|
54
|
+
var fast_glob_1 = __importDefault(require("fast-glob"));
|
|
55
|
+
var fs_extra_1 = require("fs-extra");
|
|
56
|
+
var path_1 = require("path");
|
|
57
|
+
var prettier_1 = __importDefault(require("prettier"));
|
|
58
|
+
var constants_1 = require("../../utils/constants");
|
|
59
|
+
function doPrettier(options) {
|
|
60
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
61
|
+
var files, pattern;
|
|
62
|
+
return __generator(this, function (_a) {
|
|
63
|
+
switch (_a.label) {
|
|
64
|
+
case 0:
|
|
65
|
+
files = [];
|
|
66
|
+
if (!options.files) return [3, 1];
|
|
67
|
+
files = options.files.filter(function (name) { return constants_1.PRETTIER_FILE_EXT.includes((0, path_1.extname)(name)); });
|
|
68
|
+
return [3, 3];
|
|
69
|
+
case 1:
|
|
70
|
+
pattern = (0, path_1.join)(options.include, "**/*.{".concat(constants_1.PRETTIER_FILE_EXT.map(function (t) { return t.replace(/^\./, ''); }).join(','), "}"));
|
|
71
|
+
return [4, (0, fast_glob_1.default)(pattern, {
|
|
72
|
+
cwd: options.cwd,
|
|
73
|
+
ignore: constants_1.PRETTIER_IGNORE_PATTERN,
|
|
74
|
+
})];
|
|
75
|
+
case 2:
|
|
76
|
+
files = _a.sent();
|
|
77
|
+
_a.label = 3;
|
|
78
|
+
case 3: return [4, Promise.all(files.map(formatFile))];
|
|
79
|
+
case 4:
|
|
80
|
+
_a.sent();
|
|
81
|
+
return [2];
|
|
82
|
+
}
|
|
83
|
+
});
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
exports.doPrettier = doPrettier;
|
|
87
|
+
function formatFile(filepath) {
|
|
88
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
89
|
+
var text, options, formatted;
|
|
90
|
+
return __generator(this, function (_a) {
|
|
91
|
+
switch (_a.label) {
|
|
92
|
+
case 0: return [4, (0, fs_extra_1.readFile)(filepath, 'utf8')];
|
|
93
|
+
case 1:
|
|
94
|
+
text = _a.sent();
|
|
95
|
+
return [4, prettier_1.default.resolveConfig(filepath)];
|
|
96
|
+
case 2:
|
|
97
|
+
options = _a.sent();
|
|
98
|
+
formatted = prettier_1.default.format(text, __assign(__assign({}, options), { filepath: filepath }));
|
|
99
|
+
return [4, (0, fs_extra_1.writeFile)(filepath, formatted, 'utf8')];
|
|
100
|
+
case 3:
|
|
101
|
+
_a.sent();
|
|
102
|
+
return [2];
|
|
103
|
+
}
|
|
104
|
+
});
|
|
105
|
+
});
|
|
106
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './doPrettier';
|
|
@@ -0,0 +1,17 @@
|
|
|
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("./doPrettier"), exports);
|
|
@@ -0,0 +1,86 @@
|
|
|
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.doStylelint = void 0;
|
|
54
|
+
var fast_glob_1 = __importDefault(require("fast-glob"));
|
|
55
|
+
var path_1 = require("path");
|
|
56
|
+
var stylelint_1 = __importDefault(require("stylelint"));
|
|
57
|
+
var constants_1 = require("../../utils/constants");
|
|
58
|
+
var formatStylelintResults_1 = require("./formatStylelintResults");
|
|
59
|
+
var getStylelintConfig_1 = require("./getStylelintConfig");
|
|
60
|
+
function doStylelint(options) {
|
|
61
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
62
|
+
var files, pattern, data;
|
|
63
|
+
return __generator(this, function (_a) {
|
|
64
|
+
switch (_a.label) {
|
|
65
|
+
case 0:
|
|
66
|
+
if (!options.files) return [3, 1];
|
|
67
|
+
files = options.files.filter(function (name) { return constants_1.STYLELINT_FILE_EXT.includes((0, path_1.extname)(name)); });
|
|
68
|
+
return [3, 3];
|
|
69
|
+
case 1:
|
|
70
|
+
pattern = (0, path_1.join)(options.include, "**/*.{".concat(constants_1.STYLELINT_FILE_EXT.map(function (t) { return t.replace(/^\./, ''); }).join(','), "}"));
|
|
71
|
+
return [4, (0, fast_glob_1.default)(pattern, {
|
|
72
|
+
cwd: options.cwd,
|
|
73
|
+
ignore: constants_1.STYLELINT_IGNORE_PATTERN,
|
|
74
|
+
})];
|
|
75
|
+
case 2:
|
|
76
|
+
files = _a.sent();
|
|
77
|
+
_a.label = 3;
|
|
78
|
+
case 3: return [4, stylelint_1.default.lint(__assign(__assign({}, (0, getStylelintConfig_1.getStylelintConfig)(options, options.pkg, options.config)), { files: files }))];
|
|
79
|
+
case 4:
|
|
80
|
+
data = _a.sent();
|
|
81
|
+
return [2, (0, formatStylelintResults_1.formatStylelintResults)(data.results, options.quiet)];
|
|
82
|
+
}
|
|
83
|
+
});
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
exports.doStylelint = doStylelint;
|