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

Why "lint-staged" log is different when is triggered by husky (v6)? #968

Open
luquera opened this issue May 14, 2021 · 55 comments
Open

Why "lint-staged" log is different when is triggered by husky (v6)? #968

luquera opened this issue May 14, 2021 · 55 comments

Comments

@luquera
Copy link

luquera commented May 14, 2021

Everything is set up correctly, according to the documentation. I'm using Windows 10.

by husky:
image

by npm script (running lint-staged):
image

Thanks!

@luquera luquera changed the title Why my lint-staged output is different when is triggered by Husky? Why "lint-staged" log is different when is triggered by husky? May 14, 2021
@luquera luquera changed the title Why "lint-staged" log is different when is triggered by husky? Why "lint-staged" log is different when is triggered by husky (v6)? May 14, 2021
@walkerrandolphsmith
Copy link

walkerrandolphsmith commented May 27, 2021

I am experiencing this as well with lint staged 11.0.0 and husky v6. In addition, when I run yarn lint-staged it updates staged files, but when committing and relying on a hook to call yarn lint-staged the changes are left un-staged and a commit is made.

Running lint-staged with the following config:
$ HUSKY_DEBUG=1 git commit -m "fix some bug"
husky (debug) - starting pre-commit...
Running lint-staged with the following config:
{
  '*.{js,ts,tsx}': 'prettier --write'
}
[STARTED] Preparing...
[SUCCESS] Preparing...
[STARTED] Running tasks...
[STARTED] Running tasks for *.{js,ts,tsx}
[STARTED] prettier --write
[SUCCESS] prettier --write
[SUCCESS] Running tasks for *.{js,ts,tsx}
[SUCCESS] Running tasks...
[STARTED] Applying modifications...
[SUCCESS] Applying modifications...
[STARTED] Cleaning up...
[SUCCESS] Cleaning up...

ℹ prettier --write:
src\__tests__\utilities.test.ts 326ms
[story/5065410 9ee08d85a] fix
 1 file changed, 1 insertion(+), 1 deletion(-)

@MineiToshio
Copy link

Having the same issue, @luquera did you manage to solve it?

@stale
Copy link

stale bot commented Aug 19, 2021

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added wontfix and removed wontfix labels Aug 19, 2021
@luquera
Copy link
Author

luquera commented Sep 10, 2021

Having the same issue, @luquera did you manage to solve it?

