sku 12.0.2 → 12.0.3
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/CHANGELOG.md +6 -0
- package/lib/runESLint.js +16 -5
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
package/lib/runESLint.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
// @ts-check
|
|
1
2
|
const { yellow, cyan, gray } = require('chalk');
|
|
2
3
|
const { ESLint } = require('eslint');
|
|
3
4
|
const eslintConfig = require('../config/eslint/eslintConfig');
|
|
@@ -6,7 +7,7 @@ const { lintExtensions } = require('./lint');
|
|
|
6
7
|
const extensions = lintExtensions.map((ext) => `.${ext}`);
|
|
7
8
|
|
|
8
9
|
/**
|
|
9
|
-
* @param {{ fix?: boolean, paths?: string[] }}
|
|
10
|
+
* @param {{ fix?: boolean, paths?: string[] }} options
|
|
10
11
|
*/
|
|
11
12
|
const runESLint = async ({ fix = false, paths }) => {
|
|
12
13
|
console.log(cyan(`${fix ? 'Fixing' : 'Checking'} code with ESLint`));
|
|
@@ -30,16 +31,24 @@ const runESLint = async ({ fix = false, paths }) => {
|
|
|
30
31
|
} else {
|
|
31
32
|
console.log(gray(`Paths: ${filteredFilePaths.join(' ')}`));
|
|
32
33
|
try {
|
|
33
|
-
const
|
|
34
|
+
const lintResults = await eslint.lintFiles(filteredFilePaths);
|
|
34
35
|
|
|
35
36
|
if (fix) {
|
|
36
|
-
ESLint.outputFixes(
|
|
37
|
+
ESLint.outputFixes(lintResults);
|
|
37
38
|
} else {
|
|
38
|
-
const {
|
|
39
|
+
const { warningCount, errorCount } = lintResults.reduce(
|
|
40
|
+
(acc, result) => {
|
|
41
|
+
return {
|
|
42
|
+
warningCount: acc.warningCount + result.warningCount,
|
|
43
|
+
errorCount: acc.errorCount + result.errorCount,
|
|
44
|
+
};
|
|
45
|
+
},
|
|
46
|
+
{ warningCount: 0, errorCount: 0 },
|
|
47
|
+
);
|
|
39
48
|
|
|
40
49
|
if (errorCount || warningCount) {
|
|
41
50
|
const formatter = await eslint.loadFormatter();
|
|
42
|
-
console.log(formatter(
|
|
51
|
+
console.log(await formatter.format(lintResults));
|
|
43
52
|
}
|
|
44
53
|
|
|
45
54
|
if (errorCount > 0) {
|
|
@@ -57,6 +66,8 @@ const runESLint = async ({ fix = false, paths }) => {
|
|
|
57
66
|
};
|
|
58
67
|
|
|
59
68
|
module.exports = {
|
|
69
|
+
/** @param {string[] | undefined} paths */
|
|
60
70
|
check: (paths) => runESLint({ paths }),
|
|
71
|
+
/** @param {string[] | undefined} paths */
|
|
61
72
|
fix: (paths) => runESLint({ fix: true, paths }),
|
|
62
73
|
};
|