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

Autoformat bash scripts, yaml files, and markdown files with pre-commit #1996

Merged
merged 15 commits into from
Jan 20, 2021

Conversation

manics
Copy link
Member

@manics manics commented Jan 17, 2021

Closes #1899

For discussion:

  • shellcheck (first 3 commits): I think it should be useful, and I've configured it to ignore the current warnings from ci/common. It's not automatically installed though by pre-commit (in contrast to the other autoformatters where running pre-commit will auto-download it for you), so I've put it in a separate configuration file and added a second step to test_chart.yaml to run it.

          - uses: pre-commit/action@v2.0.0
            with:
              extra_args: --config .pre-commit-shellcheck.yaml

    It picked up one minor error- ci/common uses bash not sh syntax. Should we keep shellcheck, make it part of the default pre-commit-config.yaml, or drop it?

  • helmlint: should be fine

  • prettier (last three commits): I've excluded jupyterhub/templates/ (not proper yaml files) and *.md (it makes the diff hard to review so probably best left for a separate commit after this is reviewed). There was minor one error, see 662f5e8 . The other thing to note is that had to override it's default of double quotes to use single quotes instead, this is because chartpress uses single quotes when resetting jupyterhub/values.yaml. Should we go ahead and auto-format markdown files too?

@consideRatio
Copy link
Member

consideRatio commented Jan 19, 2021

Seems good overall to me @manics, thanks for your work!

The other thing to note is that had to override it's default of double quotes to use single quotes instead, this is because chartpress uses single quotes when resetting jupyterhub/values.yaml.

Arrrgh, I'd like to avoid having both double quote and single quote enforced in different contexts. I remember this issue with chartpress, doh! Perhaps we can coerce chartpress with a new behavior instead? I believe I have tried in the past unsuccessfully though.

Should we go ahead and auto-format markdown files too?

Sure, they are prone to formatting errors. We are using MyST markdown, I wonder if there are some linting and or autoformatting or similarly for MyST specifically btw. I'll investigate.


Update:

  • VSCode extension for MyST!
  • MDFormat with pre-commit hooks available. I'm not sure about complexities of using MyST in general for markdown formatting, but I like the idea of using MDFormat as it is seeminlgy being developed to work with MyST in a sensible way, see this issue for example.

Update:

  # Markdown formatting
  - repo: https://github.com/executablebooks/mdformat
    rev: 0.5.5
    hooks:
      - id: mdformat
        additional_dependencies:
          # Autoformat nested Python code: https://github.com/hukkinj1/mdformat-black
          - mdformat-black

          # Autoformat nested json/yaml/toml: https://github.com/hukkinj1/mdformat-config
          - mdformat-config

          # Tolerate GitHub flavored markdown: https://github.com/hukkinj1/mdformat-gfm
          - mdformat-gfm

Update:

mdformat-config did the following, hmm...

  1. Single quotes over double.
  2. Not indent YAML lists. I want us to stick with indentation. There have been some situations while working with Helm templates where we could either render a list or a dict that made it required to have indentation before - item was printed. Due to that, I'm quite opinionated about indenting lists if we are going to choose one.
    spec:
-     storageClassName: ""
+     storageClassName: ''
      accessModes:
-       - ReadWriteMany
+     - ReadWriteMany

@consideRatio
Copy link
Member

@manics chartpress will not disrupt us after jupyterhub/chartpress#115 is merged and released. It will properly preserve no / single / double quotes for Chart.yaml / values.yaml then.

@consideRatio
Copy link
Member

consideRatio commented Jan 20, 2021

Requested action points

Bonus action points

  • Decide on mdformat / prettier for markdown.
    I'm since just now in favor of prettier as we use it for our dedicated yaml files etc.
  • Enable use of prettier for markdown also, it takes care of the yaml/json examples in our code blocks and doesn't cause problems even if we use MyST it seems.
  • Actuall perform: run pre-commit --all-files

manics and others added 7 commits January 20, 2021 07:55
ci/common contains bash-specific syntax, and triggers several warnings
```
tools/templates/lint-and-validate-values.yaml
[error] tools/templates/lint-and-validate-values.yaml: SyntaxError: Map keys must be unique; "nodeSelector" is repeated (11:3)
```
@consideRatio
Copy link
Member

consideRatio commented Jan 20, 2021

@manics is it okay if I --force push to this branch? (changes here: https://github.com/consideRatio/zero-to-jupyterhub-k8s/commits/pre-commit-2)

  • I omitted f000c75 specifically and added commits on top of it
  • Rebased on master
  • Configured pre-commit for markdown, yaml double quotes, bumped non-deprecated version of prettier, bump shellcheck version.

What would remain then:

@manics
Copy link
Member Author

manics commented Jan 20, 2021

Go ahead and push

@consideRatio consideRatio marked this pull request as ready for review January 20, 2021 09:14
@consideRatio consideRatio changed the title Pre commit 2 Autoformat bash scripts, yaml files, and markdown files with pre-commit Jan 20, 2021
@consideRatio
Copy link
Member

@manics this LGTM now, what do you think?

I did a visual inspection of the markdown and is generally happy about the kind of formatting changes there, as well as in the YAML now that we have double quotes which is the default. With prettier, we also automatically get indentation within the yaml syntax highlighted code blocks! We don't get python black formatting with in the python code blocks though.

Copy link
Member Author

@manics manics left a comment

Choose a reason for hiding this comment

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

Seems fine to me! Thanks for finishing this off.

@consideRatio consideRatio merged commit 6a3df2d into jupyterhub:master Jan 20, 2021
@consideRatio
Copy link
Member

🎉 thanks for starting it up!

consideRatio pushed a commit to jupyterhub/helm-chart that referenced this pull request Jan 20, 2021
@manics manics deleted the pre-commit-2 branch January 20, 2021 12:34
@consideRatio
Copy link
Member

@manics it has been a great success to use prettier I think! :D I catch several syntax errors because it fails to autoformat invalid python code! ❤️

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

Successfully merging this pull request may close these issues.

What to execute with pre-commit for a good developer experience?
2 participants