From 7d909b41bf9613acb9279cc60ab328b3b349d808 Mon Sep 17 00:00:00 2001 From: Patrick Taylor Date: Tue, 16 Jul 2024 19:17:38 +0100 Subject: [PATCH] =?UTF-8?q?Log=20the=20lint=20results=20=F0=9F=9B=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package.json | 2 +- src/index.ts | 20 +++++++++++++++++++- src/linters/markdownlint/index.ts | 2 +- src/utils/transform.ts | 24 +++++++++--------------- yarn.lock | 8 ++++---- 5 files changed, 34 insertions(+), 22 deletions(-) diff --git a/package.json b/package.json index ed18fed..ec08acd 100644 --- a/package.json +++ b/package.json @@ -32,7 +32,7 @@ "log-symbols": "6.0.0", "markdownlint": "0.34.0", "node-notifier": "10.0.1", - "space-log": "1.1.1", + "space-log": "1.2.0", "stylelint": "16.6.1" }, "devDependencies": { diff --git a/src/index.ts b/src/index.ts index 39d2684..37c243c 100755 --- a/src/index.ts +++ b/src/index.ts @@ -1,5 +1,7 @@ #!/usr/bin/env node +import chalk from 'chalk' import { Command } from 'commander' +import { spaceLog } from 'space-log' import { Events, Linter, type LinterResult, type RunLinter, type RunLintPilot } from '@Types' import colourLog from '@Utils/colourLog' @@ -20,7 +22,6 @@ program .showHelpAfterError('\n💡 Run `lint-pilot --help` for more information.\n') const runLinter = async ({ filePattern, linter }: RunLinter) => { - // TODO: Handle case where no files are sourced const startTime = new Date().getTime() colourLog.info(`Running ${linter.toLowerCase()}...`) @@ -52,6 +53,23 @@ const runLintPilot = ({ title, watch }: RunLintPilot) => { linter: Linter.Stylelint, }), ]).then((results) => { + results.forEach(({ logs, summary }) => { + if (Object.keys(logs).length === 0) { + return + } + + colourLog.info(`\nLogging ${summary.linter.toLowerCase()} results:`) + + Object.entries(logs).forEach(([file, log]) => { + console.log() + console.log(chalk.underline(`${process.cwd()}/${file}`)) + spaceLog({ + columnKeys: ['type', 'position', 'message', 'rule'], + spaceSize: 2, + }, log) + }) + }) + results.forEach(({ summary }) => { colourLog.resultBlock(summary) }) diff --git a/src/linters/markdownlint/index.ts b/src/linters/markdownlint/index.ts index 66480dc..cd691ee 100644 --- a/src/linters/markdownlint/index.ts +++ b/src/linters/markdownlint/index.ts @@ -52,7 +52,7 @@ const lintFiles = (files: Array): Promise => new Promise(( .sort((a, b) => a.lineNumber - b.lineNumber || a.ruleNames[1].localeCompare(b.ruleNames[1])) .forEach(({ errorDetail, errorRange, fixInfo, lineNumber, ruleDescription, ruleNames }) => { logs[file].push(formatFileLog({ - column: errorRange[0], + column: errorRange?.length ? errorRange[0] : undefined, lineNumber, message: errorDetail?.length ? `${ruleDescription}: ${errorDetail}` : ruleDescription, rule: ruleNames[1], diff --git a/src/utils/transform.ts b/src/utils/transform.ts index 2cb9a25..6a272e3 100644 --- a/src/utils/transform.ts +++ b/src/utils/transform.ts @@ -11,21 +11,15 @@ interface ProcessLog { type: LogType } -const formatFileLog = ({ column, lineNumber, message, rule, type }: ProcessLog): FileLog => { - const logMessage = message.length > 72 ? `${message.substring(0, 69)}...` : message - const logPosition = column ? `${lineNumber}:${column}` : lineNumber - const typeSymbol = type === LogType.WARNING ? logSymbols.warning : logSymbols.error - - return { - message: ` ${logMessage} `, - messageTheme: chalk.white, - position: ` ${logPosition} `, - positionTheme: chalk.dim, - rule: ` ${rule}`, - ruleTheme: chalk.dim, - type: `${typeSymbol} `, - } -} +const formatFileLog = ({ column, lineNumber, message, rule, type }: ProcessLog): FileLog => ({ + message: message.length > 72 ? `${message.substring(0, 69)}...` : message, + messageTheme: chalk.white, + position: column ? `${lineNumber}:${column}` : lineNumber.toString(), + positionTheme: chalk.dim, + rule: rule, + ruleTheme: chalk.dim, + type: type === LogType.WARNING ? logSymbols.warning : logSymbols.error, +}) const pluralise = (word: string, count: number) => count === 1 ? word : `${word}s` diff --git a/yarn.lock b/yarn.lock index 542f6d0..befcdef 100644 --- a/yarn.lock +++ b/yarn.lock @@ -4179,10 +4179,10 @@ source-map@^0.6.0, source-map@^0.6.1: resolved "https://registry.yarnpkg.com/source-map/-/source-map-0.6.1.tgz#74722af32e9614e9c287a8d0bbde48b5e2f1a263" integrity sha512-UjgapumWlbMhkBgzT7Ykc5YXUT46F0iKu8SGXq0bcwP5dz/h0Plj6enJqjz1Zbq2l5WaqYnrVbwWOWMyF3F47g== -space-log@1.1.1: - version "1.1.1" - resolved "https://registry.yarnpkg.com/space-log/-/space-log-1.1.1.tgz#13418b8ea43bcd0e8bc14598ed68cea9972f00f7" - integrity sha512-Snf4o+ZU8P3zSl3sFNY9Tg7229eEsmvPCoMBCcK3Kvk5eB905IGGcMTuTkqMTV7BzmFmca12tKI6rbf5rObgMg== +space-log@1.2.0: + version "1.2.0" + resolved "https://registry.yarnpkg.com/space-log/-/space-log-1.2.0.tgz#78fadb50e60a2714b0fb021472c597bb852af6f7" + integrity sha512-pG5HTbC7DCNa2U3QYIzDWl64xmX7cvI2lu4r4EXhKeKwSM7m61E9ZmRzQctGAZDvB73p5iniYb2plCtnHn0FOA== dependencies: chalk "4.1.2"