Skip to main content

automates the fixing of problems reported by yamllint

Project description

Docker Image Kataocda scenario

PyPI PyPI - Python Version PyPI - Downloads

❔ About

yamlfixer automates the fixing of problems reported by yamllint by parsing its output.

📑 Prerequisites

💡 You can try the install process online thanks to the dedicated Katacoda scenario.

In order for it to work, yamlfixer needs that the following utilities are already installed on your system, in a directory present in your $PATH :

  • Python v3.6 (or higher)
  • yamllint v1.26.3 (or higher)

Then simply install yamlfixer from pypi

python3 -m pip install yamlfixer-opt-nc

🚀 Usage

This software automatically fixes some errors and warnings reported by yamllint.

usage: yamlfixer [-h] [-v] [-b] [-d] [-j | -c | -s] [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 as `.orig`
  -d, --debug         output debug information to stderr.
  -j, --jsonsummary   output JSON summary to stderr.
  -c, --colorsummary  output colored plain text summary to stderr. If stderr
                      is not a TTY output is identical to --summary.
  -s, --summary       output plain text summary to stderr.

yamlfixer launches yamllint on each specified filename, then parses its output and try 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.

Both summaries and diagnostic information are sent to stderr.

This command exits with -2 if yamllint is not available on your system. Otherwise it exits with 0 if all input files either are skipped or successfully pass yamllint strict mode, else -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 tips

⏩ 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 vlidated json output) :

  "filestofix": 1,
  "passedstrictmode": 1,
  "modified": 0,
  "skipped": 0,
  "notwriteable": 0,
  "unknown": 0,
  "details": {
    "/home/jerome/yamlfixer/bad.yml": {
      "status": "PASSED",
      "issues": 0,
      "handled": 0
    }
  }
}

Check if yamlfixer could fix a yaml and get the exit code

See how piping fixing and linting can be intersting... and get exit code so you can go furher in automation :

yamlfixer <bad.yml | yamllint --format parsable --strict -
echo $?

🔖 Related contents

📖 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, has a corporate website on www.opt.nc

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

yamlfixer-opt-nc-0.3.4.tar.gz (24.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

yamlfixer_opt_nc-0.3.4-py3-none-any.whl (22.9 kB view details)

Uploaded Python 3

File details

Details for the file yamlfixer-opt-nc-0.3.4.tar.gz.

File metadata

  • Download URL: yamlfixer-opt-nc-0.3.4.tar.gz
  • Upload date:
  • Size: 24.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/34.0 requests/2.22.0 requests-toolbelt/0.8.0 urllib3/1.26.8 tqdm/4.30.0 importlib-metadata/4.11.3 keyring/18.0.1 rfc3986/2.0.0 colorama/0.4.3 CPython/3.8.10

File hashes

Hashes for yamlfixer-opt-nc-0.3.4.tar.gz
Algorithm Hash digest
SHA256 1feb8f3a5d852ac880fb9cbffe743d6fd2ed241da9afe18b8cf9a23fca40fe94
MD5 302674979f815b965fb244ecc8765236
BLAKE2b-256 99ae530202df2a3a686ba13f8b0e103434ae95db19d132d48a1c18b4358fa5fe

See more details on using hashes here.

File details

Details for the file yamlfixer_opt_nc-0.3.4-py3-none-any.whl.

File metadata

  • Download URL: yamlfixer_opt_nc-0.3.4-py3-none-any.whl
  • Upload date:
  • Size: 22.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/34.0 requests/2.22.0 requests-toolbelt/0.8.0 urllib3/1.26.8 tqdm/4.30.0 importlib-metadata/4.11.3 keyring/18.0.1 rfc3986/2.0.0 colorama/0.4.3 CPython/3.8.10

File hashes

Hashes for yamlfixer_opt_nc-0.3.4-py3-none-any.whl
Algorithm Hash digest
SHA256 acfe8136953d8f730bb94dd476f76d859a70b451d48c7592b317b69b3c169f0d
MD5 ee7b86f2b0367fa44295a1d87c17c2a8
BLAKE2b-256 4f047e956dc63f57671206a388d331d1123105e44e9d288b3130ab3cf775eba4

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page