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

chore: Integrate yamllint into the project #747

Merged
merged 1 commit into from
Jan 9, 2025

Conversation

webknjaz
Copy link
Contributor

@webknjaz webknjaz commented Jan 8, 2025

The initial config does not change many defaults and mostly relies on the upstream config. The only changes are to the sequence style, quoting and allowed truthy values that accomodate for GHA.

Put an x into the box if that apply:

  • This PR introduces breaking change.
  • This PR fixes a bug.
  • This PR adds new functionality.
  • This PR enhances existing functionality.
  • This PR is contributor-facing, internal stuff.

Description of your changes

N/A

How can we test changes

..stare at the diff? tox r -qq -e pre-commit -- yamllint --all-files otherwise.

@webknjaz
Copy link
Contributor Author

webknjaz commented Jan 8, 2025

@yermulnik this is the yamllint config I was talking about earlier.

- file
- yaml
args:
- --strict
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This being a CLI argument is an exception and is here only because yamllint does not allow configuring it in the common config: adrienverge/yamllint#601.

@webknjaz
Copy link
Contributor Author

webknjaz commented Jan 8, 2025

Looks like the CI is having problems accessing DockerHub. It's not related to this PR and somebody should restart the CI jobs once GH fixes their platform issues.

- repo: https://github.com/adrienverge/yamllint.git
rev: v1.35.1
hooks:
- id: yamllint
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It not format yaml locally, that's is unfortunate.

Better use

  - repo: https://github.com/jumanjihouse/pre-commit-hook-yamlfmt
    rev: 0.2.3
    hooks:
      - id: yamlfmt
        args: [
          --mapping, '2',
          --sequence, '4',
          --offset, '2',
          --width, '100',
          --implicit_start,
          --preserve_null,
        ]

which actually format code, and enforce style which should be used here anyway

Copy link
Collaborator

@MaxymVlasov MaxymVlasov Jan 8, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

They actually can be combined by

    - repo: https://github.com/adrienverge/yamllint
      rev: v1.35.1
      hooks:
          - id: yamllint
            types:
                - file
                - yaml
            args: [--format, parsable, --strict]

    - repo: https://github.com/jumanjihouse/pre-commit-hook-yamlfmt
      rev: 0.2.3
      hooks:
          - id: yamlfmt

Just need to change .yamllint a bit
Nwm, yamlfmt don't uses .yamllint

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a linter, not a formatter. I'm yet to see a formatter working well. But FWIW this is out of the scope here. This PR is about a specific linter and anything else is an undesired scope creep that can be debated elsewhere.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

They actually can be combined by

This is a bad idea as formatters should always go before linters to prevent double errors.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In this case, yamllint is redundant as yamlfmt will fix all these issues
If you want to have it for some unknown to me reason, I can adjust yamllint config

There just only issue which I see - such type of comment are not handled properly by yamlfmt, but they always can be moved or above, or just get rid of >- in simple constructions
image

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Formatting is out of the scope. So that's irrelevant. But to answer the question about a separate line — no, it's not normally okay to put comments on a separate line due to context drifting. This is important in any code-like files, including but not limited to YAML. The comment is there intentionally and must not be moved.

Just to reiterate, the scope of this PR is solely adding one specific linter and nothing else. Any other attempts to change the scope indefinitely are to be rejected with prejudice.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you want to limit just to linter, here we go then.

@webknjaz webknjaz closed this Jan 8, 2025
@webknjaz webknjaz reopened this Jan 8, 2025
Comment on lines +6 to +8
indentation:
level: error
indent-sequences: false
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
indentation:
level: error
indent-sequences: false
indentation:
level: error
indent-sequences: true
line-length:
max: 100
document-start:
present: false
comments:
min-spaces-from-content: 1

Copy link
Contributor Author

@webknjaz webknjaz Jan 8, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the line length setting is unreasonably long. Also, double whitespace before a comment is an accepted convention. A single space seems dumb with this being required just about everywhere.
Unnecessary sequence indentation would just make the lines longer, forcing the increase of other rule defaults to ridiculous values.

In general, this suggestion looks like a snowball of bad changes.
Additionally, it's going to trigger more reformatting that is not in the scope right now. I don't want things to diverge from other projects just because of a silly nitpick. You can make the style less readable yourself, once I'm done sending patches.

Copy link
Collaborator

@MaxymVlasov MaxymVlasov Jan 9, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These "Unnecessary sequence indentation" exist by the same reason why Python have 4 space indentation, not 2 - it less error-prone.

It is much simpler to figure out where part args belong to in next construction

- repo: https://github.com/adrienverge/yamllint.git
  rev: v1.35.1
  hooks:
    - id: yamllint
      types:
        - file
        - yaml
     args:
        - --strict

than in

- repo: https://github.com/adrienverge/yamllint.git
  rev: v1.35.1
  hooks:
  - id: yamllint
    types:
    - file
    - yaml
   args:
    - --strict

just because you can't have list and K/V on the same level.

This is a common and very annoying problem, and the right solution to where indent should be is not covered by linters or formatters, so the only way to deal with it if there is no such indents and no jsonschema check - manually go and check documentation each time for tool or run this tool.

And just noticed "Unnecessary sequence indentation" - is default setting of yamllint itself, and YAML formatter built-in in VS Code which, btw, ignores .yamllint config, but respects .editorconfig

More complex solution to it could be indentation.spaces=4, but it looks much worse

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My bad, there are no built-in VS Code YAML formatter, it's provided by redhat.vscode-yaml extension.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the line length setting is unreasonably long

Second vertical line is 80 chars, third - 100 chars
Screenshot from 2025-01-09 15-09-08

You added 18 ignores for line-length in such simple project. And after that you said that it "unreasonably long"?

Screenshot from 2025-01-09 15-08-06

Copy link
Collaborator

@MaxymVlasov MaxymVlasov Jan 9, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

About

  document-start:
    present: false
  comments:
    min-spaces-from-content: 1

First is just my neat-peak to skip unnecessary syntax, second - how yamlfmt formats comments and that, sadly not configurable, but I love to have automation which able to maintain "good enough" style, than go and fix issues manually to the best possible style.
But yes, they both can be skipped for now

- repo: https://github.com/adrienverge/yamllint.git
rev: v1.35.1
hooks:
- id: yamllint
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you want to limit just to linter, here we go then.

@MaxymVlasov MaxymVlasov changed the title 🧪 Integrate yamllint into the project chore: Integrate yamllint into the project Jan 8, 2025
The initial config does not change many defaults and mostly relies on
the upstream config. The only changes are to the sequence style,
quoting and allowed truthy values that accomodate for GHA.
@webknjaz webknjaz force-pushed the maintenance/yamllint branch from c82f383 to f2ead2d Compare January 9, 2025 02:06
@webknjaz
Copy link
Contributor Author

webknjaz commented Jan 9, 2025

@yermulnik could you restart the cancelled job?

Copy link
Collaborator

@MaxymVlasov MaxymVlasov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will change it later

@MaxymVlasov MaxymVlasov merged commit 1c9823e into antonbabenko:master Jan 9, 2025
38 checks passed
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

Successfully merging this pull request may close these issues.

3 participants