lint-staged: Listr spinner/ticks not displaying

Description

I have been using lint-staged for a long time and never had any issues. But recently on just one of my machines, the Listr output is not displaying correctly. Instead of the nice spinners and ticks and I am getting the below output. Does anyone know what might be causing this to happen?

[STARTED] Preparing lint-staged...
[SUCCESS] Preparing lint-staged...
[STARTED] Running tasks for staged files...
[STARTED] package.json — 2 files
[STARTED] *?(test|spec).{js,jsx,ts,tsx} — 0 file
[STARTED] *.{css,scss,md,html,json,yml,yaml} — 1 file
[SKIPPED] *?(test|spec).{js,jsx,ts,tsx} — no files
[STARTED] yarn pretty:fix
[SUCCESS] yarn pretty:fix
[SUCCESS] *.{css,scss,md,html,json,yml,yaml} — 1 file
[SUCCESS] package.json — 2 files
[SUCCESS] Running tasks for staged files...
[STARTED] Applying modifications from tasks...
[SUCCESS] Applying modifications from tasks...
[STARTED] Cleaning up temporary files...
[SUCCESS] Cleaning up temporary files...

Debug Logs

expand to view
$ /Users/damienbutt/Projects/react-hooks/node_modules/.bin/lint-staged --debug
2022-04-26T20:13:03.026Z lint-staged:bin Running `lint-staged@12.4.0`
2022-04-26T20:13:03.027Z lint-staged:bin Options parsed from command-line: {
  allowEmpty: false,
  concurrent: true,
  configPath: undefined,
  cwd: undefined,
  debug: true,
  maxArgLength: null,
  quiet: false,
  relative: false,
  shell: false,
  stash: true,
  verbose: false
}
2022-04-26T20:13:03.029Z lint-staged:validateOptions Validating options...
2022-04-26T20:13:03.029Z lint-staged:validateOptions Validated options!
2022-04-26T20:13:03.029Z lint-staged Unset GIT_LITERAL_PATHSPECS (was `undefined`)
2022-04-26T20:13:03.030Z lint-staged:runAll Running all linter scripts...
2022-04-26T20:13:03.030Z lint-staged:runAll Using working directory `/Users/damienbutt/Projects/react-hooks`
2022-04-26T20:13:03.030Z lint-staged:resolveGitRepo Resolving git repo from `/Users/damienbutt/Projects/react-hooks`
2022-04-26T20:13:03.030Z lint-staged:resolveGitRepo Unset GIT_DIR (was `undefined`)
2022-04-26T20:13:03.030Z lint-staged:resolveGitRepo Unset GIT_WORK_TREE (was `undefined`)
2022-04-26T20:13:03.030Z lint-staged:execGit Running git command [ 'rev-parse', '--show-prefix' ]
2022-04-26T20:13:03.053Z lint-staged:resolveGitRepo Resolved git directory to be `/Users/damienbutt/Projects/react-hooks`
2022-04-26T20:13:03.053Z lint-staged:resolveGitRepo Resolved git config directory to be `/Users/damienbutt/Projects/react-hooks/.git`
2022-04-26T20:13:03.053Z lint-staged:execGit Running git command [ 'log', '-1' ]
2022-04-26T20:13:03.068Z lint-staged:execGit Running git command [ 'diff', '--staged', '--diff-filter=ACMR', '--name-only', '-z' ]
2022-04-26T20:13:03.081Z lint-staged:runAll Loaded list of staged files in git:
[ '/Users/damienbutt/Projects/react-hooks/.husky/pre-commit' ]
2022-04-26T20:13:03.082Z lint-staged:searchConfigs Searching for configuration files...
2022-04-26T20:13:03.082Z lint-staged:execGit Running git command [ 'ls-files', '-z', '--full-name' ]
2022-04-26T20:13:03.093Z lint-staged:execGit Running git command [ 'ls-files', '-z', '--full-name', '--others', '--exclude-standard' ]
2022-04-26T20:13:03.106Z lint-staged:searchConfigs Found possible config files: [ '/Users/damienbutt/Projects/react-hooks/package.json' ]
2022-04-26T20:13:03.106Z lint-staged:loadConfig Loading configuration from `/Users/damienbutt/Projects/react-hooks/package.json`...
2022-04-26T20:13:03.108Z lint-staged:loadConfig Successfully loaded config from `/Users/damienbutt/Projects/react-hooks/package.json`:
{
  '*?(test|spec).{js,jsx,ts,tsx}': [ 'yarn lint:fix', 'yarn pretty:fix', 'yarn test' ],
  '*.{css,scss,md,html,json,yml,yaml}': [ 'yarn pretty:fix' ]
}
2022-04-26T20:13:03.108Z lint-staged:validateConfig Validating config from `/Users/damienbutt/Projects/react-hooks/package.json`...
2022-04-26T20:13:03.108Z lint-staged:validateConfig Validated config from `/Users/damienbutt/Projects/react-hooks/package.json`:
2022-04-26T20:13:03.111Z lint-staged:validateConfig {
  '*?(test|spec).{js,jsx,ts,tsx}': [ 'yarn lint:fix', 'yarn pretty:fix', 'yarn test' ],
  '*.{css,scss,md,html,json,yml,yaml}': [ 'yarn pretty:fix' ]
}
2022-04-26T20:13:03.111Z lint-staged:searchConfigs Found 1 config files
2022-04-26T20:13:03.111Z lint-staged:groupFilesByConfig Grouping 1 files by 1 configurations
2022-04-26T20:13:03.112Z lint-staged:chunkFiles Skip chunking files because of undefined maxArgLength
2022-04-26T20:13:03.112Z lint-staged:generateTasks Generating linter tasks
2022-04-26T20:13:03.116Z lint-staged:generateTasks Generated task: 
{
  pattern: '*?(test|spec).{js,jsx,ts,tsx}',
  commands: [ 'yarn lint:fix', 'yarn pretty:fix', 'yarn test' ],
  fileList: []
}
2022-04-26T20:13:03.117Z lint-staged:generateTasks Generated task: 
{
  pattern: '*.{css,scss,md,html,json,yml,yaml}',
  commands: [ 'yarn pretty:fix' ],
  fileList: []
}
2022-04-26T20:13:03.117Z lint-staged:makeCmdTasks Creating listr tasks for commands [ 'yarn lint:fix', 'yarn pretty:fix', 'yarn test' ]
2022-04-26T20:13:03.120Z lint-staged:resolveTaskFn cmd: yarn
2022-04-26T20:13:03.120Z lint-staged:resolveTaskFn args: [ 'lint:fix' ]
2022-04-26T20:13:03.120Z lint-staged:resolveTaskFn execaOptions: {
  cwd: '/Users/damienbutt/Projects/react-hooks',
  preferLocal: true,
  reject: false,
  shell: false
}
2022-04-26T20:13:03.121Z lint-staged:resolveTaskFn cmd: yarn
2022-04-26T20:13:03.121Z lint-staged:resolveTaskFn args: [ 'pretty:fix' ]
2022-04-26T20:13:03.121Z lint-staged:resolveTaskFn execaOptions: {
  cwd: '/Users/damienbutt/Projects/react-hooks',
  preferLocal: true,
  reject: false,
  shell: false
}
2022-04-26T20:13:03.122Z lint-staged:resolveTaskFn cmd: yarn
2022-04-26T20:13:03.122Z lint-staged:resolveTaskFn args: [ 'test' ]
2022-04-26T20:13:03.122Z lint-staged:resolveTaskFn execaOptions: {
  cwd: '/Users/damienbutt/Projects/react-hooks',
  preferLocal: true,
  reject: false,
  shell: false
}
2022-04-26T20:13:03.122Z lint-staged:makeCmdTasks Creating listr tasks for commands [ 'yarn pretty:fix' ]
2022-04-26T20:13:03.122Z lint-staged:resolveTaskFn cmd: yarn
2022-04-26T20:13:03.123Z lint-staged:resolveTaskFn args: [ 'pretty:fix' ]
2022-04-26T20:13:03.123Z lint-staged:resolveTaskFn execaOptions: {
  cwd: '/Users/damienbutt/Projects/react-hooks',
  preferLocal: true,
  reject: false,
  shell: false
}
2022-04-26T20:13:03.123Z lint-staged Tasks were executed successfully!
→ No staged files match any configured task.
$ /Users/damienbutt/Projects/react-hooks/node_modules/.bin/commitlint --edit .git/COMMIT_EDITMSG
[develop 2e0965a] chore(husky): add debug flag
 1 file changed, 1 insertion(+), 1 deletion(-)
