dragoonboots / yamlformatter
Auto-format YAML files with refs
This package's canonical repository appears to be gone and the package has been frozen as a result.
Installs: 2 538
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 0
Open Issues: 0
Requires
- php: ^7.3|^8.0
- ext-json: *
- opis/json-schema: ^1.0
- php-ds/php-ds: ^1.3
- symfony/console: ^5.0
- symfony/finder: ^5.0
- symfony/yaml: ^5.0
Requires (Dev)
- mikey179/vfsstream: ^1.6
- phpunit/phpunit: ^9.5
Suggests
- ext-ds: Allows a small speed/efficiency increase
This package is auto-updated.
Last update: 2022-11-12 20:34:28 UTC
README
Pretty-up your YAML files!
Features:
- Automatically add anchors/aliases for repeated data
- Remove unneeded whitespace
- Correct indentation
Usage
Install with Composer:
composer require dragoonboots/yamlformatter
See available options with vendor/bin/yamlformatter format --help
Usage:
format [options] [--] <INPUT> [<OUTPUT>]
Arguments:
INPUT Input file or directory
OUTPUT Output file or directory. Will overwrite when not specified.
Options:
-o, --override Override .yamlformatter.json options
--indent=INDENT Number of spaces to indent [default: 2]
--no-multiline-literal Write string literals with multiple lines with embedded escaped newlines instead of as a multi-line literal
--no-null-tilde Write null values as "null"
--no-anchors Do not create reference anchors
--anchors-include=ANCHORS-INCLUDE Regular expression for YAML path to generate anchors for. Keys are separated by periods. Defaults to generating anchors for everything. (multiple values allowed)
--anchors-exclude=ANCHORS-EXCLUDE Regular expression for YAML path to not generate anchors for. (multiple values allowed)
-h, --help Display help for the given command. When no command is given display help for the list command
-q, --quiet Do not output any message
-V, --version Display this application version
--ansi Force ANSI output
--no-ansi Disable ANSI output
-n, --no-interaction Do not ask any interactive question
-v|vv|vvv, --verbose Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug
For example:
Given a directory called resources/data
, this will add refs to all files in place:
vendor/bin/yamlformatter format resources/data
Do not generate refs automatically:
vendor/bin/yamlformatter format --no-anchors resources/data
Use a different output directory resources/cleaned
:
vendor/bin/yamlformatter format resources/data resources/cleaned
Options
If a file called .yamlformatter.json
is in the input directory, it will be used to set options. Any options set in
that file will override those passed on the command line, unless --override
is used!
The file contains a JSON object with the following properties. These properties serve the same function as the command-line switches, although some of them are negated:
- indentation
- multiLineLiteral
- nullAsTilde
- anchors
- include
- exclude
Here is an example:
{
"indentation": 2,
"multiLineLiteral": true,
"nullAsTilde": true,
"anchors": {
"exclude": [
"`.+\\.short_effect`"
]
}
}
If you use an editor like PHPStorm that supports JSON Schema, a validation schema is available here.
License
Licensed under the MIT license.