Unfortunately not yet :(

@stale
Copy link

stale bot commented Nov 9, 2021

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the wontfix label Nov 9, 2021
@FFdhorkin
Copy link

Issue is still not solved

@stale stale bot removed the wontfix label Nov 10, 2021
@mukhlisakbr
Copy link

it still not solved till now

@stale
Copy link

stale bot commented Feb 15, 2022

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added wontfix and removed wontfix labels Feb 15, 2022
@typicode
Copy link
Owner

Not sure, but I guess it detects that the terminal aren't capable of rendering the first version and renders the second one. I imagine it's done via an env variable. I would try passing some env variable to try if it's possible to "force" the first type of rendering.

And sometimes, it's better to avoid animation and have per-line information (for example logs in Git GUIs).

I would check the dependencies that lint-staged uses for rendering the results.

That said, as far as I know, I don't think there's anything that can be done in husky's code to help with that.

@TrejGun
Copy link

TrejGun commented Mar 10, 2022

same here

@acidcrash2005
Copy link

Has anyone found resolve?

@Axedyson
Copy link

Axedyson commented Apr 26, 2022

It worked for me before, but since yesterday I've now bumped into the same exact issue.
I'm using the windows terminal and running my project in WSL2

@Axedyson
Copy link

Axedyson commented Apr 26, 2022

Okay it seems like this is working for me:
https://github.com/AndysonDK/syncbase/blob/main/.husky/pre-commit
But commitizen cli is still not rendered properly

@valentinoli
Copy link

valentinoli commented May 4, 2022

Partially fixed in lint-staged
lint-staged/lint-staged#693 (comment)

valentinoli added a commit to hestiaAI/hestialabs-experiences that referenced this issue May 4, 2022
@iiroj
Copy link

iiroj commented May 30, 2022

The issue seems to be that supports-color (code link) and colorette (code link) both use the tty.isatty(1) check from node:tty to test whether the current stdin is in fact a TTY. This is reported as false when running through a git hook (with husky), and true when directly running lint-staged.

I'm not sure what caused this to start happen, but I assume it is an update to one of:

  1. dependencies of lint-staged (colorette, supports-color..., listr2)
  2. husky
  3. git itself

@iiroj
Copy link

iiroj commented Jun 1, 2022

For a simple reproduction, try running in your terminal:

> node -e "console.log(require('tty').isatty(1))"
true

Putting this same script into the pre-commit sh script of Husky, will print false instead:

#!/usr/bin/env sh
. "$(dirname "$0")/_/husky.sh"

node -e "console.log(require('tty').isatty(1))"

@akamfoad
Copy link

akamfoad commented Sep 6, 2022

Hi, I have a similar issue but in my case the terminal is being exploded with repeated log output.

OS: Windows
Shell: PowerShell 7.2.6
Git Version: 2.37.1.windows.1

running

yarn lint-staged

Through git hooks (added with husky):

PowerShell.2022-09-06.16-37-59.mp4

Directly running the command:

PowerShell.2022-09-06.16-39-07.mp4

@lalitlsg
Copy link

If I make a commit from vscode UI, by keeping exec >/dev/tty 2>&1 in pre-commit script
It gives below error:

.husky/pre-commit: line 4: /dev/tty: Device not configured

@J4v4Scr1pt
Copy link

J4v4Scr1pt commented Sep 19, 2022

Hi, I have a similar issue but in my case the terminal is being exploded with repeated log output.

OS: Windows
Shell: PowerShell 7.2.6
Git Version: 2.37.1.windows.1

running

yarn lint-staged

Through git hooks (added with husky):

PowerShell.2022-09-06.16-37-59.mp4

Directly running the command:

PowerShell.2022-09-06.16-39-07.mp4

Exactly the same thing happens to me and my team. Can't understand why and there seems to be no working solution from what I can find.
If you check Task Manager you can also see that it spins up many Node.js instances. And the computer gets super slow. It even makes working js test to timeout.

I think this is a seroius issue that will affect usage. But Like I said I cant figure out why this accure.

Edit:
I will reference you are excellent explanation in a new issue @akamfoad.

@Nick-Hopps
Copy link

image

seems they fix it in version 2.38?

@vkrol
Copy link

vkrol commented Oct 5, 2022

@Nick-Hopps No, I checked it.

@wherehows
Copy link

wherehows commented Oct 17, 2022

If I make a commit from vscode UI, by keeping exec >/dev/tty 2>&1 in pre-commit script It gives below error:

.husky/pre-commit: line 4: /dev/tty: Device not configured

@lalitlsg

i have the same problem but after i change /dev/tty to /dev/console it works

i dont know how it works exactly but anyway it works. (ㅠ.ㅠ)

cf: https://unix.stackexchange.com/questions/692257/why-no-such-device-or-address-when-open-dev-tty-in-the-first-process/

@yangliguo7
Copy link

yangliguo7 commented Nov 14, 2022

maybe you should run your command in terminal not in VSCODE or webStrom . @wherehows

@akmaldira
Copy link

Hi, I have a similar issue but in my case the terminal is being exploded with repeated log output.

OS: Windows
Shell: PowerShell 7.2.6
Git Version: 2.37.1.windows.1

running

yarn lint-staged

Through git hooks (added with husky):

PowerShell.2022-09-06.16-37-59.mp4

Directly running the command:

PowerShell.2022-09-06.16-39-07.mp4

Same problem here

@MrFlyHouse
Copy link

If I make a commit from vscode UI, by keeping exec >/dev/tty 2>&1 in pre-commit script It gives below error:
.husky/pre-commit: line 4: /dev/tty: Device not configured

@lalitlsg

i have the same problem but after i change /dev/tty to /dev/console it works

i dont know how it works exactly but anyway it works. (ㅠ.ㅠ)

cf: https://unix.stackexchange.com/questions/692257/why-no-such-device-or-address-when-open-dev-tty-in-the-first-process/

@wherehows It works when I'm using terminal panel, but doesn't work when using the SOURCE CONTROL gui panel (commit by press 'Commit' button), do you have same problem, and do you solve it if so?

VSCode said .husky/pre-commit: line 4: /dev/console: No such device or address

@wherehows
Copy link

If I make a commit from vscode UI, by keeping exec >/dev/tty 2>&1 in pre-commit script It gives below error:
.husky/pre-commit: line 4: /dev/tty: Device not configured

@lalitlsg
i have the same problem but after i change /dev/tty to /dev/console it works
i dont know how it works exactly but anyway it works. (ㅠ.ㅠ)
cf: https://unix.stackexchange.com/questions/692257/why-no-such-device-or-address-when-open-dev-tty-in-the-first-process/

@wherehows It works when I'm using terminal panel, but doesn't work when using the SOURCE CONTROL gui panel (commit by press 'Commit' button), do you have same problem, and do you solve it if so?

VSCode said .husky/pre-commit: line 4: /dev/console: No such device or address

not only source control but also 'fork' tool doesnt work. i haven't solved it yet ㅠ.ㅠ

@siarheiyelin
Copy link

I managed to solve the issue by downgrading "lint-staged" from 13.x to 12.x

@iiroj
Copy link

iiroj commented Mar 5, 2023

@siarheiyelin Are you sure downgrading lint-staged fixes it? If so, I can take a look at the updates/changes in version 13 and try out if a culprit can be found.

@iiroj
Copy link

iiroj commented Mar 5, 2023

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.

@loriswit
Copy link

loriswit commented Mar 5, 2023

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 This fixes the repeated logs issue (as seen in #968 (comment)), but shows instead the uncolored output as described in the original post. I guess this is better than the repeated outputs, but we're basically back to where we started.

@Geczy
Copy link

Geczy commented Mar 8, 2023

image

same problem here

VSCode said .husky/pre-commit: line 4: /dev/console: No such device or address

@Geczy
Copy link

Geczy commented Mar 8, 2023

#968 (comment)

this comment fixed the original issue for me. i reverted my pre-commit file

@webbertakken
Copy link

Documented a combination of fixes in https://gist.github.com/webbertakken/c2b457d39224baf701c8de1589b61555.

Works for:

  • 🍎 MacOS using Zsh (cli) or IDE (no tty)
  • 💻 Ubuntu using Zsh (cli) or IDE (no tty)
  • 🪟 Windows using Git Bash or PowerShell or IDE (no tty)

Tested with WebStorm IDE and latest git versions.

@Geczy @akmaldira @MrFlyHouse @loriswit this should solve your problems as well.

riuandg5 added a commit to riuandg5/task-execute that referenced this issue Aug 8, 2023
Git hooks output running using husky gives output as a plain text without animated log when npx lint-staged is used. A temporary fix of redirecting stdout and stderr taken from typicode/husky#968 (comment) works for the current version of husky and lint-staged.
riuandg5 added a commit to riuandg5/task-execute that referenced this issue Aug 11, 2023
This reverts commit 145923d. The workaround was taken from typicode/husky#968 (comment) which corrected the husky log output with lint-staged but lead to error "/dev/tty: No such device or address" while using semantic-release.
@sbiliaiev
Copy link

@webbertakken Thank you! Your script is exactly what I was looking for! I've tried settings manually FORCE_COLOR to 0 and 1 as it's written in other guides but it didn't help me.
Cheers!

@mreduar
Copy link

mreduar commented Jan 21, 2024

Documented a combination of fixes in https://gist.github.com/webbertakken/c2b457d39224baf701c8de1589b61555.

Works for:

  • 🍎 MacOS using Zsh (cli) or IDE (no tty)
  • 💻 Ubuntu using Zsh (cli) or IDE (no tty)
  • 🪟 Windows using Git Bash or PowerShell or IDE (no tty)

Tested with WebStorm IDE and latest git versions.

@Geczy @akmaldira @MrFlyHouse @loriswit this should solve your problems as well.

Unfortunately it does not work with Windows Terminal WSL under a docker container. For example using Laravel Sail.

@its-monotype
Copy link

@typicode It's not fixed in v9? I'm facing the same issue...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests