Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: lint-staged/lint-staged
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: da6da00654248c34e4f7ce94f61d68ee46f177a1
Choose a base ref
...
head repository: lint-staged/lint-staged
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: c01d9524f6bcec8180e6f870f0c86ae3f77ab76a
Choose a head ref
  • 1 commit
  • 6 files changed
  • 1 contributor

Commits on Mar 6, 2023

  1. Copy the full SHA
    c01d952 View commit details
Showing with 62 additions and 49 deletions.
  1. +4 −4 lib/figures.js
  2. +14 −12 lib/messages.js
  3. +4 −4 lib/resolveTaskFn.js
  4. +6 −6 lib/runAll.js
  5. +33 −22 package-lock.json
  6. +1 −1 package.json
8 changes: 4 additions & 4 deletions lib/figures.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { blue, redBright, yellow } from 'colorette'
import chalk from 'chalk'
import { figures } from 'listr2'

export const info = blue(figures.arrowRight)
export const info = chalk.blue(figures.arrowRight)

export const error = redBright(figures.cross)
export const error = chalk.redBright(figures.cross)

export const warning = yellow(figures.warning)
export const warning = chalk.yellow(figures.warning)
26 changes: 14 additions & 12 deletions lib/messages.js
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
import { redBright, bold, yellow } from 'colorette'
import chalk from 'chalk'
import inspect from 'object-inspect'

import { error, info, warning } from './figures.js'

