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

pre-commit list keys are incomplete #492

Open
mondeja opened this issue Jun 5, 2022 · 0 comments
Open

pre-commit list keys are incomplete #492

mondeja opened this issue Jun 5, 2022 · 0 comments
Labels
bug Something isn't working

Comments

@mondeja
Copy link

mondeja commented Jun 5, 2022

Different pre-commit hooks with the same id but different repos are not properly checked.

I've created a repository with a minimal reproducible example to explain the problem. You can see the execution of nitpick check and three nitpick fix here.

Expected behavior

I would be fine if nitpick would output one of these outputs.

The first would be that there aren't violations, as could be interpreted like so:

repos:
  - repo: foo
    hooks:
      - id: bar
        files: bar-1
      - id: bar
        files: bar-2
      - id: bar-3
        files: bar-3
  - repo: foo
    hooks:
      - id: bar
        files: baz-1

The second, as there is no more fields at repo level, would be to merge the two repos because there are the same. This would be the optimal solution:

repos:
  - repo: foo
    hooks:
      - id: bar
        files: bar-1
      - id: bar
        files: bar-2
      - id: bar-3
        files: bar-3
      - id: bar
        files: baz-1

Current behavior

$ nitpick check
.pre-commit-config.yaml:1: NIP368  has missing values:
repos:
  - repo: foo
    hooks:
      - id: bar
        files: bar-3
  - repo: foo
    hooks:
      - id: bar
        files: baz-1
Violations: ❌ 1 to change manually.

Note that nitpick fix does not solves the problem, it enters in a infinite loop of rewritings.

Steps to reproduce

git clone https://github.com/mondeja/nitpick-pre-commit-list-keys-error
cd nitpick-pre-commit-list-keys-error
pip install nitpick
nitpick check

Possible Solution

I suspect that the logic of defining list keys in the YAML plugin is incomplete.

Context

I'm defining multiple hooks for the same repo from different style files and this bug stucked me. As a workaround, I'm defining the hooks in the same style file, but is not scalable.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
Status: Upvoted / Requests
Development

No branches or pull requests

1 participant