Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/perlpunk/yamltidy
Automatic cleanup of YAML files
https://github.com/perlpunk/yamltidy
formatter lint tidy yaml
Last synced: 3 months ago
JSON representation
Automatic cleanup of YAML files
- Host: GitHub
- URL: https://github.com/perlpunk/yamltidy
- Owner: perlpunk
- License: other
- Created: 2020-08-28T21:43:36.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2024-05-15T12:42:00.000Z (8 months ago)
- Last Synced: 2024-10-24T13:42:25.257Z (3 months ago)
- Topics: formatter, lint, tidy, yaml
- Language: Perl
- Homepage: https://perlpunk.github.io/yamltidy
- Size: 354 KB
- Stars: 6
- Watchers: 4
- Forks: 0
- Open Issues: 10
-
Metadata Files:
- Readme: README.md
- Changelog: Changes
- Contributing: CONTRIBUTING.md
- License: LICENSE
Awesome Lists containing this project
README
# yamltidy - Automatic cleanup of YAML files
yamltidy is a formatter for YAML files.
It's is inspired by the great tools
[yamllint](https://yamllint.readthedocs.io/en/stable/) and
[perltidy](https://metacpan.org/pod/Perl::Tidy).* yamllint checks YAML files and reports errors and warnings.
* perltidy automatically reformats perl programs
* yamltidy automatically reformats YAML files## Usage
```
% yamltidy foo.yaml
---
a: # a comment
b:
c: d# inplace - directly write result into original file
yamltidy --inplace foo.yaml
```Complete documentation of options: [yamltidy.pod](lib/yamltidy.pod)
## Installation
If you don't have a Perl CPAN client to install modules, install cpanminus:
# debian example
% apt-get install cpanminus
# openSUSE
% zypper install perl-App-cpanminusInstall yamltidy
% cpanm YAML::Tidy
# faster without running tests
% cpanm --notest YAML::Tidy### Local installation
If you just want to play with it, but don't want to install it globally on your
system, use this:% cpanm -l ~/localyamltidy YAML::Tidy
% export PERL5LIB=~/localyamltidy/lib/perl5
% PATH=~/localyamltidy/bin:$PATH### Use Container Image
% docker pull perlpunk/yamltidy
% docker run -i --rm perlpunk/yamltidy yamltidy - < in.yaml## Config
The configuration is similar as for yamllint.
It's written in YAML, and it searches for it in these places:
* `$PWD/.yamltidy`
* `~/.config/yamltidy/config.yaml`
* `~/.yamltidy`You can pass the configuration file via the `-c`/`--config-file` switch.
The default config:
---
v: v0.1
indentation:
spaces: 2
block-sequence-in-mapping: 0
trailing-spaces: fix
header: true
scalar-style:
default: plain
adjacency: 0An indentation of two spaces is recommended.
Sequences will by default be zero-indented, because the hyphen `-` counts
as indentation.
The option `block-sequence-in-mapping` can influence that.More detailed information on configuration will follow.
You can find examples for several configurations here:
[perlpunk.github.io/yamltidy](https://perlpunk.github.io/yamltidy)## Utils
## Mappings for vim
Type `yt` to tidy the whole buffer:
:noremap yt :%!yamltidy -
Visually select lines and type `yt`. The first level of indentation
spaces will be kept.:vnoremap yt :!yamltidy --partial -
## Tests
yamltidy tests are using the [YAML Test
Suite](https://github.com/yaml/yaml-test-suite).The tests currently make sure that at least the yamltidy output semantically
matches the input.## Implementation
yamltidy is based on [C libyaml](https://github.com/yaml/libyaml) and
[the perl binding YAML::LibYAML::API](https://metacpan.org/pod/YAML::LibYAML::API).