Skip to content

Commit

Permalink
Merge pull request #3 from rambler-digital-solutions/format-width
Browse files Browse the repository at this point in the history
fix(format): fix error's column width in summary
  • Loading branch information
andrepolischuk authored Jan 17, 2023
2 parents d245982 + 15c549d commit feca042
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions src/format.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,13 +63,20 @@ export const format = (results: LicenseResult[], options: Options): string => {
const successLines: FormatLine[] = []
let maxNameWidth = 0
let maxLicenseWidth = 0
let maxErrorNameWidth = 0
let maxErrorLicenseWidth = 0

results.forEach((result) => {
const nameWidth = stringWidth(result.name)
const licenseWidth = stringWidth(result.licenses ?? '')

maxNameWidth = Math.max(nameWidth, maxNameWidth)
maxLicenseWidth = Math.max(licenseWidth, maxLicenseWidth)
if (result.error && options.summary) {
maxErrorNameWidth = Math.max(nameWidth, maxErrorNameWidth)
maxErrorLicenseWidth = Math.max(licenseWidth, maxErrorLicenseWidth)
} else {
maxNameWidth = Math.max(nameWidth, maxNameWidth)
maxLicenseWidth = Math.max(licenseWidth, maxLicenseWidth)
}

const lines = result.error ? errorLines : successLines

Expand All @@ -93,7 +100,11 @@ export const format = (results: LicenseResult[], options: Options): string => {
'\n ' +
chalk.red(pluralize(errorLines.length, 'error', 'errors')) +
'\n\n'
output += formatFullLines(errorLines, maxNameWidth, maxLicenseWidth)
output += formatFullLines(
errorLines,
maxErrorNameWidth || maxNameWidth,
maxErrorLicenseWidth || maxLicenseWidth
)
output += '\n'
}

Expand Down

0 comments on commit feca042

Please sign in to comment.