nitpick icon indicating copy to clipboard operation
nitpick copied to clipboard

pre-commit list keys are incomplete

Open mondeja opened this issue 2 years ago • 0 comments

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.

mondeja avatar Jun 05 '22 18:06 mondeja