@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.
- package/lib/actions/init.d.ts +3 -3
- package/lib/actions/init.js +168 -223
- package/lib/actions/scan.d.ts +3 -3
- package/lib/actions/scan.js +63 -137
- package/lib/actions/update.d.ts +2 -2
- package/lib/actions/update.js +51 -112
- package/lib/cli.d.ts +2 -2
- package/lib/cli.js +152 -230
- package/lib/config/_editorconfig.ejs +13 -13
- package/lib/config/_eslintignore.ejs +9 -9
- package/lib/config/_eslintrc.js.ejs +21 -3
- package/lib/config/_markdownlint.json.ejs +1 -1
- package/lib/config/_markdownlintignore.ejs +5 -5
- package/lib/config/_prettierrc.js.ejs +3 -8
- package/lib/config/_stylelintignore.ejs +5 -5
- package/lib/config/_stylelintrc.js.ejs +5 -5
- package/lib/config/_vscode/extensions.json.ejs +7 -7
- package/lib/config/_vscode/settings.json.ejs +55 -54
- package/lib/config/commitlint.config.js.ejs +3 -3
- package/lib/config/encode-fe-lint.config.js.ejs +6 -6
- package/lib/config/eslint.config.mjs.ejs +5 -0
- package/lib/index.d.ts +5 -5
- package/lib/index.js +36 -93
- package/lib/lints/eslint/doEslint.d.ts +6 -6
- package/lib/lints/eslint/doEslint.js +44 -80
- package/lib/lints/eslint/formatESLintResults.d.ts +3 -3
- package/lib/lints/eslint/formatESLintResults.js +28 -39
- package/lib/lints/eslint/getESLintConfig.d.ts +3 -3
- package/lib/lints/eslint/getESLintConfig.js +43 -67
- package/lib/lints/eslint/getESLintConfigType.d.ts +2 -2
- package/lib/lints/eslint/getESLintConfigType.js +23 -26
- package/lib/lints/eslint/index.d.ts +3 -3
- package/lib/lints/eslint/index.js +19 -19
- package/lib/lints/index.d.ts +4 -4
- package/lib/lints/index.js +20 -20
- package/lib/lints/markdownlint/doMarkdownlint.d.ts +6 -6
- package/lib/lints/markdownlint/doMarkdownlint.js +52 -119
- package/lib/lints/markdownlint/formatMarkdownlintResults.d.ts +3 -3
- package/lib/lints/markdownlint/formatMarkdownlintResults.js +35 -39
- package/lib/lints/markdownlint/getMarkdownlintConfig.d.ts +7 -7
- package/lib/lints/markdownlint/getMarkdownlintConfig.js +31 -31
- package/lib/lints/markdownlint/index.d.ts +3 -3
- package/lib/lints/markdownlint/index.js +19 -19
- package/lib/lints/prettier/doPrettier.d.ts +4 -4
- package/lib/lints/prettier/doPrettier.js +32 -106
- package/lib/lints/prettier/index.d.ts +1 -1
- package/lib/lints/prettier/index.js +17 -17
- package/lib/lints/stylelint/doStylelint.d.ts +5 -5
- package/lib/lints/stylelint/doStylelint.js +31 -86
- package/lib/lints/stylelint/formatStylelintResults.d.ts +3 -3
- package/lib/lints/stylelint/formatStylelintResults.js +38 -39
- package/lib/lints/stylelint/getStylelintConfig.d.ts +3 -3
- package/lib/lints/stylelint/getStylelintConfig.js +37 -36
- package/lib/lints/stylelint/getStylelintDocUrl.d.ts +1 -1
- package/lib/lints/stylelint/getStylelintDocUrl.js +13 -13
- package/lib/lints/stylelint/index.d.ts +3 -3
- package/lib/lints/stylelint/index.js +19 -19
- package/lib/types/index.d.ts +73 -73
- package/lib/types/index.js +2 -2
- package/lib/utils/conflict-resolve.d.ts +3 -3
- package/lib/utils/conflict-resolve.js +95 -175
- package/lib/utils/constants.d.ts +18 -18
- package/lib/utils/constants.js +104 -133
- package/lib/utils/generate-template.d.ts +2 -2
- package/lib/utils/generate-template.js +53 -99
- package/lib/utils/git.d.ts +3 -3
- package/lib/utils/git.js +44 -105
- package/lib/utils/log.d.ts +8 -8
- package/lib/utils/log.js +25 -25
- package/lib/utils/npm-type.d.ts +2 -2
- package/lib/utils/npm-type.js +10 -10
- package/lib/utils/print-report.d.ts +3 -3
- package/lib/utils/print-report.js +86 -109
- package/package.json +18 -14
- package/LICENSE +0 -21
- package/lib/utils/update.d.ts +0 -2
- package/lib/utils/update.js +0 -112
|
@@ -1,3 +1,21 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
<%_ if (eslintType && eslintType.startsWith('custom:')) {
|
|
2
|
+
const customPkg = eslintType.replace('custom:', '');
|
|
3
|
+
_%>
|
|
4
|
+
module.exports = {
|
|
5
|
+
extends: [
|
|
6
|
+
'<%= customPkg %>',
|
|
7
|
+
<%_ if (enablePrettier) { _%>
|
|
8
|
+
'prettier',
|
|
9
|
+
<%_ } _%>
|
|
10
|
+
],
|
|
11
|
+
};
|
|
12
|
+
<%_ } else if (eslintType) { _%>
|
|
13
|
+
module.exports = {
|
|
14
|
+
extends: [
|
|
15
|
+
'<%= eslintType === 'index' ? '@huangjunsen/eslint-config' : `@huangjunsen/eslint-config/${eslintType}` %>',
|
|
16
|
+
<%_ if (enablePrettier) { _%>
|
|
17
|
+
'prettier',
|
|
18
|
+
<%_ } _%>
|
|
19
|
+
],
|
|
20
|
+
};
|
|
21
|
+
<%_ } _%>
|
|
@@ -1 +1 @@
|
|
|
1
|
-
<%_ if (enableMarkdownlint) { _%> { "extends": "@huangjunsen/markdownlint-config" } <%_ } _%>
|
|
1
|
+
<%_ if (enableMarkdownlint) { _%> { "extends": "@huangjunsen/markdownlint-config" } <%_ } _%>
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
<%_ if (enableMarkdownlint) { _%>
|
|
2
|
-
<%_ markdownLintIgnores.forEach((txt) => { _%>
|
|
3
|
-
<%= txt %>
|
|
4
|
-
<% }) %>
|
|
5
|
-
<%_ } _%>
|
|
1
|
+
<%_ if (enableMarkdownlint) { _%>
|
|
2
|
+
<%_ markdownLintIgnores.forEach((txt) => { _%>
|
|
3
|
+
<%= txt %>
|
|
4
|
+
<% }) %>
|
|
5
|
+
<%_ } _%>
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
<%_ if (enableStylelint) { _%>
|
|
2
|
-
<%_ stylelintIgnores.forEach((txt) => { _%>
|
|
3
|
-
<%= txt %>
|
|
4
|
-
<% }) %>
|
|
5
|
-
<%_ } _%>
|
|
1
|
+
<%_ if (enableStylelint) { _%>
|
|
2
|
+
<%_ stylelintIgnores.forEach((txt) => { _%>
|
|
3
|
+
<%= txt %>
|
|
4
|
+
<% }) %>
|
|
5
|
+
<%_ } _%>
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
<%_ if (enableStylelint) { _%>
|
|
2
|
-
module.exports = {
|
|
3
|
-
extends: '@huangjunsen/stylelint-config',
|
|
4
|
-
};
|
|
5
|
-
<%_ } _%>
|
|
1
|
+
<%_ if (enableStylelint) { _%>
|
|
2
|
+
module.exports = {
|
|
3
|
+
extends: '@huangjunsen/stylelint-config',
|
|
4
|
+
};
|
|
5
|
+
<%_ } _%>
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
{
|
|
2
|
-
"recommendations": [
|
|
3
|
-
"dbaeumer.vscode-eslint",
|
|
4
|
-
"stylelint.vscode-stylelint",
|
|
5
|
-
"esbenp.prettier-vscode"
|
|
6
|
-
]
|
|
7
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"recommendations": [
|
|
3
|
+
"dbaeumer.vscode-eslint",
|
|
4
|
+
"stylelint.vscode-stylelint",
|
|
5
|
+
"esbenp.prettier-vscode"
|
|
6
|
+
]
|
|
7
|
+
}
|
|
@@ -1,54 +1,55 @@
|
|
|
1
|
-
{
|
|
2
|
-
<%_ if (enableESLint) { _%>
|
|
3
|
-
"eslint.validate": ["javascript", "javascriptreact", "typescript", "typescriptreact", "vue"],
|
|
4
|
-
<%_ } _%>
|
|
5
|
-
<%_ if (enableStylelint) { _%>
|
|
6
|
-
"stylelint.validate": [<%- stylelintExt.map((ext) => `"${ext.replace(/^\./, '')}"`).join(',') %>],
|
|
7
|
-
<%_ } _%>
|
|
8
|
-
"editor.
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
<%_
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
"
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
1
|
+
{
|
|
2
|
+
<%_ if (enableESLint) { _%>
|
|
3
|
+
"eslint.validate": ["javascript", "javascriptreact", "typescript", "typescriptreact", "vue"],
|
|
4
|
+
<%_ } _%>
|
|
5
|
+
<%_ if (enableStylelint) { _%>
|
|
6
|
+
"stylelint.validate": [<%- stylelintExt.map((ext) => `"${ext.replace(/^\./, '')}"`).join(',') %>],
|
|
7
|
+
<%_ } _%>
|
|
8
|
+
"editor.formatOnSave": true,
|
|
9
|
+
"editor.codeActionsOnSave": {
|
|
10
|
+
"source.fixAll.eslint": "explicit"<%= enableStylelint || enableMarkdownlint ? ',' : ''%>
|
|
11
|
+
<%_ if (enableStylelint) { _%>
|
|
12
|
+
"source.fixAll.stylelint": "explicit"<%= enableMarkdownlint ? ',' : ''%>
|
|
13
|
+
<%_ } _%>
|
|
14
|
+
<%_ if (enableMarkdownlint) { _%>
|
|
15
|
+
"source.fixAll.markdownlint": "explicit"
|
|
16
|
+
<%_ } _%>
|
|
17
|
+
},
|
|
18
|
+
<%_ if (enablePrettier) { _%>
|
|
19
|
+
"editor.defaultFormatter": "esbenp.prettier-vscode",
|
|
20
|
+
"[javascript]": {
|
|
21
|
+
"editor.defaultFormatter": "esbenp.prettier-vscode"
|
|
22
|
+
},
|
|
23
|
+
"[javascriptreact]": {
|
|
24
|
+
"editor.defaultFormatter": "esbenp.prettier-vscode"
|
|
25
|
+
},
|
|
26
|
+
"[typescript]": {
|
|
27
|
+
"editor.defaultFormatter": "esbenp.prettier-vscode"
|
|
28
|
+
},
|
|
29
|
+
"[typescriptreact]": {
|
|
30
|
+
"editor.defaultFormatter": "esbenp.prettier-vscode"
|
|
31
|
+
},
|
|
32
|
+
"[vue]": {
|
|
33
|
+
"editor.defaultFormatter": "esbenp.prettier-vscode"
|
|
34
|
+
},
|
|
35
|
+
"[css]": {
|
|
36
|
+
"editor.defaultFormatter": "esbenp.prettier-vscode"
|
|
37
|
+
},
|
|
38
|
+
"[less]": {
|
|
39
|
+
"editor.defaultFormatter": "esbenp.prettier-vscode"
|
|
40
|
+
},
|
|
41
|
+
"[scss]": {
|
|
42
|
+
"editor.defaultFormatter": "esbenp.prettier-vscode"
|
|
43
|
+
},
|
|
44
|
+
"[html]": {
|
|
45
|
+
"editor.defaultFormatter": "esbenp.prettier-vscode"
|
|
46
|
+
},
|
|
47
|
+
"[json]": {
|
|
48
|
+
"editor.defaultFormatter": "esbenp.prettier-vscode"
|
|
49
|
+
},
|
|
50
|
+
"[jsonc]": {
|
|
51
|
+
"editor.defaultFormatter": "esbenp.prettier-vscode"
|
|
52
|
+
},
|
|
53
|
+
<%_ } _%>
|
|
54
|
+
"editor.formatOnSave": <%= enablePrettier ? 'true' : 'false' %>
|
|
55
|
+
}
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
module.exports = {
|
|
2
|
-
extends: ['@huangjunsen/commitlint-config'],
|
|
3
|
-
};
|
|
1
|
+
module.exports = {
|
|
2
|
+
extends: ['@huangjunsen/commitlint-config'],
|
|
3
|
+
};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
module.exports = {
|
|
2
|
-
enableESLint: <%= enableESLint %>,
|
|
3
|
-
enableStylelint: <%= enableStylelint %>,
|
|
4
|
-
enableMarkdownlint: <%= enableMarkdownlint %>,
|
|
5
|
-
enablePrettier: <%= enablePrettier %>,
|
|
6
|
-
};
|
|
1
|
+
module.exports = {
|
|
2
|
+
enableESLint: <%= enableESLint %>,
|
|
3
|
+
enableStylelint: <%= enableStylelint %>,
|
|
4
|
+
enableMarkdownlint: <%= enableMarkdownlint %>,
|
|
5
|
+
enablePrettier: <%= enablePrettier %>,
|
|
6
|
+
};
|
package/lib/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { InitOptions, ScanOptions } from './types';
|
|
2
|
-
type IInitOptions = Omit<InitOptions, 'checkVersionUpdate'>;
|
|
3
|
-
export declare const init: (options: IInitOptions) => Promise<void>;
|
|
4
|
-
export declare const scan: (options: ScanOptions) => Promise<import("./types").ScanReport>;
|
|
5
|
-
export {};
|
|
1
|
+
import type { InitOptions, ScanOptions } from './types';
|
|
2
|
+
type IInitOptions = Omit<InitOptions, 'checkVersionUpdate'>;
|
|
3
|
+
export declare const init: (options: IInitOptions) => Promise<void>;
|
|
4
|
+
export declare const scan: (options: ScanOptions) => Promise<import("./types").ScanReport>;
|
|
5
|
+
export {};
|
package/lib/index.js
CHANGED
|
@@ -1,93 +1,36 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
};
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
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.scan = exports.init = void 0;
|
|
54
|
-
var ora_1 = __importDefault(require("ora"));
|
|
55
|
-
var scan_1 = __importDefault(require("./actions/scan"));
|
|
56
|
-
var init_1 = __importDefault(require("./actions/init"));
|
|
57
|
-
var constants_1 = require("./utils/constants");
|
|
58
|
-
var print_report_1 = __importDefault(require("./utils/print-report"));
|
|
59
|
-
var init = function (options) { return __awaiter(void 0, void 0, void 0, function () {
|
|
60
|
-
return __generator(this, function (_a) {
|
|
61
|
-
switch (_a.label) {
|
|
62
|
-
case 0: return [4, (0, init_1.default)(__assign(__assign({}, options), { checkVersionUpdate: false }))];
|
|
63
|
-
case 1: return [2, _a.sent()];
|
|
64
|
-
}
|
|
65
|
-
});
|
|
66
|
-
}); };
|
|
67
|
-
exports.init = init;
|
|
68
|
-
var scan = function (options) { return __awaiter(void 0, void 0, void 0, function () {
|
|
69
|
-
var checking, report, results, errorCount, warningCount, type;
|
|
70
|
-
return __generator(this, function (_a) {
|
|
71
|
-
switch (_a.label) {
|
|
72
|
-
case 0:
|
|
73
|
-
checking = (0, ora_1.default)();
|
|
74
|
-
checking.start("\u6267\u884C ".concat(constants_1.PKG_NAME, " \u4EE3\u7801\u68C0\u67E5"));
|
|
75
|
-
return [4, (0, scan_1.default)(options)];
|
|
76
|
-
case 1:
|
|
77
|
-
report = _a.sent();
|
|
78
|
-
results = report.results, errorCount = report.errorCount, warningCount = report.warningCount;
|
|
79
|
-
type = 'succeed';
|
|
80
|
-
if (errorCount > 0) {
|
|
81
|
-
type = 'fail';
|
|
82
|
-
}
|
|
83
|
-
else if (warningCount > 0) {
|
|
84
|
-
type = 'warn';
|
|
85
|
-
}
|
|
86
|
-
checking[type]();
|
|
87
|
-
if (results.length > 0)
|
|
88
|
-
(0, print_report_1.default)(results, false);
|
|
89
|
-
return [2, report];
|
|
90
|
-
}
|
|
91
|
-
});
|
|
92
|
-
}); };
|
|
93
|
-
exports.scan = scan;
|
|
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.scan = exports.init = void 0;
|
|
7
|
+
const ora_1 = __importDefault(require("ora"));
|
|
8
|
+
const scan_1 = __importDefault(require("./actions/scan"));
|
|
9
|
+
const init_1 = __importDefault(require("./actions/init"));
|
|
10
|
+
const constants_1 = require("./utils/constants");
|
|
11
|
+
const print_report_1 = __importDefault(require("./utils/print-report"));
|
|
12
|
+
const init = async (options) => {
|
|
13
|
+
return await (0, init_1.default)({
|
|
14
|
+
...options,
|
|
15
|
+
checkVersionUpdate: false,
|
|
16
|
+
});
|
|
17
|
+
};
|
|
18
|
+
exports.init = init;
|
|
19
|
+
const scan = async (options) => {
|
|
20
|
+
const checking = (0, ora_1.default)();
|
|
21
|
+
checking.start(`执行 ${constants_1.PKG_NAME} 代码检查`);
|
|
22
|
+
const report = await (0, scan_1.default)(options);
|
|
23
|
+
const { results, errorCount, warningCount } = report;
|
|
24
|
+
let type = 'succeed';
|
|
25
|
+
if (errorCount > 0) {
|
|
26
|
+
type = 'fail';
|
|
27
|
+
}
|
|
28
|
+
else if (warningCount > 0) {
|
|
29
|
+
type = 'warn';
|
|
30
|
+
}
|
|
31
|
+
checking[type]();
|
|
32
|
+
if (results.length > 0)
|
|
33
|
+
(0, print_report_1.default)(results, false);
|
|
34
|
+
return report;
|
|
35
|
+
};
|
|
36
|
+
exports.scan = scan;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { Config, PKG, ScanOptions } from '../../types';
|
|
2
|
-
export interface DoESLintOptions extends ScanOptions {
|
|
3
|
-
pkg: PKG;
|
|
4
|
-
config?: Config;
|
|
5
|
-
}
|
|
6
|
-
export declare function doESLint(options: DoESLintOptions): Promise<import("../../types").ScanResult[]>;
|
|
1
|
+
import { Config, PKG, ScanOptions } from '../../types';
|
|
2
|
+
export interface DoESLintOptions extends ScanOptions {
|
|
3
|
+
pkg: PKG;
|
|
4
|
+
config?: Config;
|
|
5
|
+
}
|
|
6
|
+
export declare function doESLint(options: DoESLintOptions): Promise<import("../../types").ScanResult[]>;
|
|
@@ -1,80 +1,44 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
var path_1 = require("path");
|
|
46
|
-
var constants_1 = require("../../utils/constants");
|
|
47
|
-
var formatESLintResults_1 = require("./formatESLintResults");
|
|
48
|
-
var getESLintConfig_1 = require("./getESLintConfig");
|
|
49
|
-
function doESLint(options) {
|
|
50
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
51
|
-
var files, eslint, reports;
|
|
52
|
-
return __generator(this, function (_a) {
|
|
53
|
-
switch (_a.label) {
|
|
54
|
-
case 0:
|
|
55
|
-
if (!options.files) return [3, 1];
|
|
56
|
-
files = options.files.filter(function (name) { return constants_1.ESLINT_FILE_EXT.includes((0, path_1.extname)(name)); });
|
|
57
|
-
return [3, 3];
|
|
58
|
-
case 1: return [4, (0, fast_glob_1.default)("**/*.{".concat(constants_1.ESLINT_FILE_EXT.map(function (t) { return t.replace(/^\./, ''); }).join(','), "}"), {
|
|
59
|
-
cwd: options.cwd,
|
|
60
|
-
ignore: constants_1.ESLINT_IGNORE_PATTERN,
|
|
61
|
-
})];
|
|
62
|
-
case 2:
|
|
63
|
-
files = _a.sent();
|
|
64
|
-
_a.label = 3;
|
|
65
|
-
case 3:
|
|
66
|
-
eslint = new eslint_1.ESLint((0, getESLintConfig_1.getESLintConfig)(options, options.pkg, options.config));
|
|
67
|
-
return [4, eslint.lintFiles(files)];
|
|
68
|
-
case 4:
|
|
69
|
-
reports = _a.sent();
|
|
70
|
-
if (!options.fix) return [3, 6];
|
|
71
|
-
return [4, eslint_1.ESLint.outputFixes(reports)];
|
|
72
|
-
case 5:
|
|
73
|
-
_a.sent();
|
|
74
|
-
_a.label = 6;
|
|
75
|
-
case 6: return [2, (0, formatESLintResults_1.formatESLintResults)(reports, options.quiet, eslint)];
|
|
76
|
-
}
|
|
77
|
-
});
|
|
78
|
-
});
|
|
79
|
-
}
|
|
80
|
-
exports.doESLint = doESLint;
|
|
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.doESLint = void 0;
|
|
7
|
+
const eslint_1 = require("eslint");
|
|
8
|
+
const fast_glob_1 = __importDefault(require("fast-glob"));
|
|
9
|
+
const fs_extra_1 = __importDefault(require("fs-extra"));
|
|
10
|
+
const path_1 = require("path");
|
|
11
|
+
const constants_1 = require("../../utils/constants");
|
|
12
|
+
const formatESLintResults_1 = require("./formatESLintResults");
|
|
13
|
+
const getESLintConfig_1 = require("./getESLintConfig");
|
|
14
|
+
async function doESLint(options) {
|
|
15
|
+
let files;
|
|
16
|
+
if (options.files) {
|
|
17
|
+
files = options.files.filter((name) => constants_1.ESLINT_FILE_EXT.includes((0, path_1.extname)(name)));
|
|
18
|
+
}
|
|
19
|
+
else {
|
|
20
|
+
files = await (0, fast_glob_1.default)(`**/*.{${constants_1.ESLINT_FILE_EXT.map((t) => t.replace(/^\./, '')).join(',')}}`, {
|
|
21
|
+
cwd: options.cwd,
|
|
22
|
+
ignore: constants_1.ESLINT_IGNORE_PATTERN,
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
const hasFlatConfig = [
|
|
26
|
+
'eslint.config.js',
|
|
27
|
+
'eslint.config.mjs',
|
|
28
|
+
'eslint.config.cjs',
|
|
29
|
+
'eslint.config.ts',
|
|
30
|
+
].some((file) => fs_extra_1.default.existsSync((0, path_1.join)(options.cwd, file)));
|
|
31
|
+
const eslintConfig = hasFlatConfig
|
|
32
|
+
? {
|
|
33
|
+
fix: options.fix,
|
|
34
|
+
cwd: options.cwd,
|
|
35
|
+
}
|
|
36
|
+
: (0, getESLintConfig_1.getESLintConfig)(options, options.pkg, options.config);
|
|
37
|
+
const eslint = new eslint_1.ESLint(eslintConfig);
|
|
38
|
+
const reports = await eslint.lintFiles(files);
|
|
39
|
+
if (options.fix) {
|
|
40
|
+
await eslint_1.ESLint.outputFixes(reports);
|
|
41
|
+
}
|
|
42
|
+
return (0, formatESLintResults_1.formatESLintResults)(reports, options.quiet, eslint);
|
|
43
|
+
}
|
|
44
|
+
exports.doESLint = doESLint;
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { ESLint } from 'eslint';
|
|
2
|
-
import type { ScanResult } from '../../types';
|
|
3
|
-
export declare function formatESLintResults(results: ESLint.LintResult[], quiet: boolean, eslint: ESLint): ScanResult[];
|
|
1
|
+
import { ESLint } from 'eslint';
|
|
2
|
+
import type { ScanResult } from '../../types';
|
|
3
|
+
export declare function formatESLintResults(results: ESLint.LintResult[], quiet: boolean, eslint: ESLint): ScanResult[];
|
|
@@ -1,39 +1,28 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.formatESLintResults = void 0;
|
|
4
|
-
function formatESLintResults(results, quiet, eslint) {
|
|
5
|
-
|
|
6
|
-
return results
|
|
7
|
-
.filter(
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
errored: fatal || severity === 2,
|
|
30
|
-
};
|
|
31
|
-
})
|
|
32
|
-
.filter(function (_a) {
|
|
33
|
-
var errored = _a.errored;
|
|
34
|
-
return (quiet ? errored : true);
|
|
35
|
-
}),
|
|
36
|
-
});
|
|
37
|
-
});
|
|
38
|
-
}
|
|
39
|
-
exports.formatESLintResults = formatESLintResults;
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.formatESLintResults = void 0;
|
|
4
|
+
function formatESLintResults(results, quiet, eslint) {
|
|
5
|
+
const rulesMeta = eslint.getRulesMetaForResults(results);
|
|
6
|
+
return results
|
|
7
|
+
.filter(({ warningCount, errorCount }) => errorCount || warningCount)
|
|
8
|
+
.map(({ filePath, messages, errorCount, warningCount, fixableErrorCount, fixableWarningCount, }) => ({
|
|
9
|
+
filePath,
|
|
10
|
+
errorCount,
|
|
11
|
+
warningCount: quiet ? 0 : warningCount,
|
|
12
|
+
fixableErrorCount,
|
|
13
|
+
fixableWarningCount: quiet ? 0 : fixableWarningCount,
|
|
14
|
+
messages: messages
|
|
15
|
+
.map(({ line = 0, column = 0, ruleId, message, fatal, severity }) => {
|
|
16
|
+
return {
|
|
17
|
+
line,
|
|
18
|
+
column,
|
|
19
|
+
rule: ruleId,
|
|
20
|
+
url: rulesMeta[ruleId]?.docs?.url || '',
|
|
21
|
+
message: message.replace(/([^ ])\.$/u, '$1'),
|
|
22
|
+
errored: fatal || severity === 2,
|
|
23
|
+
};
|
|
24
|
+
})
|
|
25
|
+
.filter(({ errored }) => (quiet ? errored : true)),
|
|
26
|
+
}));
|
|
27
|
+
}
|
|
28
|
+
exports.formatESLintResults = formatESLintResults;
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { ESLint } from 'eslint';
|
|
2
|
-
import type { Config, PKG, ScanOptions } from '../../types';
|
|
3
|
-
export declare function getESLintConfig(opts: ScanOptions, pkg: PKG, config: Config): ESLint.Options;
|
|
1
|
+
import { ESLint } from 'eslint';
|
|
2
|
+
import type { Config, PKG, ScanOptions } from '../../types';
|
|
3
|
+
export declare function getESLintConfig(opts: ScanOptions, pkg: PKG, config: Config): ESLint.Options;
|