Skip to content

Commit

Permalink
Improve console color constrast (#609)
Browse files Browse the repository at this point in the history
  • Loading branch information
tclindner authored Mar 19, 2022
1 parent 59dd6cb commit d6afef6
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 18 deletions.
14 changes: 4 additions & 10 deletions src/console-reporter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,9 @@ const oneFile = 1;
* @internal
*/
const printResultSetIssues = (issues: LintIssue[]): void => {
// eslint-disable-next-line no-restricted-syntax
for (const issue of issues) {
// eslint-disable-next-line no-console
issues.forEach((issue) => {
console.log(issue.toString());
}
});
};

/**
Expand All @@ -26,7 +24,6 @@ const printResultSetIssues = (issues: LintIssue[]): void => {
* @param quiet True suppress warnings, false show warnings
* @internal
*/
// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
const printIndividualResultSet = (resultSet, quiet: boolean): void => {
const {filePath, issues, ignored, errorCount, warningCount} = resultSet;

Expand Down Expand Up @@ -59,7 +56,6 @@ const printIndividualResultSet = (resultSet, quiet: boolean): void => {
* @param quiet True suppress warnings, false show warnings
* @internal
*/
// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
const printTotals = (linterOutput, quiet: boolean): void => {
const {errorCount, warningCount, ignoreCount} = linterOutput;

Expand All @@ -86,12 +82,10 @@ const printTotals = (linterOutput, quiet: boolean): void => {
* @param quiet Flag indicating whether to print warnings.
* @internal
*/
// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
export const write = (linterOutput, quiet: boolean): void => {
// eslint-disable-next-line no-restricted-syntax
for (const result of linterOutput.results) {
linterOutput.results.forEach((result) => {
printIndividualResultSet(result, quiet);
}
});

if (linterOutput.results.length > oneFile) {
printTotals(linterOutput, quiet);
Expand Down
6 changes: 3 additions & 3 deletions src/lint-issue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,10 @@ export class LintIssue {
*/
toString(): string {
const logSymbol = this.severity === Severity.Error ? logSymbols.error : logSymbols.warning;
const formattedLintId = chalk.gray.dim(this.lintId);
const formattedNode = chalk.gray.bold(this.node);
const formattedLintId = chalk.cyan.bold(this.lintId);
const formattedNode = chalk.magenta.bold(this.node);
const formattedMessage =
this.severity === Severity.Error ? chalk.bold.red(this.lintMessage) : chalk.yellow(this.lintMessage);
this.severity === Severity.Error ? chalk.red.bold(this.lintMessage) : chalk.yellow(this.lintMessage);

return `${logSymbol} ${formattedLintId} - node: ${formattedNode} - ${formattedMessage}`;
}
Expand Down
10 changes: 5 additions & 5 deletions test/unit/lint-issue.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,18 +29,18 @@ describe('LintIssue Unit Tests', () => {
describe('toString method', () => {
describe('when the severity is an error', () => {
test('the formattedMessage should equal', () => {
const formattedLintId = chalk.gray.dim('lintId');
const formattedNode = chalk.gray.bold('node');
const formattedMessage = chalk.bold.red('lintMessage');
const formattedLintId = chalk.cyan.bold('lintId');
const formattedNode = chalk.magenta.bold('node');
const formattedMessage = chalk.red.bold('lintMessage');
const output = `${logSymbols.error} ${formattedLintId} - node: ${formattedNode} - ${formattedMessage}`;
const lintIssue = new LintIssue('lintId', Severity.Error, 'node', 'lintMessage');

expect(lintIssue.toString()).toStrictEqual(output);
});

test('when an array with one error is passed a formatted message should be returned saying there is one error', () => {
const formattedLintId = chalk.gray.dim('lintId');
const formattedNode = chalk.gray.bold('node');
const formattedLintId = chalk.cyan.bold('lintId');
const formattedNode = chalk.magenta.bold('node');
const formattedMessage = chalk.yellow('lintMessage');
const output = `${logSymbols.warning} ${formattedLintId} - node: ${formattedNode} - ${formattedMessage}`;
const lintIssue = new LintIssue('lintId', Severity.Warning, 'node', 'lintMessage');
Expand Down

0 comments on commit d6afef6

Please sign in to comment.