Package: yamlfixer-opt-nc
yamlfixer❔ Aboutyamlfixerautomates the fixing
of problems reported byyamllintby parsing its
output.🖼️  ScreenshotHere'a screenshot of yamlfixer launched onyaml-test-suite:📑 InstallationThe easiest way to installyamlfixeris frompypi, as described
below.🐧 Linux installpython3-mpipinstallyamlfixer-opt-nc🪟  Windows installpython-mpipinstallyamlfixer-opt-ncpipxsetupFor an optimal experience we recommand usingpipx.To install :pipxinstallyamlfixer-opt-nc
pipxlistTo upgrade :pipxupgradeyamlfixer-opt-ncTo uninstall :pipx uninstall yamlfixer-opt-nc🚀 UsageThis software automatically fixes some errors and warnings reported byyamllint.usage:yamlfixer[-h][-v][-b][-BBACKUPSUFFIX][-d][-DDIFF_FILE][-eEXTENSIONS][-f][-F][-l][-N][-n][-rLEVEL][-j|-p|-s][-tTABSIZE][-cCONFIG_FILE|-CCONFIG_DATA][FILE_or_DIR[FILE_or_DIR...]]FixformattingproblemsinYAMLdocuments.Ifnofileisspecified,thenreadsinputfrom`stdin`.

positionalarguments:FILE_or_DIRtheYAMLfilestofix.Use`-`toreadfrom`stdin`.

optionalarguments:-h,--helpshowthishelpmessageandexit-v,--versiondisplaythisprogram's version number and exit.-b, --backup          make a backup copy of original files.-B BACKUPSUFFIX, --backupsuffix BACKUPSUFFIXsets the suffix for backup files, `.orig` is the default.-d, --debug           output debug information to stderr.-D DIFF_FILE, --diffto DIFF_FILEname of the file a unified diff will be written to.Defaults to `/dev/null`.-e EXTENSIONS, --ext EXTENSIONScomma separated list of acceptable extensions when searching directoriesfor 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'ttrytofixsyntaxerrors.-n,--nochangedon't modify anything.-r LEVEL, --recurse LEVELsets the maximum recursion level for directories. Default is `0` meaningno 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 TTYoutput is identical to --plainsummary unless --forcecolors is also used.-t TABSIZE, --tabsize TABSIZEsets the number of spaces to replace tabs with, default is `2`.-c CONFIG_FILE, --config-file CONFIG_FILEpath to yamllint'scustomconfigurationfile,nonebydefault.-CCONFIG_DATA,--config-dataCONFIG_DATAcustomconfigurationforyamllintasYAMLsource,nonebydefault.yamlfixer launchesyamllinton each specified filename, then parses
its output and tries to fix the reported problems. The special
filename-meansstdin, and is assumed if there's no other
filename argument.If input is read fromstdin, the corrected output will be sent tostdout.Other files will be overwritten if needed. Original files,stdinexcepted, can be preserved as.origif the--backupcommand line
option is used. You can specify any other backup filename suffix with
the--backupsuffixcommand line option.Both summaries and diagnostic information are sent to stderr.This command exits with status2if there are incompatible command
line options. It exits with-2if yamllint is not available on your
system. Otherwise it exits with0if all input files either are
skipped, entirely fixed, or already successfully passedyamllintstrict 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@argsfilesyntax. For example you could do something like this :$find.-typef-name"*.yml">list-of-yaml-files
$yamlfixer--nochange--summary@list-of-yaml-filesAlthough this could probably be shortened to :$yamlfixer--nochange--summary--recurse-1.IMPORTANT:Not all problems are fixable byyamlfixer. Due to the
fact thatyamllintdoesn't currently report all faulty lines,yamlfixermight even introduce indentation problems under some
circumstances.⚠️Use at your own risk, you have been warned...⚠️✍️ BloggingYou can find dedicated ressources onyamlfixeron :Dedicated series on DEV.to:octocat: GitHub ActionYou can now use this software as a GitHub Action, available fromhttps://github.com/opt-nc/yamlfixer-action.
This GitHub Action will automatically create Pull Requests to your repository with the changes made by yamlfixer.✔️ Fixersyamlfixercurrently (as of0.9.11) can fix
the following problems as reported byyamllint:comment not indented like content (comments-indentation)found forbidden document endfound forbidden document startline too longmissing document endmissing document startmissing starting space in comment (comments)no new line character at the end of filesyntax 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 heretoo few spaces after comma (commas)too few spaces before comment (comments)too few spaces inside empty brackets (brackets)too few spaces inside bracketstoo many blank linestoo 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] (truthy)wrong indentation: expectedwrong new line character: expected \nwrong new line character: expected \r\nAn always up-to-date list of fixers can be obtained withyamlfixer --listfixers.☝️ Please read ourTODO listto 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 preventyamlfixerfrom trying to fix syntax
errors.🎬 DemoClick on the white triangle in the image below to view a short video demonstration:💪 Tips and tricksFind 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 linersMost of us love short and efficient command lines. Here are some ready to use ones :Pipingjsonsummary throughjqyamlfixer --jsonsummary examples/good.yml 2>&1 | jqSo you can get a nicely colorized (and validatedjsonoutput) :{"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 ifyamlfixercould fix ayamland get the exit codeSee how to produce a patch file without modifying the original one,
and get the exit code so you can go further in automation :$yamlfixer--nochange--summary--difftomy.patchexamples/bad.yml
Filestofix:10fileswerealreadycorrectbefore0filesweremodifiedbutproblemsremain1fileswereentirelyfixed0fileswereskipped0fileswerenotwritable0fileswithunknownstatusFIXEDexamples/bad.yml(handled4/4)WARNING:Nofilewasmodifiedperuser's request !$ echo $?0$ cat my.patchdiff -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:BuildwithMaven
-run:mvnpackage
-
-
+run:mvnpackage
$You can then manually apply the patch file to modifyexamples/bad.ymlif
that's what you want to do :$patch-p0<my.patch
patchingfileexamples/bad.yml
$But of course, it would have been simpler to not use the--nochangecommand line option in the first place, so that the file would have
been fixed automatically.🧰 Single purpose tools worth knowingytt:"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 contentsDedicated Post explaining how we are using this project to automateyamllinting and fixingGH Action relying on this projectDedicated Katacoda scenarioso you can see it liveYamlfixer video intro (French, 15')Fromclito community DEV.to blog postto better understandyamlfixer inception, historyand roadmap📖 Licensing informationCopyright (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/>.🧑‍🤝‍🧑 ContributingYou can contribute to this project byfiling an issueor bysending a pull requestPlease read ourcontributing guidelinesbefore.🧑‍🤝‍🧑 ContactTo contact theauthorsof this software, simply fill an
issue on this project.OPT-NC, akaOffice des Postes et Télécommunications de Nouvelle-Calédonie, checkOPT-NCGithub Organization page for more.