-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add cli table builder for results
- Loading branch information
Showing
2 changed files
with
45 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import Table from 'cli-table3'; | ||
import chalk from 'chalk'; | ||
import type { RuleResults } from '../common/types.js'; | ||
|
||
export function generateTableResults(ruleResults: RuleResults): void { | ||
const headerValues = ['ruleId', 'filePath', 'level', 'startLn', 'endLn', 'startCol', 'endCol']; | ||
const headers = headerValues.map((header) => chalk.bold(header)); | ||
|
||
const table = new Table({ | ||
head: headers, | ||
style: { | ||
head: [], | ||
border: [], | ||
}, | ||
colWidths: [40, 80, 10, 10, 10, 10, 10], | ||
}); | ||
|
||
for (const ruleId in ruleResults) { | ||
if (Object.hasOwn(ruleResults, ruleId)) { | ||
const rule = ruleResults[ruleId]; | ||
for (const result of rule.results) { | ||
const row = []; | ||
row.push( | ||
rule.ruleId, | ||
result.filePath, | ||
rule.level === 'warning' | ||
? chalk.yellow(rule.level) | ||
: rule.level === 'error' | ||
? chalk.red(rule.level) | ||
: rule.level, | ||
result.startLine, | ||
result.endLine, | ||
result.startColumn, | ||
result.endColumn | ||
); | ||
table.push(row); | ||
} | ||
} | ||
} | ||
|
||
process.stdout.write(table.toString()); | ||
} |