Yamllint: Difference between revisions

From Omnia
Jump to navigation Jump to search
Line 13: Line 13:
  https://yamllint.readthedocs.io/en/stable/
  https://yamllint.readthedocs.io/en/stable/


== default configuration ==
== Common Errors and Warnings ==
 
Obvious Errors (that shouldn't be errors, that I turned into warnings):
<pre>
* error    line too long (94 > 80 characters)  (line-length)
* error    no new line character at the end of file  (new-line-at-end-of-file)
</pre>
 
Errors related to bad indentation:
<pre>
* error    syntax error: expected <block end>, but found '<block mapping start>' (syntax)
* error    wrong indentation: expected 7 but found 8  (indentation)
* error    syntax error: mapping values are not allowed here (syntax)
</pre>
 
Error related to incomplete quoting:
<pre>
* error    syntax error: expected <block end>, but found '<scalar>' (syntax)
</pre>
 
Obvious Warnings:
<pre>
* warning  missing document start "---"  (document-start)
* warning  comment not indented like content  (comments-indentation)
</pre>


See https://yamllint.readthedocs.io/en/stable/configuration.html#default-configuration
== config file ==


Specify config with:
Specify config with:
Line 29: Line 53:
This did work:
This did work:
  ~/.config/yamllint/config
  ~/.config/yamllint/config
So I did this:
ln -s ~/.config/yamllint/config ~/.yamllint
== default configuration ==
See https://yamllint.readthedocs.io/en/stable/configuration.html#default-configuration


Default:
Default:
Line 68: Line 99:
     level: warning
     level: warning
</pre>
</pre>
== Extending Configuration ==


Extending to disable comments indentation:
Extending to disable comments indentation:

Revision as of 20:29, 25 February 2024

yamllint

Install:

apt install yamllint

Use:

yamllint file.yaml

Note:

  • Defaults to max lines 80 limit

Doc:

https://yamllint.readthedocs.io/en/stable/

Common Errors and Warnings

Obvious Errors (that shouldn't be errors, that I turned into warnings):

* error    line too long (94 > 80 characters)  (line-length)
* error    no new line character at the end of file  (new-line-at-end-of-file)

Errors related to bad indentation:

* error    syntax error: expected <block end>, but found '<block mapping start>' (syntax)
* error    wrong indentation: expected 7 but found 8  (indentation)
* error    syntax error: mapping values are not allowed here (syntax)

Error related to incomplete quoting:

* error    syntax error: expected <block end>, but found '<scalar>' (syntax)

Obvious Warnings:

* warning  missing document start "---"  (document-start)
* warning  comment not indented like content  (comments-indentation)

config file

Specify config with:

yamllint -c .yamllint file.yaml

Default config location:

  • a file named .yamllint, .yamllint.yaml, or .yamllint.yml in the current working directory, or a parent directory (the search for this file is terminated at the user’s home or filesystem root)
  • a filename referenced by $YAMLLINT_CONFIG_FILE, if set
  • a file named $XDG_CONFIG_HOME/yamllint/config or ~/.config/yamllint/config, if present

WARNING: ~/.yamllint or ~/.yamllint.yml ~/.yamllint.yaml should work, but doesn't seem to work for me?

This did work:

~/.config/yamllint/config

So I did this:

ln -s ~/.config/yamllint/config ~/.yamllint

default configuration

See https://yamllint.readthedocs.io/en/stable/configuration.html#default-configuration

Default:

---

yaml-files:
  - '*.yaml'
  - '*.yml'
  - '.yamllint'

rules:
  anchors: enable
  braces: enable
  brackets: enable
  colons: enable
  commas: enable
  comments:
    level: warning
  comments-indentation:
    level: warning
  document-end: disable
  document-start:
    level: warning
  empty-lines: enable
  empty-values: disable
  float-values: disable
  hyphens: enable
  indentation: enable
  key-duplicates: enable
  key-ordering: disable
  line-length: enable
  new-line-at-end-of-file: enable
  new-lines: enable
  octal-values: disable
  quoted-strings: disable
  trailing-spaces: enable
  truthy:
    level: warning

Extending Configuration

Extending to disable comments indentation:

# This is my first, very own configuration file for yamllint!
# It extends the default conf by adjusting some options.

extends: default

rules:
  comments-indentation: disable  # don't bother me with this rule

Extending to extend line length:

extends: default

rules:
  # 80 chars should be enough, but don't fail if a line is longer
  line-length:
    max: 80
    level: warning

  # accept both     key:
  #                   - item
  #
  # and             key:
  #                 - item
  indentation:
    indent-sequences: whatever

yaml

See yaml