Yamllint: Difference between revisions

From Omnia
Jump to navigation Jump to search
 
(2 intermediate revisions by the same user not shown)
Line 19: Line 19:
* error    line too long (94 > 80 characters)  (line-length)
* 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)
* error    no new line character at the end of file  (new-line-at-end-of-file)
** error    too many blank lines (1 > 0)  (empty-lines)
  ^^ And then sometimes it doesn't want the new new line at end of file, not sure why - just can't win!
</pre>
</pre>


Errors related to bad indentation:
Errors related to bad indentation:
<pre>
<pre>
* error    wrong indentation: expected 4 but found 2  (indentation)
* error    syntax error: expected <block end>, but found '<block mapping start>' (syntax)
* error    syntax error: expected <block end>, but found '<block mapping start>' (syntax)
* error    wrong indentation: expected 7 but found 8  (indentation)
* error    wrong indentation: expected 7 but found 8  (indentation)

Latest revision as of 21:02, 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)
** error    too many blank lines (1 > 0)  (empty-lines)
   ^^ And then sometimes it doesn't want the new new line at end of file, not sure why - just can't win!

Errors related to bad indentation:

* error    wrong indentation: expected 4 but found 2  (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

Turn no end of line error into warning:

  new-line-at-end-of-file:
    level: warning

Extending to extend line length:

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

yaml

See YAML

keywords