Skip to content

Commit

Permalink
perf: re-use figures from listr2 and remove log-symbols
Browse files Browse the repository at this point in the history
  • Loading branch information
iiroj committed Oct 2, 2021
1 parent 946625a commit 5240c26
Show file tree
Hide file tree
Showing 13 changed files with 49 additions and 52 deletions.
10 changes: 10 additions & 0 deletions lib/figures.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
const chalk = require('chalk')
const { figures } = require('listr2')

const { arrowRight, cross, warning } = figures

module.exports = {
info: chalk.blue(arrowRight),
error: chalk.red(cross),
warning: chalk.yellow(warning),
}
3 changes: 2 additions & 1 deletion lib/messages.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
'use strict'

const chalk = require('chalk')
const { error, info, warning } = require('log-symbols')
const format = require('stringify-object')

const { error, info, warning } = require('./figures')

const configurationError = (opt, helpMsg, value) =>
`${chalk.redBright(`${error} Validation Error:`)}
Expand Down
2 changes: 1 addition & 1 deletion lib/resolveTaskFn.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ const { redBright, dim } = require('chalk')
const execa = require('execa')
const debug = require('debug')('lint-staged:task')
const { parseArgsStringToArgv } = require('string-argv')
const { error, info } = require('log-symbols')

const { error, info } = require('./figures')
const { getInitialState } = require('./state')
const { TaskError } = require('./symbols')

Expand Down
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
"enquirer": "^2.3.6",
"execa": "^5.1.1",
"listr2": "^3.12.2",
"log-symbols": "^4.1.0",
"micromatch": "^4.0.4",
"normalize-path": "^3.0.0",
"please-upgrade-node": "^3.2.0",
Expand Down
34 changes: 17 additions & 17 deletions test/__snapshots__/validateConfig.spec.js.snap
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`validateConfig should throw and should print validation errors for invalid config 1`] = `
"× Validation Error:
" Validation Error:
Invalid value for 'foo': false
Expand All @@ -11,49 +11,49 @@ exports[`validateConfig should throw and should print validation errors for inva
exports[`validateConfig should throw and should print validation errors for invalid config 1 1`] = `"Configuration should be an object or a function!"`;

exports[`validateConfig should throw when detecting deprecated advanced configuration 1`] = `
"× Validation Error:
" Validation Error:
Invalid value for 'chunkSize': 10
Advanced configuration has been deprecated.
× Validation Error:
Validation Error:
Invalid value for 'concurrent': false
Advanced configuration has been deprecated.
× Validation Error:
Validation Error:
Invalid value for 'globOptions': {matchBase: false}
Advanced configuration has been deprecated.
× Validation Error:
Validation Error:
Invalid value for 'ignore': ['test.js']
Advanced configuration has been deprecated.
× Validation Error:
Validation Error:
Invalid value for 'linters': {'*.js': ['eslint']}
Advanced configuration has been deprecated.
× Validation Error:
Validation Error:
Invalid value for 'relative': true
Advanced configuration has been deprecated.
× Validation Error:
Validation Error:
Invalid value for 'renderer': 'silent'
Advanced configuration has been deprecated.
× Validation Error:
Validation Error:
Invalid value for 'subTaskConcurrency': 10
Expand All @@ -64,49 +64,49 @@ exports[`validateConfig should throw when detecting deprecated advanced configur
"
ERROR Could not parse lint-staged config.
× Validation Error:
Validation Error:
Invalid value for 'chunkSize': 10
Advanced configuration has been deprecated.
× Validation Error:
Validation Error:
Invalid value for 'concurrent': false
Advanced configuration has been deprecated.
× Validation Error:
Validation Error:
Invalid value for 'globOptions': {matchBase: false}
Advanced configuration has been deprecated.
× Validation Error:
Validation Error:
Invalid value for 'ignore': ['test.js']
Advanced configuration has been deprecated.
× Validation Error:
Validation Error:
Invalid value for 'linters': {'*.js': ['eslint']}
Advanced configuration has been deprecated.
× Validation Error:
Validation Error:
Invalid value for 'relative': true
Advanced configuration has been deprecated.
× Validation Error:
Validation Error:
Invalid value for 'renderer': 'silent'
Advanced configuration has been deprecated.
× Validation Error:
Validation Error:
Invalid value for 'subTaskConcurrency': 10
Expand Down
2 changes: 1 addition & 1 deletion test/index.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ describe('lintStaged', () => {

expect(logger.printHistory()).toMatchInlineSnapshot(`
"
ERROR × Failed to get staged files!"
ERROR Failed to get staged files!"
`)
})

Expand Down
14 changes: 7 additions & 7 deletions test/integration.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ describe('lint-staged', () => {
await expect(lintStaged({ ...fixJsConfig, cwd: nonGitDir }, logger)).resolves.toEqual(false)
expect(logger.printHistory()).toMatchInlineSnapshot(`
"
ERROR × Current directory is not a git directory!"
ERROR Current directory is not a git directory!"
`)
await fs.remove(nonGitDir)
})
Expand Down Expand Up @@ -761,7 +761,7 @@ describe('lint-staged', () => {

expect(console.printHistory()).toMatchInlineSnapshot(`
"
WARN Some of your tasks use \`git add\` command. Please remove it from the config since all modifications made by tasks will be automatically added to the git commit index.
WARN Some of your tasks use \`git add\` command. Please remove it from the config since all modifications made by tasks will be automatically added to the git commit index.
LOG [STARTED] Preparing...
LOG [SUCCESS] Preparing...
Expand All @@ -780,7 +780,7 @@ describe('lint-staged', () => {
LOG [STARTED] Cleaning up...
LOG [SUCCESS] Cleaning up...
WARN
lint-staged prevented an empty git commit.
lint-staged prevented an empty git commit.
Use the --allow-empty option to continue, or check your task configuration
"
`)
Expand Down Expand Up @@ -909,7 +909,7 @@ describe('lint-staged', () => {

expect(console.printHistory()).toMatchInlineSnapshot(`
"
WARN Skipping backup because \`--no-stash\` was used.
WARN Skipping backup because \`--no-stash\` was used.
LOG [STARTED] Preparing...
LOG [SUCCESS] Preparing...
Expand Down Expand Up @@ -963,7 +963,7 @@ describe('lint-staged', () => {

expect(console.printHistory()).toMatchInlineSnapshot(`
"
WARN Skipping backup because \`--no-stash\` was used.
WARN Skipping backup because \`--no-stash\` was used.
LOG [STARTED] Preparing...
LOG [SUCCESS] Preparing...
Expand All @@ -980,7 +980,7 @@ describe('lint-staged', () => {
LOG [STARTED] Restoring unstaged changes to partially staged files...
ERROR [FAILED] Unstaged changes could not be restored due to a merge conflict!
ERROR
× lint-staged failed due to a git error."
lint-staged failed due to a git error."
`)

// Something was wrong so the commit was aborted
Expand Down Expand Up @@ -1080,7 +1080,7 @@ describe('lintStaged', () => {

expect(console.printHistory()).toMatchInlineSnapshot(`
"
WARN Skipping backup because there’s no initial commit yet.
WARN Skipping backup because there’s no initial commit yet.
LOG [STARTED] Preparing...
LOG [SUCCESS] Preparing...
Expand Down
2 changes: 1 addition & 1 deletion test/makeCmdTasks.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ describe('makeCmdTasks', () => {
it("should throw when function task doesn't return string | string[]", async () => {
await expect(makeCmdTasks({ commands: () => null, gitDir, files: ['test.js'] })).rejects
.toThrowErrorMatchingInlineSnapshot(`
"× Validation Error:
" Validation Error:
Invalid value for '[Function]': null
Expand Down
2 changes: 1 addition & 1 deletion test/resolveTaskFn.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ describe('resolveTaskFn', () => {
"hasPartiallyStagedFiles": null,
"output": Array [
"
i mock cmd:
mock cmd:
Mock success",
],
"quiet": false,
Expand Down
6 changes: 3 additions & 3 deletions test/runAll.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ describe('runAll', () => {
"errors": Set {},
"hasPartiallyStagedFiles": null,
"output": Array [
"i No staged files found.",
" No staged files found.",
],
"quiet": false,
"shouldBackup": true,
Expand Down Expand Up @@ -128,10 +128,10 @@ describe('runAll', () => {
INFO [SKIPPED] Skipped because of previous git error.
LOG [STARTED] Applying modifications...
INFO [SKIPPED]
[SKIPPED] × lint-staged failed due to a git error.
[SKIPPED] lint-staged failed due to a git error.
LOG [STARTED] Cleaning up...
INFO [SKIPPED]
[SKIPPED] × lint-staged failed due to a git error."
[SKIPPED] lint-staged failed due to a git error."
`)
})

Expand Down
8 changes: 4 additions & 4 deletions test/validateBraces.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ describe('validateBraces', () => {
expect(fixedBraces).toEqual('*.js')
expect(logger.printHistory()).toMatchInlineSnapshot(`
"
WARN Detected incorrect braces with only single value: \`*.{js}\`. Reformatted as: \`*.js\`
WARN Detected incorrect braces with only single value: \`*.{js}\`. Reformatted as: \`*.js\`
"
`)
})
Expand All @@ -66,7 +66,7 @@ describe('validateBraces', () => {
expect(fixedBraces).toEqual('*.tsx')
expect(logger.printHistory()).toMatchInlineSnapshot(`
"
WARN Detected incorrect braces with only single value: \`*.{ts}{x}\`. Reformatted as: \`*.tsx\`
WARN Detected incorrect braces with only single value: \`*.{ts}{x}\`. Reformatted as: \`*.tsx\`
"
`)
})
Expand All @@ -79,7 +79,7 @@ describe('validateBraces', () => {
expect(fixedBraces).toEqual('*.{js,ts}')
expect(logger.printHistory()).toMatchInlineSnapshot(`
"
WARN Detected incorrect braces with only single value: \`*.{js,{ts}}\`. Reformatted as: \`*.{js,ts}\`
WARN Detected incorrect braces with only single value: \`*.{js,{ts}}\`. Reformatted as: \`*.{js,ts}\`
"
`)
})
Expand Down Expand Up @@ -108,7 +108,7 @@ describe('validateBraces', () => {
expect(fixedBraces).toEqual('*.{{js,ts},css}')
expect(logger.printHistory()).toMatchInlineSnapshot(`
"
WARN Detected incorrect braces with only single value: \`*.{{js,ts},{css}}\`. Reformatted as: \`*.{{js,ts},css}\`
WARN Detected incorrect braces with only single value: \`*.{{js,ts},{css}}\`. Reformatted as: \`*.{{js,ts},css}\`
"
`)
})
Expand Down
2 changes: 1 addition & 1 deletion test/validateOptions.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ describe('validateOptions', () => {
expect(logger.history()).toHaveLength(1)
expect(logger.printHistory()).toMatchInlineSnapshot(`
"
ERROR × Validation Error:
ERROR Validation Error:
Invalid value for option 'shell': /bin/sh
Expand Down
15 changes: 1 addition & 14 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1569,7 +1569,7 @@ chalk@^2.0.0:
escape-string-regexp "^1.0.5"
supports-color "^5.3.0"

chalk@^4.0.0, chalk@^4.1.0, chalk@^4.1.2:
chalk@^4.0.0, chalk@^4.1.2:
version "4.1.2"
resolved "https://registry.yarnpkg.com/chalk/-/chalk-4.1.2.tgz#aac4e2b7734a740867aeb16bf02aad556a1e7a01"
integrity sha512-oKnbhFyRIXpUuez8iBMmyEa4nbj4IOQyuhc/wy9kY7/WVPcwIO9VA668Pu8RkO7+0G76SLROeyw9CpQ061i4mA==
Expand Down Expand Up @@ -2612,11 +2612,6 @@ is-typedarray@^1.0.0:
resolved "https://registry.yarnpkg.com/is-typedarray/-/is-typedarray-1.0.0.tgz#e479c80858df0c1b11ddda6940f96011fcda4a9a"
integrity sha1-5HnICFjfDBsR3dppQPlgEfzaSpo=

is-unicode-supported@^0.1.0:
version "0.1.0"
resolved "https://registry.yarnpkg.com/is-unicode-supported/-/is-unicode-supported-0.1.0.tgz#3f26c76a809593b52bfa2ecb5710ed2779b522a7"
integrity sha512-knxG2q4UC3u8stRGyAVJCOdxFmv5DZiRcdlIaAQXAbSfJya+OhopNotLQrstBhququ4ZpuKbDc/8S6mgXgPFPw==

is-weakref@^1.0.1:
version "1.0.1"
resolved "https://registry.yarnpkg.com/is-weakref/-/is-weakref-1.0.1.tgz#842dba4ec17fa9ac9850df2d6efbc1737274f2a2"
Expand Down Expand Up @@ -3287,14 +3282,6 @@ lodash@^4.7.0:
resolved "https://registry.yarnpkg.com/lodash/-/lodash-4.17.21.tgz#679591c564c3bffaae8454cf0b3df370c3d6911c"
integrity sha512-v2kDEe57lecTulaDIuNTPy3Ry4gLGJ6Z1O3vE1krgXZNrsQ+LFTGHVxVjcXPs17LhbZVGedAJv8XZ1tvj5FvSg==

log-symbols@^4.1.0:
version "4.1.0"
resolved "https://registry.yarnpkg.com/log-symbols/-/log-symbols-4.1.0.tgz#3fbdbb95b4683ac9fc785111e792e558d4abd503"
integrity sha512-8XPvpAA8uyhfteu8pIvQxpJZ7SYYdpUivZpGy6sFsBuKRY/7rQGavedeB8aK+Zkyq6upMFVL/9AW6vOYzfRyLg==
dependencies:
chalk "^4.1.0"
is-unicode-supported "^0.1.0"

log-update@^4.0.0:
version "4.0.0"
resolved "https://registry.yarnpkg.com/log-update/-/log-update-4.0.0.tgz#589ecd352471f2a1c0c570287543a64dfd20e0a1"
Expand Down

0 comments on commit 5240c26

Please sign in to comment.