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

fix: restore .pre-commit-hooks.yaml #1380

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

sqwhong
Copy link

@sqwhong sqwhong commented Dec 29, 2023

This file is essential when using pre-commit. It throws an error if this file is missing.

$ pre-commit run       
An error has occurred: InvalidManifestError: 
=====> /Users/username/.cache/pre-commit/reponfms5uhx/.pre-commit-hooks.yaml is not a file

Copy link

changeset-bot bot commented Dec 29, 2023

🦋 Changeset detected

Latest commit: 55a8318

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
lint-staged Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@iiroj
Copy link
Member

iiroj commented Dec 29, 2023

This looks like a configuration file for pre-commit and not really related to lint-staged. I'm closing this PR because I don't know why this file would be needed. It hasn't been needed so far so it's not a "fix" either.

@iiroj iiroj closed this Dec 29, 2023
@sqwhong
Copy link
Author

sqwhong commented Dec 29, 2023

@iiroj this was removed from this PR. without this file, i cannot initialize this hook with pre-commit.

@sqwhong
Copy link
Author

sqwhong commented Dec 29, 2023

we were upgrading lint-staged from an older version which supports pre-commit. but this file being removed makes lint-staged unusable by pre-commit without any note from releases. so it confused me as if it was unintentially deleted.

@iiroj
Copy link
Member

iiroj commented Dec 29, 2023

Thank you, you are correct.

@iiroj iiroj reopened this Dec 29, 2023
.changeset/quick-taxis-teach.md Outdated Show resolved Hide resolved
@iiroj
Copy link
Member

iiroj commented Dec 29, 2023

I guess I removed the file because it's undocumented and I simply didn't know about it... IMO it's a bit redundant to run two tools that provide the same functionality. Essentially pre-commit does the same things as lint-staged does:

https://pre-commit.com/#pre-commit

pre-commit is triggered before the commit is finalized to allow checks on the code being committed. Running hooks on unstaged changes can lead to both false-positives and false-negatives during committing. pre-commit only runs on the staged contents of files by temporarily stashing the unstaged changes while running hooks.

Because lint-staged also runs only on staged files, and also hides unstaged changes, I do not recommend running them both.

@iiroj
Copy link
Member

iiroj commented Dec 29, 2023

Does it work if you setup a local hook according to https://pre-commit.com/#repository-local-hooks

-   repo: local
    hooks:
    -   id: lint-staged
        name: lint-staged
        entry: lint-staged
        language: node
        pass_filenames: false # lint-staged handles staged files itself
        stages: [pre-commit]

Co-authored-by: Iiro Jäppinen <iiro@jappinen.fi>
@sqwhong
Copy link
Author

sqwhong commented Dec 29, 2023

local hook seems to work as the initialization passed. but it failed with this message:

lint-staged..............................................................Failed
- hook id: lint-staged
- exit code: 1

Executable `lint-staged` not found

it might be a different issue than what this PR is trying to solve, though

update: my config

- repo: local
    hooks:
      - id: lint-staged
        name: lint-staged
        entry: lint-staged
        language: node
        pass_filenames: false
        stages: [pre-commit]
        args: ["--config", ".lintstagedrc.json"]

@iiroj
Copy link
Member

iiroj commented Dec 29, 2023

If you don't mind posting your lint-staged and pre-commit configs, I could also take a look at them. I'm still debating whether it's a good idea to add this file back, as the two tools seem to be doing the same thing.

Maybe it would be possible for you to migrate to using only one of them... I can help.

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

Successfully merging this pull request may close these issues.

None yet

2 participants