-
Notifications
You must be signed in to change notification settings - Fork 33
Allow xq to be used as a pre-commit hook
#143
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
base: master
Are you sure you want to change the base?
Conversation
This change makes it so that the names for all of the YAML files in this repository end with “.yaml” instead of “.yml”. According to the IANA Media Types list, “yaml” is the preferred file extension for YAML files. “yml” is still a valid file extension, but it’s not preferred [1]. Additionally, there are some situations where you need to use “yaml” instead of “yml”. Specifically, if you want to create a pre-commit [2] hook repository, then you need to create a file named “.pre-commit-hooks.yaml”. If you create a file named “.pre-commit-hooks.yml”, then pre-commit will fail with this error [3]: > An error has occurred: InvalidManifestError: > =====> /home/jayman/.cache/pre-commit/repo5e3r89vk/.pre-commit-hooks.yaml is not a file > Check the log at /home/jayman/.cache/pre-commit/pre-commit.log The main motivation behind this change is to prepare for a future commit. That future commit will add a .pre-commit-hooks.yaml file. It would be inconsistent if some YAML files ended with “.yaml” and others ended with “.yml”. This commit ensures that we end up using the same file extension for every YAML file in this repository even after a .pre-commit-hooks.yaml file is added. --- When making this change, I was concerned that renaming all of these files might break something so I did some research. I tried to find sources that would confirm that each of the affect files is allowed to use “.yaml” instead of “.yml”. • .github/dependabot.yaml: <dependabot/dependabot-core#9789 (comment)> • .github/workflows/*: <https://docs.github.com/en/actions/reference/workflows-and-actions/workflow-syntax#about-yaml-syntax-for-workflows> • .goreleaser.yaml: <https://goreleaser.com/customization/#fn:goreleaser-yaml> • codecov.yaml: I couldn’t find a citation for this one, so I decided to follow this codecov tutorial [4][5]. When I got to the part of the tutorial that told me to create a “codecov.yml” file, I decided to create a “codecov.yaml” file instead. Everything seemed to work fine when using “codecov.yaml” instead of “codecov.yml”. I was able to verify that codecov.yaml was being read by Codecov by logging in to Codecov, selecting the repository, going to the “Configuration” tab and going to the “Yaml” section. Whenever I changed codecov.yaml in the repository’s main branch, the contents of the Configuration tab’s Yaml section were updated. • docker-compose.yaml: <https://docs.docker.com/compose/intro/compose-application-model#the-compose-file> --- This change was created using this Bash script: #!/usr/bin/env bash set -o errexit -o nounset -o pipefail git ls-files -z | while read -rd '' path do if [[ "$path" == *.yml ]] then git mv -- "$path" "${path/%.yml/.yaml}" fi done After running that script, I ran “git grep .yml” and manually updated anything that referenced one of the old file paths. --- [1]: <https://www.iana.org/assignments/media-types/application/yaml> [2]: <https://pre-commit.com> [3]: <https://codeberg.org/JasonYundt/pre-commit-file-extension-test> [4]: <https://docs.codecov.com/docs/gitlab-tutorial> [5]: <https://gitlab.com/Jayman2000/codecov-demo>
The main motivation behind this change is to prepare for a future commit. That future commit will make it possible to use xq as a pre-commit [1] hook. The idea is that the xq pre-commit hook will fail if any XML files in the repository aren’t formatted the way that xq would format them. In order for a pre-commit hook to report a failure, it must do the following [2]: > The hook must exit nonzero on failure or modify files. Before this change, xq did neither of those things. This change makes it so that xq will modify unformatted files if the --overwrite option is used. I could have added an option that made xq exit with a nonzero exit status, but I thought that making xq modify files would be more convenient and make more sense. [1]: <https://pre-commit.com> [2]: <https://pre-commit.com#new-hooks>
The main motivation behind this change is prepare for a future commit. That future commit will make it so that you can use xq as a pre-commit [1] hook. When pre-commit executes a pre-commit hook, it passes each file that the hook should be run on as a command-line argument. In order for xq to work properly as a pre-commit hook, xq needs to support passing multiple files as command-line arguments. [1]: <https://pre-commit.com>
This changes makes it so that you can use pre-commit [1] to help make sure that any XML files in your Git repositories are always formatted nicely. [1]: <https://pre-commit.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I prefer to stay aligned with GitHub docs, Dependabot default configuration, and thousands of other repos.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So are you saying that I should change this pull request so that it doesn’t change .github/dependabot.yml’s filename to .github/dependabot.yaml?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, thank you. I'll rework some parts based on your ideas. For example, I prefer to go with the "-i" option for conformity with sed and Perl. Also, I would like to cover changes with tests to avoid regression issues.
This pull request makes it so that you can use pre-commit to automatically run
xqfor you so that you don’t forget to format your XML files.See the commit messages for details.