export const configurationError = (opt, helpMsg, value) =>
`${redBright(`${error} Validation Error:`)}
`${chalk.redBright(`${error} Validation Error:`)}
Invalid value for '${bold(opt)}': ${bold(
Invalid value for '${chalk.bold(opt)}': ${chalk.bold(
inspect(value, { inlineCharacterLimit: Number.POSITIVE_INFINITY })
)}
${helpMsg}`

export const NOT_GIT_REPO = redBright(`${error} Current directory is not a git directory!`)
export const NOT_GIT_REPO = chalk.redBright(`${error} Current directory is not a git directory!`)

export const FAILED_GET_STAGED_FILES = redBright(`${error} Failed to get staged files!`)
export const FAILED_GET_STAGED_FILES = chalk.redBright(`${error} Failed to get staged files!`)

export const incorrectBraces = (before, after) =>
yellow(
chalk.yellow(
`${warning} Detected incorrect braces with only single value: \`${before}\`. Reformatted as: \`${after}\`
`
)
@@ -36,10 +36,10 @@ export const skippingBackup = (hasInitialCommit, diff) => {
? '`--no-stash` was used'
: 'there’s no initial commit yet'

return yellow(`${warning} Skipping backup because ${reason}.\n`)
return chalk.yellow(`${warning} Skipping backup because ${reason}.\n`)
}

export const DEPRECATED_GIT_ADD = yellow(
export const DEPRECATED_GIT_ADD = chalk.yellow(
`${warning} 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.
`
)
@@ -48,18 +48,20 @@ export const TASK_ERROR = 'Skipped because of errors from tasks.'

export const SKIPPED_GIT_ERROR = 'Skipped because of previous git error.'

export const GIT_ERROR = `\n ${redBright(`${error} lint-staged failed due to a git error.`)}`
export const GIT_ERROR = `\n ${chalk.redBright(`${error} lint-staged failed due to a git error.`)}`

export const invalidOption = (name, value, message) => `${redBright(`${error} Validation Error:`)}
export const invalidOption = (name, value, message) => `${chalk.redBright(
`${error} Validation Error:`
)}
Invalid value for option '${bold(name)}': ${bold(value)}
Invalid value for option '${chalk.bold(name)}': ${chalk.bold(value)}
${message}
See https://github.com/okonet/lint-staged#command-line-flags`

export const PREVENTED_EMPTY_COMMIT = `
${yellow(`${warning} lint-staged prevented an empty git commit.
${chalk.yellow(`${warning} lint-staged prevented an empty git commit.
Use the --allow-empty option to continue, or check your task configuration`)}
`

8 changes: 4 additions & 4 deletions lib/resolveTaskFn.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { redBright, dim } from 'colorette'
import chalk from 'chalk'
import { execa, execaCommand } from 'execa'
import debug from 'debug'
import { parseArgsStringToArgv } from 'string-argv'
@@ -32,7 +32,7 @@ const handleOutput = (command, result, ctx, isError = false) => {
const hasOutput = !!stderr || !!stdout

if (hasOutput) {
const outputTitle = isError ? redBright(`${error} ${command}:`) : `${info} ${command}:`
const outputTitle = isError ? chalk.redBright(`${error} ${command}:`) : `${info} ${command}:`
const output = []
.concat(ctx.quiet ? [] : ['', outputTitle])
.concat(stderr ? stderr : [])
@@ -41,7 +41,7 @@ const handleOutput = (command, result, ctx, isError = false) => {
} else if (isError) {
// Show generic error when task had no output
const tag = getTag(result)
const message = redBright(`\n${error} ${command} failed without output (${tag}).`)
const message = chalk.redBright(`\n${error} ${command} failed without output (${tag}).`)
if (!ctx.quiet) ctx.output.push(message)
}
}
@@ -116,7 +116,7 @@ const makeErr = (command, result, ctx) => {

handleOutput(command, result, ctx, true)
const tag = getTag(result)
return new Error(`${redBright(command)} ${dim(`[${tag}]`)}`)
return new Error(`${chalk.redBright(command)} ${chalk.dim(`[${tag}]`)}`)
}

/**
12 changes: 6 additions & 6 deletions lib/runAll.js
Original file line number Diff line number Diff line change
@@ -2,7 +2,7 @@

import path from 'node:path'

import { dim } from 'colorette'
import chalk from 'chalk'
import debug from 'debug'
import { Listr } from 'listr2'
import normalize from 'normalize-path'
@@ -204,7 +204,7 @@ export const runAll = async (
const fileCount = task.fileList.length

return {
title: `${task.pattern}${dim(
title: `${task.pattern}${chalk.dim(
` — ${fileCount} ${fileCount === 1 ? 'file' : 'files'}`
)}`,
task: async (ctx, task) =>
@@ -216,7 +216,7 @@ export const runAll = async (
skip: () => {
// Skip task when no files matched
if (fileCount === 0) {
return `${task.pattern}${dim(' — no files')}`
return `${task.pattern}${chalk.dim(' — no files')}`
}
return false
},
@@ -227,15 +227,15 @@ export const runAll = async (

listrTasks.push({
title:
`${configName}${dim(` — ${files.length} ${files.length > 1 ? 'files' : 'file'}`)}` +
(chunkCount > 1 ? dim(` (chunk ${index + 1}/${chunkCount})...`) : ''),
`${configName}${chalk.dim(` — ${files.length} ${files.length > 1 ? 'files' : 'file'}`)}` +
(chunkCount > 1 ? chalk.dim(` (chunk ${index + 1}/${chunkCount})...`) : ''),
task: (ctx, task) => task.newListr(chunkListrTasks, { concurrent, exitOnError: true }),
skip: () => {
// Skip if the first step (backup) failed
if (ctx.errors.has(GitError)) return SKIPPED_GIT_ERROR
// Skip chunk when no every task is skipped (due to no matches)
if (chunkListrTasks.every((task) => task.skip())) {
return `${configName}${dim(' — no tasks to run')}`
return `${configName}${chalk.dim(' — no tasks to run')}`
}
return false
},
55 changes: 33 additions & 22 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
@@ -33,8 +33,8 @@
"test:watch": "jest --watch"
},
"dependencies": {
"chalk": "5.2.0",
"cli-truncate": "^3.1.0",
"colorette": "^2.0.19",
"commander": "^10.0.0",
"debug": "^4.3.4",
"execa": "^7.0.0",