Skip to content

Commit

Permalink
Log the lint results 🛟
Browse files Browse the repository at this point in the history
  • Loading branch information
01taylop committed Jul 16, 2024
1 parent 64d8ffa commit 7d909b4
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 22 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
20 changes: 19 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
@@ -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'
Expand All @@ -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()}...`)

Expand Down Expand Up @@ -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)
})
Expand Down
2 changes: 1 addition & 1 deletion src/linters/markdownlint/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ const lintFiles = (files: Array<string>): Promise<LinterResult> => 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],
Expand Down
24 changes: 9 additions & 15 deletions src/utils/transform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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`

Expand Down
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down

0 comments on commit 7d909b4

Please sign in to comment.