Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: use chalk instead of colors #433

Merged
merged 7 commits into from
May 31, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
96 changes: 82 additions & 14 deletions package-lock.json

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

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
},
"dependencies": {
"async": "3.2.0",
"colors": "1.4.0",
"chalk": "4.0.0",
"commander": "5.1.0",
"glob": "7.1.6",
"parse-glob": "3.0.4",
Expand Down
3 changes: 2 additions & 1 deletion src/cli/formatter.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import * as chalk from 'chalk'
import { EventEmitter } from 'events'
import { sync as globSync } from 'glob'
import { parse, resolve } from 'path'
Expand Down Expand Up @@ -94,7 +95,7 @@ formatter.setFormat = function (format) {

if (formatHandel === undefined) {
console.log(
'No supported formatter, supported formatters: %s'.red,
chalk.red('No supported formatter, supported formatters: %s'),
arrSupportedFormatters.join(', ')
)
process.exit(1)
Expand Down
12 changes: 7 additions & 5 deletions src/cli/formatters/compact.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import * as colors from 'colors'
import * as chalk from 'chalk'
import { FormatterCallback } from '../formatter'

const compactFormatter: FormatterCallback = function (
Expand All @@ -8,9 +8,8 @@ const compactFormatter: FormatterCallback = function (
) {
const nocolor = options.nocolor

if (nocolor !== false) {
colors.enable()
}
const chalkInstance =
nocolor !== false ? new chalk.Instance({ level: 1 }) : chalk

formatter.on('file', (event) => {
event.messages.forEach((message) => {
Expand All @@ -31,7 +30,10 @@ const compactFormatter: FormatterCallback = function (
if (allHintCount > 0) {
console.log('')
const message = '%d problems'
console.log(nocolor ? message : message.red, event.allHintCount)
console.log(
nocolor ? message : chalkInstance.red(message),
event.allHintCount
)
}
})
}
Expand Down
12 changes: 8 additions & 4 deletions src/cli/formatters/default.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import * as chalk from 'chalk'
import { FormatterCallback } from '../formatter'

const defaultFormatter: FormatterCallback = function (
Expand All @@ -14,12 +15,15 @@ const defaultFormatter: FormatterCallback = function (
formatter.on('config', (event) => {
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
const configPath = event.configPath!
console.log(' Config loaded: %s', nocolor ? configPath : configPath.cyan)
console.log(
' Config loaded: %s',
nocolor ? configPath : chalk.cyan(configPath)
)
console.log('')
})

formatter.on('file', (event) => {
console.log(` ${event.file.white}`)
console.log(` ${chalk.white(event.file)}`)

const arrLogs = HTMLHint.format(event.messages, {
colors: !nocolor,
Expand All @@ -43,15 +47,15 @@ const defaultFormatter: FormatterCallback = function (
if (allHintCount > 0) {
message = 'Scanned %d files, found %d errors in %d files (%d ms)'
console.log(
nocolor ? message : message.red,
nocolor ? message : chalk.red(message),
allFileCount,
allHintCount,
allHintFileCount,
time
)
} else {
message = 'Scanned %d files, no errors found (%d ms).'
console.log(nocolor ? message : message.green, allFileCount, time)
console.log(nocolor ? message : chalk.green(message), allFileCount, time)
}
})
}
Expand Down
12 changes: 7 additions & 5 deletions src/cli/formatters/unix.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import * as colors from 'colors'
import * as chalk from 'chalk'
import { FormatterCallback } from '../formatter'

const unixFormatter: FormatterCallback = function (
Expand All @@ -8,9 +8,8 @@ const unixFormatter: FormatterCallback = function (
) {
const nocolor = options.nocolor

if (nocolor !== false) {
colors.enable()
}
const chalkInstance =
nocolor !== false ? new chalk.Instance({ level: 1 }) : chalk

formatter.on('file', (event) => {
event.messages.forEach((message) => {
Expand All @@ -30,7 +29,10 @@ const unixFormatter: FormatterCallback = function (
if (allHintCount > 0) {
console.log('')
const message = '%d problems'
console.log(nocolor ? message : message.red, event.allHintCount)
console.log(
nocolor ? message : chalkInstance.red(message),
event.allHintCount
)
}
})
}
Expand Down
5 changes: 2 additions & 3 deletions src/cli/htmlhint.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env node

import { queue as asyncQueue, series as asyncSeries } from 'async'
import 'colors'
import * as chalk from 'chalk'
import * as program from 'commander'
import { existsSync, readFileSync, statSync } from 'fs'
import * as glob from 'glob'
Expand Down Expand Up @@ -112,8 +112,7 @@ function listRules() {

for (const id in rules) {
rule = rules[id]
// eslint-disable-next-line @typescript-eslint/unbound-method
console.log(' %s : %s', rule.id.bold, rule.description)
console.log(' %s : %s', chalk.bold(rule.id), rule.description)
}
}

Expand Down