Skip to content

Problem using prettier as a git hook. #2978

@migrachev

Description

@migrachev

[Explaning my problem]
Hello I am trying to use prettier as pre-commit git hook (along with WebStorm).
I had the problem that even after I commit my changes, my files are marked as changed and git status and git diff output something strange. I spent some time investigating the problem and I reproduce it directly from the command line, excluding WebStorm from the problem. Since the problem occurs only when prettier prettifies my files my conclusion was that the problem must be in prettier not git.

[If you are in a hurry]
Just go to My Simple Example

[The actual problem]
When I commit a file that is considered ugly by prettier, the git hook that i have defined invoke prettier on the file, makes it pretty and then git performs the commit. At that point my expectations are that there will be no changes in my working directory, however git does not think so.

[Why do I think the problem comes from prettier and not git]

  • If the changed file is considered pretty by prettier, it seems that prettier does not process it and the problem does not reproduce.
  • According to the internet changing the source code in pre-commit git hooks seems to be a practice and it should work fine.

[My Simple Example]

Metadata

Metadata

Assignees

No one assigned

    Labels

    locked-due-to-inactivityPlease open a new issue and fill out the template instead of commenting.scope:externalThis is not an issue with Prettier, it’s an issue with external software, like an editor integrationtype:questionQuestions and support requests. Please use Stack Overflow for them, not the issue tracker.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions