Allow xq to be used as a pre-commit hook#143
Open
Jayman2000 wants to merge 4 commits intosibprogrammer:masterfrom
Open
Allow xq to be used as a pre-commit hook#143Jayman2000 wants to merge 4 commits intosibprogrammer:masterfrom
xq to be used as a pre-commit hook#143Jayman2000 wants to merge 4 commits intosibprogrammer:masterfrom
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>
Owner
There was a problem hiding this comment.
I prefer to stay aligned with GitHub docs, Dependabot default configuration, and thousands of other repos.
Contributor
Author
There was a problem hiding this comment.
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?
Owner
There was a problem hiding this comment.
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 file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.