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

remove strip-ansi and replace chalk with picocolors #632

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
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
4 changes: 2 additions & 2 deletions lib/config/config-validator.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const chalk = require('chalk')
const picocolors = require('picocolors')
const _ = require('lodash')
const ajv = require('../common/ajv')
const configSchema = require('./config-schema')
Expand Down Expand Up @@ -42,7 +42,7 @@ const formatErrors = (errors) =>

const deprecatedDisableValue = _.once(() => {
console.warn(
chalk.yellow(
picocolors.yellow(
'[Solhint] Warning: Disabling rules with `false` or `0` is deprecated. Please use `"off"` instead.'
)
)
Expand Down
20 changes: 10 additions & 10 deletions lib/formatters/stylish.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
* @author Sindre Sorhus
*/

const chalk = require('chalk')
const stripAnsi = require('strip-ansi')
const picocolors = require('picocolors')
const { stripVTControlCharacters: stripAnsi } = require('util')
const table = require('text-table')

//------------------------------------------------------------------------------
Expand Down Expand Up @@ -46,17 +46,17 @@ module.exports = function (results) {
fixableErrorCount += result.fixableErrorCount
fixableWarningCount += result.fixableWarningCount

output += `${chalk.underline(result.filePath)}\n`
output += `${picocolors.underline(result.filePath)}\n`

output += `${table(
messages.map((message) => {
let messageType

if (message.fatal || message.severity === 2) {
messageType = chalk.red('error')
messageType = picocolors.red('error')
summaryColor = 'red'
} else {
messageType = chalk.yellow('warning')
messageType = picocolors.yellow('warning')
}

return [
Expand All @@ -65,7 +65,7 @@ module.exports = function (results) {
message.column || 0,
messageType,
message.message.replace(/([^ ])\.$/u, '$1'),
chalk.dim(message.ruleId || ''),
picocolors.dim(message.ruleId || ''),
]
}),
{
Expand All @@ -76,14 +76,14 @@ module.exports = function (results) {
}
)
.split('\n')
.map((el) => el.replace(/(\d+)\s+(\d+)/u, (m, p1, p2) => chalk.dim(`${p1}:${p2}`)))
.map((el) => el.replace(/(\d+)\s+(\d+)/u, (m, p1, p2) => picocolors.dim(`${p1}:${p2}`)))
.join('\n')}\n\n`
})

const total = errorCount + warningCount

if (total > 0) {
output += chalk[summaryColor].bold(
output += picocolors[summaryColor].bold(
[
'\u2716 ',
total,
Expand All @@ -99,7 +99,7 @@ module.exports = function (results) {
)

if (fixableErrorCount > 0 || fixableWarningCount > 0) {
output += chalk[summaryColor].bold(
output += picocolors[summaryColor].bold(
[
' ',
fixableErrorCount,
Expand All @@ -114,5 +114,5 @@ module.exports = function (results) {
}

// Resets output color, for prevent change on top level
return total > 0 ? chalk.reset(output) : ''
return total > 0 ? picocolors.reset(output) : ''
}
20 changes: 10 additions & 10 deletions lib/formatters/table.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
// Requirements
//------------------------------------------------------------------------------

const chalk = require('chalk')
const picocolors = require('picocolors')
const table = require('table').table
const pluralize = require('pluralize')

Expand All @@ -28,20 +28,20 @@ function drawTable(messages) {
}

rows.push([
chalk.bold('Line'),
chalk.bold('Column'),
chalk.bold('Type'),
chalk.bold('Message'),
chalk.bold('Rule ID'),
picocolors.bold('Line'),
picocolors.bold('Column'),
picocolors.bold('Type'),
picocolors.bold('Message'),
picocolors.bold('Rule ID'),
])

messages.forEach((message) => {
let messageType

if (message.fatal || message.severity === 2) {
messageType = chalk.red('error')
messageType = picocolors.red('error')
} else {
messageType = chalk.yellow('warning')
messageType = picocolors.yellow('warning')
}

rows.push([
Expand Down Expand Up @@ -129,8 +129,8 @@ module.exports = function (report) {

result += `\n${table(
[
[chalk.red(pluralize('Error', errorCount, true))],
[chalk.yellow(pluralize('Warning', warningCount, true))],
[picocolors.red(pluralize('Error', errorCount, true))],
[picocolors.yellow(pluralize('Warning', warningCount, true))],
],
{
columns: {
Expand Down
6 changes: 3 additions & 3 deletions lib/rules/base-checker.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const chalk = require('chalk')
const picocolors = require('picocolors')
const Ajv = require('ajv')

const ruleConfigSchema = (schema) => {
Expand Down Expand Up @@ -44,14 +44,14 @@ class BaseChecker {
.join('\n')

console.warn(
chalk.yellow(
picocolors.yellow(
`[solhint] Warning: invalid configuration for rule '${ruleId}':\n${messages}`
)
)
}
} else if (!['off', 'warn', 'error'].includes(userConfig)) {
console.warn(
chalk.yellow(
picocolors.yellow(
`[solhint] Warning: rule '${ruleId}' level is '${userConfig}'; should be one of "error", "warn" or "off"`
)
)
Expand Down
10 changes: 5 additions & 5 deletions lib/rules/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const chalk = require('chalk')
const picocolors = require('picocolors')
const _ = require('lodash')
const security = require('./security/index')
const naming = require('./naming/index')
Expand All @@ -14,11 +14,11 @@ const notifyRuleDeprecated = _.memoize((ruleId, deprecationMessage) => {
const message = deprecationMessage
? `[solhint] Warning: rule '${ruleId}' is deprecated, ${deprecationMessage}.`
: `[solhint] Warning: rule '${ruleId}' is deprecated.`
console.warn(chalk.yellow(message))
console.warn(picocolors.yellow(message))
})

const notifyRuleDoesntExist = _.memoize((ruleId) => {
console.warn(chalk.yellow(`[solhint] Warning: Rule '${ruleId}' doesn't exist`))
console.warn(picocolors.yellow(`[solhint] Warning: Rule '${ruleId}' doesn't exist`))
})

module.exports = function checkers(reporter, configVals, inputSrc, tokens, fileName) {
Expand Down Expand Up @@ -75,7 +75,7 @@ function loadPlugin(pluginName, { reporter, config, inputSrc, fileName }) {
plugins = require(`solhint-plugin-${pluginName}`)
} catch (e) {
console.error(
chalk.red(
picocolors.red(
`[solhint] Error: Could not load solhint-plugin-${pluginName}, make sure it's installed.`
)
)
Expand All @@ -84,7 +84,7 @@ function loadPlugin(pluginName, { reporter, config, inputSrc, fileName }) {

if (!Array.isArray(plugins)) {
console.warn(
chalk.yellow(
picocolors.yellow(
`[solhint] Warning: Plugin solhint-plugin-${pluginName} doesn't export an array of rules. Ignoring it.`
)
)
Expand Down
33 changes: 19 additions & 14 deletions package-lock.json

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

3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@
"ajv": "^6.12.6",
"antlr4": "^4.13.1-patch-1",
"ast-parents": "^0.0.1",
"chalk": "^4.1.2",
"commander": "^10.0.0",
"cosmiconfig": "^8.0.0",
"fast-diff": "^1.2.0",
Expand All @@ -52,9 +51,9 @@
"js-yaml": "^4.1.0",
"latest-version": "^7.0.0",
"lodash": "^4.17.21",
"picocolors": "^1.1.1",
"pluralize": "^8.0.0",
"semver": "^7.5.2",
"strip-ansi": "^6.0.1",
"table": "^6.8.1",
"text-table": "^0.2.0"
},
Expand Down
8 changes: 4 additions & 4 deletions solhint.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const _ = require('lodash')
const fs = require('fs')
const process = require('process')
const readline = require('readline')
const chalk = require('chalk')
const picocolors = require('picocolors')

const linter = require('./lib/index')
const { loadConfig } = require('./lib/config/config-file')
Expand Down Expand Up @@ -312,19 +312,19 @@ function printReports(reports, formatter) {
console.log(fullReport)
if (fullReport && !program.opts().formatter) {
console.log(
chalk.italic.bgYellow.black.bold(
picocolors.italic.bgYellow.black.bold(
' -------------------------------------------------------------------------- '
)
)

console.log(
chalk.italic.bgYellow.black.bold(
picocolors.italic.bgYellow.black.bold(
' ===> Join SOLHINT Community at: https://discord.com/invite/4TYGq3zpjs <=== '
)
)

console.log(
chalk.italic.bgYellow.black.bold(
picocolors.italic.bgYellow.black.bold(
' -------------------------------------------------------------------------- \n'
)
)
Expand Down