lint-staged icon indicating copy to clipboard operation
lint-staged copied to clipboard

Listr spinner/ticks not displaying

Open damienbutt opened this issue 2 years ago • 23 comments

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 `[email protected]`
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

damienbutt avatar Apr 26 '22 20:04 damienbutt

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"
  }
}

levymetal avatar May 03 '22 08:05 levymetal

Thanks for the update. I have added the ~/.huskyrc file and it is now working as expected.

D

damienbutt avatar May 03 '22 10:05 damienbutt

In this case I assume when running through husky, it somehow loses some env variables needed to make the colors work; FORCE_COLOR shouldn't be necessary especially when running on macOS.

Maybe you can get it to work by tweaking these:

https://github.com/okonet/lint-staged/blob/f0536dcc6a2e0758b1554c2673c218dd8e9c2d38/bin/lint-staged.js#L14-L17

iiroj avatar May 03 '22 10:05 iiroj

I'm using simple-git-hooks with same issue.

I use the following in my .zshrc as workaround:

export FORCE_COLOR=1

JounQin avatar May 17 '22 02:05 JounQin

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

kiosion avatar May 21 '22 19:05 kiosion

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

iiroj avatar May 22 '22 14:05 iiroj

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

iiroj avatar May 22 '22 14:05 iiroj

FYI: The above mentioned issue ^ holds many details about the behaviour on different OSes and lib versions on this issue.

webbertakken avatar Jun 01 '22 09:06 webbertakken

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

iiroj avatar Jun 01 '22 13:06 iiroj

Could it be that this is fixed in git 2.37.0? See the changelog:

  • In Git 2.36 we revamped the way how hooks are invoked. One change that is end-user visible is that the output of a hook is no longer directly connected to the standard output of "git" that spawns the hook, which was noticed post release. This is getting corrected. (merge a082345372 ab/hooks-regression-fix later to maint).

https://github.com/git/git/commit/a082345372

iiroj avatar Aug 14 '22 08:08 iiroj

~I don't think so, I'm using git 2.37.1 and don't remember updating it.~

Can't double check right now as I moved away from husky and lint-staged because of this.

Edit: The release date of 2.37.1 is after my last comment, so possibly.

webbertakken avatar Aug 14 '22 18:08 webbertakken

Could it be that this is fixed in git 2.37.0? See the changelog:

  • In Git 2.36 we revamped the way how hooks are invoked. One change that is end-user visible is that the output of a hook is no longer directly connected to the standard output of "git" that spawns the hook, which was noticed post release. This is getting corrected. (merge a082345372 ab/hooks-regression-fix later to maint).

git/git@a082345372

FWIW im running 2.37.1, i've removed FORCE_COLOR=1 from my ~/.huskyrc, and am no longer able to reproduce the buggy behaviour.

janeklb avatar Aug 14 '22 20:08 janeklb

FWIW im running 2.37.1, i've removed FORCE_COLOR=1 from my ~/.huskyrc, and am no longer able to reproduce the buggy behaviour.

Many comments in this and linked threads are mentioning that FORCE_COLOR=1 is needed when running lint staged through a git hook, like with husky. See this comment for an example output without and with it.

Could you confirm your output is properly coloured, even when running lint staged through a git hook?

webbertakken avatar Aug 14 '22 21:08 webbertakken

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 (?)

janeklb avatar Aug 14 '22 21:08 janeklb

this is the comment that fixed it for my build.

tldr; add

exec >/dev/tty 2>&1

before running lint-staged in your hook

adityavm avatar Aug 15 '22 02:08 adityavm

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.

levymetal avatar Aug 15 '22 03:08 levymetal

Added a note to FAQ here: https://github.com/okonet/lint-staged/pull/1200/commits/20ab7e17ce52ce0e9e0f855095bdab8e1ccd985c

iiroj avatar Aug 15 '22 03:08 iiroj

This still happens to me. Git is installed via Chocolatey

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

mrlonis avatar Dec 08 '22 20:12 mrlonis

This still happens to me. Git is installed via Chocolatey

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

Same in 2.39.0

> git --version
git version 2.39.0.windows.1
    "husky": "^8.0.3",
    "lint-staged": "^13.1.0",

Found someone saying v9 works, "lint-staged": "^9", it has no colors but it doesn't loop!

brunolm avatar Jan 05 '23 16:01 brunolm

Can you try installing lint-staged@next (version 13.1.3) to see if it helps? I restored supports-color in place of colorette's isColorSupported util, a change that was introduced in 13.0.0.

iiroj avatar Mar 05 '23 14:03 iiroj

☝️ 13.1.3

No colors, no loops.

image

brunolm avatar Mar 06 '23 12:03 brunolm

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

iiroj avatar Mar 06 '23 15:03 iiroj

Unlinking the PR because even though it fixes output duplication, it doesn't help in restoring the fancy colored animation.

iiroj avatar Mar 06 '23 18:03 iiroj