✨  Done in 14.41s.

Environment

  • OS: macOS Monterey
  • Node.js: 16.14.2
  • lint-staged: 12.4.0

Thanks,

D

About this issue

  • Original URL
  • State: open
  • Created 2 years ago
  • Reactions: 18
  • Comments: 23 (9 by maintainers)

Commits related to this issue

Most upvoted comments

I’m pretty sure it’s working fine now - here’s a screenshot of a pre-commit hook executing: image

Please note / some context:

  • some time ago my husky + lint-staged output was looking good
  • then it broke (i’m not sure what caused it to break)
  • i googled the internets for a fix and added export FORCE_COLOR=1 to my ~/.huskyrc based on the comments here etc.
  • was notified today about the git updated, so i decided to test out the theory and remove the line from my ~/.huskyrc
  • and everything is awesome now (?)

Just tested this on git 2.37.1 and can confirm I’m getting pretty output in my husky pre-commit hook that runs lint-staged without having to set FORCE_COLOR=1 or redirect output to /dev/tty.

this is the comment that fixed it for my build.

tldr; add

exec >/dev/tty 2>&1

before running lint-staged in your hook

I created a Draft PR that forces the process.stdout to be a writable stream to /dev/tty… it feels a bit hacky but at least fixes the issue on my macOS Monterey Terminal.app.

