yamlfixer-opt-nc
Automates the fixing of problems reported by yamllint by parsing its output
Science Score: 44.0%
This score indicates how likely this project is to be science-related based on various indicators:
-
✓CITATION.cff file
Found CITATION.cff file -
✓codemeta.json file
Found codemeta.json file -
✓.zenodo.json file
Found .zenodo.json file -
○DOI references
-
○Academic publication links
-
○Committers with academic emails
-
○Institutional organization owner
-
○JOSS paper metadata
-
○Scientific vocabulary similarity
Low similarity (11.9%) to scientific vocabulary
Keywords
Keywords from Contributors
Repository
Automates the fixing of problems reported by yamllint by parsing its output
Basic Info
- Host: GitHub
- Owner: opt-nc
- License: gpl-3.0
- Language: Python
- Default Branch: main
- Homepage: https://dev.to/adriens/series/18168
- Size: 638 KB
Statistics
- Stars: 62
- Watchers: 2
- Forks: 9
- Open Issues: 33
- Releases: 69
Topics
Metadata Files
README.md
yamlfixer
❔ About
yamlfixer automates the fixing of problems reported by yamllint by parsing its output.
🖼️ Screenshot
Here'a screenshot of yamlfixer launched on yaml-test-suite :

📑 Installation
The easiest way to install yamlfixer is from
pypi, as described
below.
🐧 Linux install
shell
python3 -m pip install yamlfixer-opt-nc
🪟 Windows install
shell
python -m pip install yamlfixer-opt-nc
pipx setup
For an optimal experience we recommand using pipx.
To install :
shell
pipx install yamlfixer-opt-nc
pipx list
To upgrade :
shell
pipx upgrade yamlfixer-opt-nc
To uninstall :
pipx uninstall yamlfixer-opt-nc
🚀 Usage
This software automatically fixes some errors and warnings reported by
yamllint.
```shell usage: yamlfixer [-h] [-v] [-b] [-B BACKUPSUFFIX] [-d] [-D DIFFFILE] [-e EXTENSIONS] [-f] [-F] [-l] [-N] [-n] [-r LEVEL] [-j | -p | -s] [-t TABSIZE] [-c CONFIGFILE | -C CONFIGDATA] [FILEorDIR [FILEor_DIR ...]]
Fix formatting problems in YAML documents. If no file is specified, then reads input from stdin.
positional arguments:
FILEorDIR 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.
-D DIFFFILE, --diffto DIFFFILE
name of the file a unified diff will be written to.
Defaults to /dev/null.
-e EXTENSIONS, --ext EXTENSIONS
comma separated list of acceptable extensions when searching directories
for YAML files. Defaults to yaml,yml,yamllint.
-f, --forcecolors force colorized output even if stream is not a TTY.
-F, --followsymlinks follow symbolic links when recursing directories.
-l, --listfixers output the list of available fixers.
-N, --nosyntax don't try to fix syntax errors.
-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 colorized plain text summary to stderr. If stderr is not a TTY
output is identical to --plainsummary unless --forcecolors is also used.
-t TABSIZE, --tabsize TABSIZE
sets the number of spaces to replace tabs with, default is 2.
-c CONFIGFILE, --config-file CONFIGFILE
path to yamllint's custom configuration file, none by default.
-C CONFIGDATA, --config-data CONFIGDATA
custom configuration for yamllint as YAML source, none by default.
```
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 :
shell
$ find . -type f -name "*.yml" >list-of-yaml-files
$ yamlfixer --nochange --summary @list-of-yaml-files
Although this could probably be shortened to :
shell
$ 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... ⚠️
✍️ Blogging
You can find dedicated ressources on yamlfixer on :
:octocat: GitHub Action
You can now use this software as a GitHub Action, available from https://github.com/opt-nc/yamlfixer-action . This GitHub Action will automatically create Pull Requests to your repository with the changes made by yamlfixer.
✔️ Fixers
yamlfixer currently (as of 0.9.11) can fix
the following problems as reported by yamllint :
- comment not indented like content (comments-indentation)
- found forbidden document end
- found forbidden document start
- line too long
- missing document end
- missing document start
- missing starting space in comment (comments)
- no new line character at the end of file
- syntax error: could not find expected ':' (syntax)
- syntax error: expected
'<document start>', but found'<stream end>'(syntax) - syntax error: expected
<block end>, but found'<block mapping start>' - syntax error: expected
<block end>, but found'<block sequence start>'(syntax) - syntax error: expected
<block end>, but found'?' - syntax error: found character '\t' that cannot start any token (syntax)
- syntax error: mapping values are not allowed here
- too few spaces after comma (commas)
- too few spaces before comment (comments)
- too few spaces inside empty brackets (brackets)
- too few spaces inside brackets
- too many blank lines
- too many spaces after colon (colons)
- too many spaces after comma (commas)
- too many spaces after hyphen (hyphens)
- too many spaces before colon (colons)
- too many spaces before comma (commas)
- too many spaces inside braces (braces)
- too many spaces inside brackets (brackets)
- too many spaces inside empty brackets (brackets)
- trailing spaces (trailing-spaces)
- truthy value should be one of false, true
- wrong indentation: expected
- wrong new line character: expected \n
- wrong new line character: expected \r\n
An always up-to-date list of fixers can be obtained with yamlfixer --listfixers.
☝️ Please read our TODO list to see which problems are still unsupported but which we plan to support some day.
IMPORTANT : fixing syntax errors is done on a best effort basis and
may work only partially or not at all for you. Use the -N|--nosyntax
command line switch do prevent yamlfixer from trying to fix syntax
errors.
🎬 Demo
Click on the white triangle in the image below to view a short video demonstration:
💪 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 us love short and efficient command lines. Here are some ready to use ones :
Piping json summary through jq
yamlfixer --jsonsummary examples/good.yml 2>&1 | jq
So you can get a nicely colorized (and validated json output) :
json
{
"filestofix": 1,
"passed": 1,
"modified": 0,
"fixed": 0,
"skipped": 0,
"notwritable": 0,
"unknown": 0,
"nochangemode": false,
"details": {
"examples/good.yml": {
"numericstatus": 0,
"status": "PASSED",
"issues": 0,
"handled": 0
}
}
}
Check if yamlfixer could fix a yaml and get the exit code
See how to produce a patch file without modifying the original one, and get the exit code so you can go further in automation :
```shell $ yamlfixer --nochange --summary --diffto my.patch examples/bad.yml Files to fix: 1 0 files were already correct before 0 files were modified but problems remain 1 files were entirely fixed 0 files were skipped 0 files were not writable 0 files with unknown status FIXED examples/bad.yml (handled 4/4) WARNING: No file was modified per user's request !
$ echo $? 0
$ cat my.patch diff -u "examples/bad.yml" "examples/bad.yml-after" --- "examples/bad.yml" +++ "examples/bad.yml-after"
@@ -1,4 +1,4 @@
+--- name: Build HelloYaml
# yamllint disable-line rule:truthy @@ -17,6 +17,4 @@ cache: 'maven'
- name: Build with Maven
- run: mvn package
- + run: mvn package $ ```
You can then manually apply the patch file to modify examples/bad.yml if
that's what you want to do :
shell
$ patch -p0 <my.patch
patching file examples/bad.yml
$
But of course, it would have been simpler to not use the --nochange
command line option in the first place, so that the file would have
been fixed automatically.
🧰 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
yamllinting and fixing - GH Action relying on this project
- Dedicated Katacoda scenario so you can see it live
- Yamlfixer video intro (French, 15')
- From
clito community DEV.to blog post to better understandyamlfixer inception, historyand 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/. ```
🧑🤝🧑 Contributing
You can contribute to this project by filing an issue or by sending a pull request
Please read our contributing guidelines before.
🧑🤝🧑 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.
Owner
- Name: OPT Nouvelle Caledonie
- Login: opt-nc
- Kind: organization
- Location: noumea, nouvelle caledonie
- Website: https://www.opt.nc
- Twitter: OPT_NC
- Repositories: 26
- Profile: https://github.com/opt-nc
Citation (CITATION.cff)
cff-version: 1.2.0 message: "Automates the fixing of problems reported by yamllint by parsing its output." type: software authors: - family-names: "ALET" given-names: "Jérôme" orcid: "https://orcid.org/0000-0002-0983-1498" - family-names: "SALES" given-names: "Adrien" orcid: "https://orcid.org/0000-0002-3171-7229" title: "yamlfixer" version: 1.0.0 doi: 10.5281/zenodo.1234 date-released: 2022-04-29 url: "https://github.com/opt-nc/yamlfixer" license: GNU General Public License v3.0
GitHub Events
Total
- Watch event: 6
- Issue comment event: 1
Last Year
- Watch event: 6
- Issue comment event: 1
Committers
Last synced: about 1 year ago
Top Committers
| Name | Commits | |
|---|---|---|
| Jérôme Alet | j****t@o****c | 276 |
| SALES | A****s@g****m | 50 |
| dependabot[bot] | 4****] | 11 |
| Michèle BARRE | m****e@o****c | 10 |
| Augustas | r****z@g****m | 2 |
Committer Domains (Top 20 + Academic)
Issues and Pull Requests
Last synced: 4 months ago
All Time
- Total issues: 41
- Total pull requests: 76
- Average time to close issues: 4 days
- Average time to close pull requests: 8 days
- Total issue authors: 13
- Total pull request authors: 9
- Average comments per issue: 3.0
- Average comments per pull request: 0.46
- Merged pull requests: 55
- Bot issues: 0
- Bot pull requests: 38
Past Year
- Issues: 0
- Pull requests: 0
- Average time to close issues: N/A
- Average time to close pull requests: N/A
- Issue authors: 0
- Pull request authors: 0
- Average comments per issue: 0
- Average comments per pull request: 0
- Merged pull requests: 0
- Bot issues: 0
- Bot pull requests: 0
Top Authors
Issue Authors
- adriens (18)
- tamere-allo-peter (11)
- mbarre (2)
- af-now-it (1)
- giggio (1)
- Cougar (1)
- BnGx (1)
- benedikt-bartscher (1)
- hanqyu (1)
- alvarogonzalez-packlink (1)
- stephanecollot (1)
- dosmanak (1)
- adam-rummer-hpe (1)
Pull Request Authors
- tamere-allo-peter (27)
- dependabot[bot] (21)
- github-actions[bot] (17)
- mbarre (4)
- adriens (3)
- dosmanak (2)
- richardsondev (1)
- DingGGu (1)
- AugustasV (1)
Top Labels
Issue Labels
Pull Request Labels
Packages
- Total packages: 1
-
Total downloads:
- pypi 10,097 last-month
- Total dependent packages: 0
- Total dependent repositories: 1
- Total versions: 64
- Total maintainers: 1
pypi.org: yamlfixer-opt-nc
automates the fixing of problems reported by yamllint
- Homepage: https://github.com/opt-nc/yamlfixer
- Documentation: https://yamlfixer-opt-nc.readthedocs.io/
- License: "GPLv3+"
-
Latest release: 0.9.15
published over 3 years ago
Rankings
Maintainers (1)
Dependencies
- actions/checkout v3 composite
- actions/setup-python v4 composite
- actions/checkout v3 composite
- github/codeql-action/analyze v2 composite
- github/codeql-action/autobuild v2 composite
- github/codeql-action/init v2 composite
- actions/checkout v3 composite
- docker/build-push-action v3.2.0 composite
- docker/login-action v2.1.0 composite
- actions/checkout v3 composite
- ncipollo/release-action v1 composite
- actions/checkout v3 composite
- actions/setup-python v4 composite
- pypa/gh-action-pypi-publish master composite
- python 3.11.0a7-alpine build