Skip to content

Commit

Permalink
Fix ESLint warning and error reporting (#826)
Browse files Browse the repository at this point in the history
  • Loading branch information
askoufis committed Jun 5, 2023
1 parent 0c522c4 commit 4ae7f3f
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 5 deletions.
5 changes: 5 additions & 0 deletions .changeset/silly-countries-drive.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'sku': patch
---

Fix ESLint warning and error reporting
21 changes: 16 additions & 5 deletions packages/sku/lib/runESLint.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// @ts-check
const { yellow, cyan, gray } = require('chalk');
const { ESLint } = require('eslint');
const eslintConfig = require('../config/eslint/eslintConfig');
Expand All @@ -6,7 +7,7 @@ const { lintExtensions } = require('./lint');
const extensions = lintExtensions.map((ext) => `.${ext}`);

/**
* @param {{ fix?: boolean, paths?: string[] }}
* @param {{ fix?: boolean, paths?: string[] }} options
*/
const runESLint = async ({ fix = false, paths }) => {
console.log(cyan(`${fix ? 'Fixing' : 'Checking'} code with ESLint`));
Expand All @@ -30,16 +31,24 @@ const runESLint = async ({ fix = false, paths }) => {
} else {
console.log(gray(`Paths: ${filteredFilePaths.join(' ')}`));
try {
const report = await eslint.lintFiles(filteredFilePaths);
const lintResults = await eslint.lintFiles(filteredFilePaths);

if (fix) {
ESLint.outputFixes(report);
ESLint.outputFixes(lintResults);
} else {
const { errorCount, warningCount, results } = report;
const { warningCount, errorCount } = lintResults.reduce(
(acc, result) => {
return {
warningCount: acc.warningCount + result.warningCount,
errorCount: acc.errorCount + result.errorCount,
};
},
{ warningCount: 0, errorCount: 0 },
);

if (errorCount || warningCount) {
const formatter = await eslint.loadFormatter();
console.log(formatter(results));
console.log(await formatter.format(lintResults));
}

if (errorCount > 0) {
Expand All @@ -57,6 +66,8 @@ const runESLint = async ({ fix = false, paths }) => {
};

module.exports = {
/** @param {string[] | undefined} paths */
check: (paths) => runESLint({ paths }),
/** @param {string[] | undefined} paths */
fix: (paths) => runESLint({ fix: true, paths }),
};

0 comments on commit 4ae7f3f

Please sign in to comment.