-
Notifications
You must be signed in to change notification settings - Fork 718
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixed how formatter is used in cli.ts Fix #187
- Loading branch information
Showing
6 changed files
with
79 additions
and
9 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
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,61 @@ | ||
/** | ||
* @fileoverview The basic formatter, it just a table format with diferent colors | ||
* for errors and warnings. | ||
*/ | ||
|
||
// ------------------------------------------------------------------------------ | ||
// Requirements | ||
// ------------------------------------------------------------------------------ | ||
|
||
import * as chalk from 'chalk'; | ||
import * as _ from 'lodash'; | ||
import * as table from 'text-table'; | ||
|
||
import { debug as d } from '../../utils/debug'; | ||
import { IFormatter, Severity } from '../../types'; // eslint-disable-line no-unused-vars | ||
import * as logger from '../../utils/logging'; | ||
|
||
const debug = d(__filename); | ||
|
||
// ------------------------------------------------------------------------------ | ||
// Formatter | ||
// ------------------------------------------------------------------------------ | ||
|
||
const formatter: IFormatter = { | ||
/** Format the problems grouped by `resource` name and sorted by line and column number */ | ||
format(messages) { | ||
|
||
debug('Formatting results'); | ||
|
||
const resources = _.groupBy(messages, 'resource'); | ||
let warnings = 0; | ||
let errors = 0; | ||
|
||
_.forEach(resources, (msgs, resource) => { | ||
const sortedMessages = _.sortBy(msgs, ['line', 'column']); | ||
const tableData = []; | ||
|
||
logger.log(chalk.cyan(`${resource}: ${msgs.length} issues`)); | ||
_.forEach(sortedMessages, (msg) => { | ||
const severity = Severity.error === msg.severity ? chalk.red('Error') : chalk.yellow('Warning'); | ||
|
||
if (Severity.error === msg.severity) { | ||
errors++; | ||
} else { | ||
warnings++; | ||
} | ||
|
||
tableData.push([severity, msg.message, msg.ruleId]); | ||
}); | ||
|
||
logger.log(table(tableData)); | ||
logger.log(''); | ||
}); | ||
|
||
const color = errors > 0 ? chalk.red : chalk.yellow; | ||
|
||
logger.log(color(`Found ${errors} errors and ${warnings} warnings`)); | ||
} | ||
}; | ||
|
||
export default formatter; |
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