automates the fixing of problems reported by yamllint
Project description
yamlfixer
❔ About
yamlfixer automates the fixing of problems reported by yamllint by parsing its output.
🎬 Demo
Click on the white triangle in the image below to view a short video demonstration:
📑 Installation
💡 You can try the install process online thanks to the dedicated Katacoda scenario.
The easiest way to install yamlfixer
is from
pypi, as described
below.
🐧 Linux install
python3 -m pip install yamlfixer-opt-nc
🪟 Windows install
python -m pip install yamlfixer-opt-nc
pipx
setup
For an optimal experience we recommand using pipx
.
To install :
pipx install yamlfixer-opt-nc
pipx list
To upgrade :
pipx upgrade yamlfixer-opt-nc
To uninstall :
pipx uninstall yamlfixer-opt-nc
🚀 Usage
This software automatically fixes some errors and warnings reported by
yamllint
.
usage: yamlfixer [-h] [-v] [-b] [-B BACKUPSUFFIX] [-d] [-e extensions] [-l] [-n] [-r level] [-j | -p | -s] [-t TABSIZE] [file [file ...]]
Fix formatting problems in YAML documents. If no file is specified,
then reads input from `stdin`.
positional arguments:
file the YAML files to fix. Use `-` to read from `stdin`.
optional arguments:
-h, --help show this help message and exit
-v, --version display this program's version number and exit.
-b, --backup make a backup copy of original files.
-B BACKUPSUFFIX, --backupsuffix BACKUPSUFFIX
sets the suffix for backup files, `.orig` is
the default.
-d, --debug output debug information to stderr.
-e extensions, --ext extensions
comma separated list of acceptable extensions
when searching directories for YAML files.
Defaults to yaml,yml,yamllint
-l, --listfixers output the list of available fixers.
-n, --nochange don't modify anything.
-r level, --recurse level
sets the maximum recursion level for directories.
Default is 0 meaning no recursion, and any negative
value means no limit.
-j, --jsonsummary output JSON summary to stderr.
-p, --plainsummary output plain text summary to stderr.
-s, --summary output colored plain text summary to stderr.
If stderr is not a TTY output is identical to
--plainsummary.
-t TABSIZE, --tabsize TABSIZE
sets the number of spaces to replace tabs with,
default is 2.
yamlfixer launches yamllint
on each specified filename, then parses
its output and tries to fix the reported problems. The special
filename -
means stdin
, and is assumed if there's no other
filename argument.
If input is read from stdin
, the corrected output will be sent to
stdout
.
Other files will be overwritten if needed. Original files, stdin
excepted, can be preserved as .orig
if the --backup
command line
option is used. You can specify any other backup filename suffix with
the --backupsuffix
command line option.
Both summaries and diagnostic information are sent to stderr.
This command exits with status 2
if there are incompatible command
line options. It exits with -2
if yamllint is not available on your
system. Otherwise it exits with 0
if all input files either are
skipped, entirely fixed, or already successfully passed yamllint
strict mode before, else -1
.
For convenience, all or parts of the command line arguments can be
read from a file, one per line, by using the well known @argsfile
syntax. For example you could do something like this :
$ find . -type f -name "*.yml" >list-of-yaml-files
$ yamlfixer --nochange --summary @list-of-yaml-files
Although this could probably be shortened to :
$ yamlfixer --nochange --summary --recurse -1 .
IMPORTANT: Not all problems are fixable by yamlfixer
. Due to the
fact that yamllint
doesn't currently report all faulty lines,
yamlfixer
might even introduce indentation problems under some
circumstances.
⚠️Use at your own risk, you have been warned... ⚠️
💪 Tips and tricks
Find here a set of tips & tricks about how to achieve great things.
Don't find the usecase you're looking for ➡️ 🎫 Fill a dedicated issue so we could share your idea with the comunity
⏩ One liners
Most of use love short and efficient command lines. Here are some ready to use ones :
Piping json
summary through jq
yamlfixer --jsonsummary bad.yml 2>&1 | jq
So you can get a nicely colored (and validated json
output) :
"filestofix": 1,
"passedstrictmode": 1,
"modified": 0,
"fixed": 0,
"skipped": 0,
"notwriteable": 0,
"unknown": 0,
"details": {
"/home/jerome/yamlfixer/bad.yml": {
"status": "PASSED",
"issues": 0,
"handled": 0
}
},
"nochangemode": false
}
Check if yamlfixer
could fix a yaml
and get the exit code
See how piping fixing and linting can be interesting... and get exit code so you can go further in automation :
yamlfixer <bad.yml | yamllint --format parsable --strict -
echo $?
🧰 Single purpose tools worth knowing
ytt
: "YAML templating tool that works on YAML structure (instead of text)."jq
: "lightweight and flexible command-line JSON processor."vimdiff
: "edit two, three or four versions of a file with Vim and show differences"icdiff
: "improved colored diff "gomplate
: "A flexible commandline tool for template rendering. Supports lots of local and remote datasources."
🔖 Related contents
- Dedicated Post explaining how we are using this project to automate
yaml
linting and fixing - GH Action relying on this project
- Dedicated Katacoda scenario so you can see it live
- Yamlfixer video intro (French, 15')
- From
cli
to community DEV.to blog post to better understandyamlfixer inception, history
and roadmap
📖 Licensing information
Copyright (C) 2021-2022 OPT-NC
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
🧑🤝🧑 Contact
To contact the authors of this software, simply fill an issue on this project.
OPT-NC, aka Office des Postes et Télécommunications de Nouvelle-Calédonie, check
OPT-NC
Github Organization page for more.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for yamlfixer_opt_nc-0.5.4-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ff14af6f9e0e9ae6b63aea2cdac72fbeb09edf57df346bca24312edfcafa471a |
|
MD5 | 4f99b09c6cd917aadadd7ab73dd117b3 |
|
BLAKE2b-256 | bde3b403723e305805be0e23c3cf8b3dc489cda319adc2150845a3394dd0ff01 |