Skip to content

Commit

Permalink
Make locations visible (Intellij) (#149)
Browse files Browse the repository at this point in the history
  • Loading branch information
daniilsapa authored Dec 24, 2024
1 parent 26130b5 commit 5bc4f60
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 16 deletions.
5 changes: 5 additions & 0 deletions .changeset/early-knives-type.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@steiger/pretty-reporter': minor
---

Make printed diagnostic location more readable
1 change: 1 addition & 0 deletions packages/pretty-reporter/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
"dependencies": {
"chalk": "^5.3.0",
"figures": "^6.1.0",
"picocolors": "^1.1.1",
"terminal-link": "^3.0.0"
}
}
18 changes: 9 additions & 9 deletions packages/pretty-reporter/src/format-single-diagnostic.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
import { relative } from 'node:path'
import figures from 'figures'
import terminalLink from 'terminal-link'
import chalk from 'chalk'
import pc from 'picocolors'
import type { Diagnostic } from '@steiger/types'

export function formatSingleDiagnostic(d: Diagnostic, cwd: string): string {
const x = d.severity === 'error' ? chalk.red(figures.cross) : chalk.yellow(figures.warning)
const s = chalk.reset(figures.lineDownRight)
const bar = chalk.reset(figures.lineVertical)
const e = chalk.reset(figures.lineUpRight)
const message = chalk.reset(d.message)
const autofixable = d.fixes !== undefined && d.fixes.length > 0 ? chalk.green(`${figures.tick} Auto-fixable`) : null
const location = chalk.gray(formatLocation(d.location, cwd))
const ruleName = chalk.blue(terminalLink(d.ruleName, d.getRuleDescriptionUrl(d.ruleName).toString()))
const x = d.severity === 'error' ? pc.red(figures.cross) : pc.yellow(figures.warning)
const s = pc.reset(figures.lineDownRight)
const bar = pc.reset(figures.lineVertical)
const e = pc.reset(figures.lineUpRight)
const message = pc.reset(d.message)
const autofixable = d.fixes !== undefined && d.fixes.length > 0 ? pc.green(`${figures.tick} Auto-fixable`) : null
const location = pc.underline(formatLocation(d.location, cwd))
const ruleName = pc.blue(terminalLink(d.ruleName, d.getRuleDescriptionUrl(d.ruleName).toString()))

return `
${s} ${location}
Expand Down
14 changes: 7 additions & 7 deletions packages/pretty-reporter/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import chalk from 'chalk'
import pc from 'picocolors'
import figures from 'figures'
import type { Diagnostic } from '@steiger/types'

Expand All @@ -7,7 +7,7 @@ import { s } from './pluralization.js'

export function formatPretty(diagnostics: Array<Diagnostic>, cwd: string) {
if (diagnostics.length === 0) {
return chalk.green(`${figures.tick} No problems found!`)
return pc.green(`${figures.tick} No problems found!`)
}

const errors = diagnostics.filter((d) => d.severity === 'error')
Expand All @@ -16,17 +16,17 @@ export function formatPretty(diagnostics: Array<Diagnostic>, cwd: string) {
let footer =
'Found ' +
[
errors.length > 0 && chalk.red.bold(`${errors.length} error${s(errors.length)}`),
warnings.length > 0 && chalk.yellow.bold(`${warnings.length} warning${s(warnings.length)}`),
errors.length > 0 && pc.bold(pc.red(`${errors.length} error${s(errors.length)}`)),
warnings.length > 0 && pc.bold(pc.yellow(`${warnings.length} warning${s(warnings.length)}`)),
]
.filter(Boolean)
.join(' and ')

const autofixable = diagnostics.filter((d) => (d.fixes?.length ?? 0) > 0)
if (autofixable.length === diagnostics.length) {
footer += ` (all can be fixed automatically with ${chalk.green.bold('--fix')})`
footer += ` (all can be fixed automatically with ${pc.bold(pc.green('--fix'))})`
} else if (autofixable.length > 0) {
footer += ` (${autofixable.length} can be fixed automatically with ${chalk.green.bold('--fix')})`
footer += ` (${autofixable.length} can be fixed automatically with ${pc.bold(pc.green('--fix'))})`
} else {
footer += ' (none can be fixed automatically)'
}
Expand All @@ -36,7 +36,7 @@ export function formatPretty(diagnostics: Array<Diagnostic>, cwd: string) {
diagnostics.map((d) => formatSingleDiagnostic(d, cwd)).join('\n\n') +
'\n\n' +
// Due to formatting characters, it won't be exactly the size of the footer, that is okay
chalk.gray(figures.line.repeat(footer.length)) +
pc.gray(figures.line.repeat(footer.length)) +
'\n ' +
footer +
'\n'
Expand Down
3 changes: 3 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 5bc4f60

Please sign in to comment.