Checks YAML files for correct syntax. Currently it checks for:
- Valid YAML syntax
- Overlapping key definitions in YAML files, where the last definition would win
This is a YAML version of jsonlint
Add this line to your application's Gemfile:
gem 'yamllint'
And then execute:
$ bundle
Or install it yourself as:
$ gem install yamllint
You can run yamllint against a set of files in the command line. Any errors will be printed and the process will exit with a non-zero exit code.
$ yamllint spec/data/*
spec/data/empty.yaml
The YAML should not be an empty string
spec/data/invalid.yaml
(<unknown>): found character that cannot start any token while scanning for the next token at line 1 column 6
spec/data/overlapping_keys.yaml
The same key is defined more than once: foo
spec/data/overlapping_keys_complex.yaml
The same key is defined more than once: foo
spec/data/overlapping_keys_deep.yaml
The same key is defined more than once: foo
spec/data/spaces.yaml
The YAML should not just be spaces
$
Short | Long | Description | Default |
---|---|---|---|
-D |
--debug |
Debug logging | false |
-d |
--disable-ext-check |
Disable file extension check | false |
-e |
--extensions= |
Add more allowed extensions (comma delimited list) | nil |
-h |
--help |
Show help message | false |
-v |
--version |
Print version and exit | false |
You can integrate yamllint into your build process by adding a Rake task to your project
require 'yamllint/rake_task'
YamlLint::RakeTask.new do |t|
t.paths = %w(
spec/**/*.yaml
)
end
Then run the rake task.
$ rake yamllint
spec/data/empty.yaml
The YAML should not be an empty string
spec/data/invalid.yaml
(<unknown>): found character that cannot start any token while scanning for the next token at line 1 column 6
spec/data/overlapping_keys.yaml
The same key is defined more than once: foo
spec/data/overlapping_keys_complex.yaml
The same key is defined more than once: foo
spec/data/overlapping_keys_deep.yaml
The same key is defined more than once: foo
spec/data/spaces.yaml
The YAML should not just be spaces
$
Add these options similarly to the path option seen above.
Option | Description | Default |
---|---|---|
debug |
Debug logging | false |
disable_ext_check |
Disable file extension check | false |
exclude_paths |
List of files or paths to exclude from linting | nil |
extensions |
Add more allowed extensions (list) | nil |
fail_on_error |
Continue on to the next rake task and don't fail even if YamlLint finds errors | true |
paths |
List of files or paths to lint | nil |
- Fork it ( https://github.com/shortdudey123/yamllint/fork )
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create a new Pull Request