What are the possible downsides of this?

https://github.com/okonet/lint-staged/pull/1163

Hmm, after updating some dependencies in one of my projects, I’m also hitting this bug myself… Looks like supports-color is reporting that colors are not supported.

  1. run lint-staged directly with npx lint-staged
    • spinners work correctly
  2. run lint-staged via husky directly by invoking .husky/lint-staged
    • spinners work correctly
  3. run git commit, invoking husky and lint-staged
    • spinners do not work

I ran into the same issue using both zsh and fish, putting export FORCE_COLOR=1 at the top of .husky/pre-commit fixed it for me

I have a feeling this was caused by https://github.com/okonet/lint-staged/pull/1119, although I haven’t had the time to nail down why.

In our setup with husky, we now need to explicitly set FORCE_COLOR. There are a few of ways to do this as documented here: https://github.com/okonet/lint-staged/issues/693#issuecomment-549439481

Option 1: Create file ~/.huskyrc (source):

# ~/.huskyrc
export FORCE_COLOR=1

Option 2: Add FORCE_COLORS to your package.json, like this (source):

"husky": {
  "hooks": {
    "pre-commit": "env FORCE_COLOR=1 node  ./node_modules/lint-staged/bin/lint-staged -r"
  }
}

@brunolm Thanks, I think that is still an improvement to the current situation 👍

This still happens to me. Git is installed via Chocolatey

> git --version
git version 2.38.1.windows.1

After debugging, when running through git it seems to hit this line of code, because streamIsTTY === false:

https://github.com/chalk/supports-color/blob/ee88ebcfca649233bb35c9b0db226059883a77b8/index.js#L83-L85