diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-05-04 00:38:50 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-05-04 00:38:50 +0000 |
commit | 09e7b47bad7e7310a6f52bdc20e9a9f251e79769 (patch) | |
tree | c93d189c1318902b8f1e5333d7ee34a1e9db9a34 /docs | |
parent | Initial commit. (diff) | |
download | yamllint-09e7b47bad7e7310a6f52bdc20e9a9f251e79769.tar.xz yamllint-09e7b47bad7e7310a6f52bdc20e9a9f251e79769.zip |
Adding upstream version 1.33.0.upstream/1.33.0
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'docs')
-rw-r--r-- | docs/Makefile | 177 | ||||
-rw-r--r-- | docs/conf.py | 54 | ||||
-rw-r--r-- | docs/configuration.rst | 255 | ||||
-rw-r--r-- | docs/development.rst | 18 | ||||
-rw-r--r-- | docs/disable_with_comments.rst | 136 | ||||
-rw-r--r-- | docs/index.rst | 29 | ||||
-rw-r--r-- | docs/integration.rst | 67 | ||||
-rw-r--r-- | docs/quickstart.rst | 115 | ||||
-rw-r--r-- | docs/rules.rst | 131 | ||||
-rw-r--r-- | docs/screenshot.png | bin | 0 -> 31372 bytes | |||
-rw-r--r-- | docs/text_editors.rst | 52 |
11 files changed, 1034 insertions, 0 deletions
diff --git a/docs/Makefile b/docs/Makefile new file mode 100644 index 0000000..0426d42 --- /dev/null +++ b/docs/Makefile @@ -0,0 +1,177 @@ +# Makefile for Sphinx documentation +# + +# You can set these variables from the command line. +SPHINXOPTS = -W +SPHINXBUILD = sphinx-build +PAPER = +BUILDDIR = _build + +# User-friendly check for sphinx-build +ifeq ($(shell which $(SPHINXBUILD) >/dev/null 2>&1; echo $$?), 1) +$(error The '$(SPHINXBUILD)' command was not found. Make sure you have Sphinx installed, then set the SPHINXBUILD environment variable to point to the full path of the '$(SPHINXBUILD)' executable. Alternatively you can add the directory with the executable to your PATH. If you don't have Sphinx installed, grab it from http://sphinx-doc.org/) +endif + +# Internal variables. +PAPEROPT_a4 = -D latex_paper_size=a4 +PAPEROPT_letter = -D latex_paper_size=letter +ALLSPHINXOPTS = -d $(BUILDDIR)/doctrees $(PAPEROPT_$(PAPER)) $(SPHINXOPTS) . +# the i18n builder cannot share the environment and doctrees with the others +I18NSPHINXOPTS = $(PAPEROPT_$(PAPER)) $(SPHINXOPTS) . + +.PHONY: help clean html dirhtml singlehtml pickle json htmlhelp qthelp devhelp epub latex latexpdf text man changes linkcheck doctest gettext + +help: + @echo "Please use \`make <target>' where <target> is one of" + @echo " html to make standalone HTML files" + @echo " dirhtml to make HTML files named index.html in directories" + @echo " singlehtml to make a single large HTML file" + @echo " pickle to make pickle files" + @echo " json to make JSON files" + @echo " htmlhelp to make HTML files and a HTML help project" + @echo " qthelp to make HTML files and a qthelp project" + @echo " devhelp to make HTML files and a Devhelp project" + @echo " epub to make an epub" + @echo " latex to make LaTeX files, you can set PAPER=a4 or PAPER=letter" + @echo " latexpdf to make LaTeX files and run them through pdflatex" + @echo " latexpdfja to make LaTeX files and run them through platex/dvipdfmx" + @echo " text to make text files" + @echo " man to make manual pages" + @echo " texinfo to make Texinfo files" + @echo " info to make Texinfo files and run them through makeinfo" + @echo " gettext to make PO message catalogs" + @echo " changes to make an overview of all changed/added/deprecated items" + @echo " xml to make Docutils-native XML files" + @echo " pseudoxml to make pseudoxml-XML files for display purposes" + @echo " linkcheck to check all external links for integrity" + @echo " doctest to run all doctests embedded in the documentation (if enabled)" + +clean: + rm -rf $(BUILDDIR)/* + +html: + $(SPHINXBUILD) -b html $(ALLSPHINXOPTS) $(BUILDDIR)/html + @echo + @echo "Build finished. The HTML pages are in $(BUILDDIR)/html." + +dirhtml: + $(SPHINXBUILD) -b dirhtml $(ALLSPHINXOPTS) $(BUILDDIR)/dirhtml + @echo + @echo "Build finished. The HTML pages are in $(BUILDDIR)/dirhtml." + +singlehtml: + $(SPHINXBUILD) -b singlehtml $(ALLSPHINXOPTS) $(BUILDDIR)/singlehtml + @echo + @echo "Build finished. The HTML page is in $(BUILDDIR)/singlehtml." + +pickle: + $(SPHINXBUILD) -b pickle $(ALLSPHINXOPTS) $(BUILDDIR)/pickle + @echo + @echo "Build finished; now you can process the pickle files." + +json: + $(SPHINXBUILD) -b json $(ALLSPHINXOPTS) $(BUILDDIR)/json + @echo + @echo "Build finished; now you can process the JSON files." + +htmlhelp: + $(SPHINXBUILD) -b htmlhelp $(ALLSPHINXOPTS) $(BUILDDIR)/htmlhelp + @echo + @echo "Build finished; now you can run HTML Help Workshop with the" \ + ".hhp project file in $(BUILDDIR)/htmlhelp." + +qthelp: + $(SPHINXBUILD) -b qthelp $(ALLSPHINXOPTS) $(BUILDDIR)/qthelp + @echo + @echo "Build finished; now you can run "qcollectiongenerator" with the" \ + ".qhcp project file in $(BUILDDIR)/qthelp, like this:" + @echo "# qcollectiongenerator $(BUILDDIR)/qthelp/yamllint.qhcp" + @echo "To view the help file:" + @echo "# assistant -collectionFile $(BUILDDIR)/qthelp/yamllint.qhc" + +devhelp: + $(SPHINXBUILD) -b devhelp $(ALLSPHINXOPTS) $(BUILDDIR)/devhelp + @echo + @echo "Build finished." + @echo "To view the help file:" + @echo "# mkdir -p $$HOME/.local/share/devhelp/yamllint" + @echo "# ln -s $(BUILDDIR)/devhelp $$HOME/.local/share/devhelp/yamllint" + @echo "# devhelp" + +epub: + $(SPHINXBUILD) -b epub $(ALLSPHINXOPTS) $(BUILDDIR)/epub + @echo + @echo "Build finished. The epub file is in $(BUILDDIR)/epub." + +latex: + $(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex + @echo + @echo "Build finished; the LaTeX files are in $(BUILDDIR)/latex." + @echo "Run \`make' in that directory to run these through (pdf)latex" \ + "(use \`make latexpdf' here to do that automatically)." + +latexpdf: + $(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex + @echo "Running LaTeX files through pdflatex..." + $(MAKE) -C $(BUILDDIR)/latex all-pdf + @echo "pdflatex finished; the PDF files are in $(BUILDDIR)/latex." + +latexpdfja: + $(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex + @echo "Running LaTeX files through platex and dvipdfmx..." + $(MAKE) -C $(BUILDDIR)/latex all-pdf-ja + @echo "pdflatex finished; the PDF files are in $(BUILDDIR)/latex." + +text: + $(SPHINXBUILD) -b text $(ALLSPHINXOPTS) $(BUILDDIR)/text + @echo + @echo "Build finished. The text files are in $(BUILDDIR)/text." + +man: + $(SPHINXBUILD) -b man $(ALLSPHINXOPTS) $(BUILDDIR)/man + @echo + @echo "Build finished. The manual pages are in $(BUILDDIR)/man." + +texinfo: + $(SPHINXBUILD) -b texinfo $(ALLSPHINXOPTS) $(BUILDDIR)/texinfo + @echo + @echo "Build finished. The Texinfo files are in $(BUILDDIR)/texinfo." + @echo "Run \`make' in that directory to run these through makeinfo" \ + "(use \`make info' here to do that automatically)." + +info: + $(SPHINXBUILD) -b texinfo $(ALLSPHINXOPTS) $(BUILDDIR)/texinfo + @echo "Running Texinfo files through makeinfo..." + make -C $(BUILDDIR)/texinfo info + @echo "makeinfo finished; the Info files are in $(BUILDDIR)/texinfo." + +gettext: + $(SPHINXBUILD) -b gettext $(I18NSPHINXOPTS) $(BUILDDIR)/locale + @echo + @echo "Build finished. The message catalogs are in $(BUILDDIR)/locale." + +changes: + $(SPHINXBUILD) -b changes $(ALLSPHINXOPTS) $(BUILDDIR)/changes + @echo + @echo "The overview file is in $(BUILDDIR)/changes." + +linkcheck: + $(SPHINXBUILD) -b linkcheck $(ALLSPHINXOPTS) $(BUILDDIR)/linkcheck + @echo + @echo "Link check complete; look for any errors in the above output " \ + "or in $(BUILDDIR)/linkcheck/output.txt." + +doctest: + $(SPHINXBUILD) -b doctest $(ALLSPHINXOPTS) $(BUILDDIR)/doctest + @echo "Testing of doctests in the sources finished, look at the " \ + "results in $(BUILDDIR)/doctest/output.txt." + +xml: + $(SPHINXBUILD) -b xml $(ALLSPHINXOPTS) $(BUILDDIR)/xml + @echo + @echo "Build finished. The XML files are in $(BUILDDIR)/xml." + +pseudoxml: + $(SPHINXBUILD) -b pseudoxml $(ALLSPHINXOPTS) $(BUILDDIR)/pseudoxml + @echo + @echo "Build finished. The pseudo-XML files are in $(BUILDDIR)/pseudoxml." diff --git a/docs/conf.py b/docs/conf.py new file mode 100644 index 0000000..2c40177 --- /dev/null +++ b/docs/conf.py @@ -0,0 +1,54 @@ +# yamllint documentation build configuration file, created by +# sphinx-quickstart on Thu Jan 21 21:18:52 2016. + +import sys +import os +from unittest.mock import MagicMock + +sys.path.insert(0, os.path.abspath('..')) + +from yamllint import __copyright__, APP_NAME, APP_VERSION # noqa + +# -- General configuration ------------------------------------------------ + +extensions = [ + 'sphinx.ext.autodoc', +] + +source_suffix = '.rst' + +master_doc = 'index' + +project = APP_NAME +copyright = __copyright__.lstrip('Copyright ') + +version = APP_VERSION +release = APP_VERSION + +pygments_style = 'sphinx' + +# -- Options for HTML output ---------------------------------------------- + +html_theme = 'default' + +htmlhelp_basename = 'yamllintdoc' + +# -- Options for manual page output --------------------------------------- + +# One entry per manual page. List of tuples +# (source start file, name, description, authors, manual section). +man_pages = [ + ('index', 'yamllint', 'Linter for YAML files', ['Adrien Vergé'], 1) +] + +# -- Build with sphinx automodule without needing to install third-party libs + + +class Mock(MagicMock): + @classmethod + def __getattr__(cls, name): + return MagicMock() + + +MOCK_MODULES = ['pathspec', 'yaml'] +sys.modules.update((mod_name, Mock()) for mod_name in MOCK_MODULES) diff --git a/docs/configuration.rst b/docs/configuration.rst new file mode 100644 index 0000000..9624b49 --- /dev/null +++ b/docs/configuration.rst @@ -0,0 +1,255 @@ +Configuration +============= + +yamllint uses a set of :doc:`rules <rules>` to check source files for problems. +Each rule is independent from the others, and can be enabled, disabled or +tweaked. All these settings can be gathered in a configuration file. + +To use a custom configuration file, use the ``-c`` option: + +.. code:: bash + + yamllint -c /path/to/myconfig file-to-lint.yaml + +If ``-c`` is not provided, yamllint will look for a configuration file in the +following locations (by order of preference): + +- 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 + +Finally if no config file is found, the default configuration is applied. + +Default configuration +--------------------- + +Unless told otherwise, yamllint uses its ``default`` configuration: + +.. literalinclude:: ../yamllint/conf/default.yaml + :language: yaml + +Details on rules can be found on :doc:`the rules page <rules>`. + +There is another pre-defined configuration named ``relaxed``. As its name +suggests, it is more tolerant: + +.. literalinclude:: ../yamllint/conf/relaxed.yaml + :language: yaml + +It can be chosen using: + +.. code:: bash + + yamllint -d relaxed file.yml + +Extending the default configuration +----------------------------------- + +When writing a custom configuration file, you don't need to redefine every +rule. Just extend the ``default`` configuration (or any already-existing +configuration file). + +For instance, if you just want to disable the ``comments-indentation`` rule, +your file could look like this: + +.. code-block:: yaml + + # 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 + +Similarly, if you want to set the ``line-length`` rule as a warning and be less +strict on block sequences indentation: + +.. code-block:: yaml + + 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 + +Custom configuration without a config file +------------------------------------------ + +It is possible -- although not recommended -- to pass custom configuration +options to yamllint with the ``-d`` (short for ``--config-data``) option. + +Its content can either be the name of a pre-defined conf (example: ``default`` +or ``relaxed``) or a serialized YAML object describing the configuration. + +For instance: + +.. code:: bash + + yamllint -d "{extends: relaxed, rules: {line-length: {max: 120}}}" file.yaml + +Errors and warnings +------------------- + +Problems detected by yamllint can be raised either as errors or as warnings. +The CLI will output them (with different colors when using the ``colored`` +output format, or ``auto`` when run from a terminal). + +By default the script will exit with a return code ``1`` *only when* there is +one or more error(s). + +However if strict mode is enabled with the ``-s`` (or ``--strict``) option, the +return code will be: + + * ``0`` if no errors or warnings occur + * ``1`` if one or more errors occur + * ``2`` if no errors occur, but one or more warnings occur + +If the script is invoked with the ``--no-warnings`` option, it won't output +warning level problems, only error level ones. + +YAML files extensions +--------------------- + +To configure what yamllint should consider as YAML files when listing +directories, set ``yaml-files`` configuration option. The default is: + +.. code-block:: yaml + + yaml-files: + - '*.yaml' + - '*.yml' + - '.yamllint' + +The same rules as for ignoring paths apply (``.gitignore``-style path pattern, +see below). + +If you need to know the exact list of files that yamllint would process, +without really linting them, you can use ``--list-files``: + +.. code:: bash + + yamllint --list-files . + +Ignoring paths +-------------- + +It is possible to exclude specific files or directories, so that the linter +doesn't process them. They can be provided either as a list of paths, or as a +bulk string. + +You can either totally ignore files (they won't be looked at): + +.. code-block:: yaml + + extends: default + + ignore: | + /this/specific/file.yaml + all/this/directory/ + *.template.yaml + + # or: + + ignore: + - /this/specific/file.yaml + - all/this/directory/ + - '*.template.yaml' + +or ignore paths only for specific rules: + +.. code-block:: yaml + + extends: default + + rules: + trailing-spaces: + ignore: | + /this-file-has-trailing-spaces-but-it-is-OK.yaml + /generated/*.yaml + + # or: + + rules: + trailing-spaces: + ignore: + - /this-file-has-trailing-spaces-but-it-is-OK.yaml + - /generated/*.yaml + +Note that this ``.gitignore``-style path pattern allows complex path +exclusion/inclusion, see the `pathspec README file +<https://pypi.org/project/pathspec/>`_ for more details. Here is a more complex +example: + +.. code-block:: yaml + + # For all rules + ignore: | + *.dont-lint-me.yaml + /bin/ + !/bin/*.lint-me-anyway.yaml + + extends: default + + rules: + key-duplicates: + ignore: | + generated + *.template.yaml + trailing-spaces: + ignore: | + *.ignore-trailing-spaces.yaml + ascii-art/* + +You can also use the ``.gitignore`` file (or any list of files) through: + +.. code-block:: yaml + + ignore-from-file: .gitignore + +or: + +.. code-block:: yaml + + ignore-from-file: [.gitignore, .yamlignore] + +.. note:: However, this is mutually exclusive with the ``ignore`` key. + +If you need to know the exact list of files that yamllint would process, +without really linting them, you can use ``--list-files``: + +.. code:: bash + + yamllint --list-files . + +Setting the locale +------------------ + +It is possible to set the ``locale`` option globally. This is passed to Python's +`locale.setlocale +<https://docs.python.org/3/library/locale.html#locale.setlocale>`_, +so an empty string ``""`` will use the system default locale, while e.g. +``"en_US.UTF-8"`` will use that. + +Currently this only affects the ``key-ordering`` rule. The default will order +by Unicode code point number, while locales will sort case and accents +properly as well. + +.. code-block:: yaml + + extends: default + + locale: en_US.UTF-8 diff --git a/docs/development.rst b/docs/development.rst new file mode 100644 index 0000000..b179de2 --- /dev/null +++ b/docs/development.rst @@ -0,0 +1,18 @@ +Development +=========== + +yamllint provides both a script and a Python module. The latter can be used to +write your own linting tools. + +Basic example of running the linter from Python: + +.. code-block:: python + + import yamllint + + yaml_config = yamllint.config.YamlLintConfig("extends: default") + for p in yamllint.linter.run(open("example.yaml", "r"), yaml_config): + print(p.desc, p.line, p.rule) + +.. automodule:: yamllint.linter + :members: diff --git a/docs/disable_with_comments.rst b/docs/disable_with_comments.rst new file mode 100644 index 0000000..a973da6 --- /dev/null +++ b/docs/disable_with_comments.rst @@ -0,0 +1,136 @@ +Disable with comments +===================== + +Disabling checks for a specific line +------------------------------------ + +To prevent yamllint from reporting problems for a specific line, add a +directive comment (``# yamllint disable-line ...``) on that line, or on the +line above. For instance: + +.. code-block:: yaml + + # The following mapping contains the same key twice, + # but I know what I'm doing: + key: value 1 + key: value 2 # yamllint disable-line rule:key-duplicates + + - This line is waaaaaaaaaay too long but yamllint will not report anything about it. # yamllint disable-line rule:line-length + This line will be checked by yamllint. + +or: + +.. code-block:: yaml + + # The following mapping contains the same key twice, + # but I know what I'm doing: + key: value 1 + # yamllint disable-line rule:key-duplicates + key: value 2 + + # yamllint disable-line rule:line-length + - This line is waaaaaaaaaay too long but yamllint will not report anything about it. + This line will be checked by yamllint. + +It is possible, although not recommend, to disabled **all** rules for a +specific line: + +.. code-block:: yaml + + # yamllint disable-line + - { all : rules ,are disabled for this line} + +You can't make yamllint ignore invalid YAML syntax on a line (which generates a +`syntax error`), such as when templating a YAML file with Jinja. In some cases, +you can workaround this by putting the templating syntax in a YAML comment. See +`Putting template flow control in comments`_. + +If you need to disable multiple rules, it is allowed to chain rules like this: +``# yamllint disable-line rule:hyphens rule:commas rule:indentation``. + +Disabling checks for all (or part of) the file +---------------------------------------------- + +To prevent yamllint from reporting problems for the whole file, or for a block +of lines within the file, use ``# yamllint disable ...`` and ``# yamllint +enable ...`` directive comments. For instance: + +.. code-block:: yaml + + # yamllint disable rule:colons + - Lorem : ipsum + dolor : sit amet, + consectetur : adipiscing elit + # yamllint enable rule:colons + + - rest of the document... + +It is possible, although not recommend, to disabled **all** rules: + +.. code-block:: yaml + + # yamllint disable + - Lorem : + ipsum: + dolor : [ sit,amet] + - consectetur : adipiscing elit + # yamllint enable + +If you need to disable multiple rules, it is allowed to chain rules like this: +``# yamllint disable rule:hyphens rule:commas rule:indentation``. + +Disabling all checks for a file +------------------------------- + +To prevent yamllint from reporting problems for a specific file, add the +directive comment ``# yamllint disable-file`` as the first line of the file. +For instance: + +.. code-block:: yaml + + # yamllint disable-file + # The following mapping contains the same key twice, but I know what I'm doing: + key: value 1 + key: value 2 + + - This line is waaaaaaaaaay too long but yamllint will not report anything about it. + +or: + +.. code-block:: jinja + + # yamllint disable-file + # This file is not valid YAML because it is a Jinja template + {% if extra_info %} + key1: value1 + {% endif %} + key2: value2 + +Putting template flow control in comments +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +Alternatively for templating you can wrap the template statements in comments +to make it a valid YAML file. As long as the templating language doesn't use +the same comment symbol, it should be a valid template and valid YAML (pre and +post-template processing). + +Example of a Jinja2 code that cannot be parsed as YAML because it contains +invalid tokens ``{%`` and ``%}``: + +.. code-block:: text + + # This file IS NOT valid YAML and will produce syntax errors + {% if extra_info %} + key1: value1 + {% endif %} + key2: value2 + +But it can be fixed using YAML comments: + +.. code-block:: yaml + + # This file IS valid YAML because the Jinja is in a YAML comment + # {% if extra_info %} + key1: value1 + # {% endif %} + key2: value2 diff --git a/docs/index.rst b/docs/index.rst new file mode 100644 index 0000000..5456d6a --- /dev/null +++ b/docs/index.rst @@ -0,0 +1,29 @@ +yamllint documentation +====================== + +.. automodule:: yamllint + +Screenshot +---------- + +.. image:: screenshot.png + :alt: yamllint screenshot + +.. note:: + + The default output format is inspired by `eslint <https://eslint.org/>`_, a + great linting tool for Javascript. + +Table of contents +----------------- + +.. toctree:: + :maxdepth: 2 + + quickstart + configuration + rules + disable_with_comments + development + text_editors + integration diff --git a/docs/integration.rst b/docs/integration.rst new file mode 100644 index 0000000..9a6a935 --- /dev/null +++ b/docs/integration.rst @@ -0,0 +1,67 @@ +Integration with other software +=============================== + +Integration with pre-commit +--------------------------- + +You can integrate yamllint in the `pre-commit <https://pre-commit.com/>`_ tool. +Here is an example, to add in your .pre-commit-config.yaml + +.. code:: yaml + + --- + # Update the rev variable with the release version that you want, from the yamllint repo + # You can pass your custom .yamllint with args attribute. + repos: + - repo: https://github.com/adrienverge/yamllint.git + rev: v1.29.0 + hooks: + - id: yamllint + args: [--strict, -c=/path/to/.yamllint] + + +Integration with GitHub Actions +------------------------------- + +yamllint auto-detects when it's running inside of `GitHub +Actions <https://github.com/features/actions>`_ and automatically uses the +suited output format to decorate code with linting errors. You can also force +the GitHub Actions output with ``yamllint --format github``. + +A minimal example workflow using GitHub Actions: + +.. code:: yaml + + --- + on: push # yamllint disable-line rule:truthy + + jobs: + lint: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + + - name: Install yamllint + run: pip install yamllint + + - name: Lint YAML files + run: yamllint . + +Integration with Arcanist +------------------------- + +You can configure yamllint to run on ``arc lint``. Here is an example +``.arclint`` file that makes use of this configuration. + +.. code:: json + + { + "linters": { + "yamllint": { + "type": "script-and-regex", + "script-and-regex.script": "yamllint", + "script-and-regex.regex": "/^(?P<line>\\d+):(?P<offset>\\d+) +(?P<severity>warning|error) +(?P<message>.*) +\\((?P<name>.*)\\)$/m", + "include": "(\\.(yml|yaml)$)" + } + } + } diff --git a/docs/quickstart.rst b/docs/quickstart.rst new file mode 100644 index 0000000..9828dd6 --- /dev/null +++ b/docs/quickstart.rst @@ -0,0 +1,115 @@ +Quickstart +========== + +Installing yamllint +------------------- + +On Fedora / CentOS (note: `EPEL <https://docs.fedoraproject.org/en-US/epel/>`_ is +required on CentOS): + +.. code:: bash + + sudo dnf install yamllint + +On Debian 8+ / Ubuntu 16.04+: + +.. code:: bash + + sudo apt-get install yamllint + +On Mac OS 10.11+: + +.. code:: bash + + brew install yamllint + +On FreeBSD: + +.. code:: sh + + pkg install py36-yamllint + +On OpenBSD: + +.. code:: sh + + doas pkg_add py3-yamllint + +Alternatively using pip, the Python package manager: + +.. code:: bash + + pip install --user yamllint + +If you prefer installing from source, you can run, from the source directory: + +.. code:: bash + + python -m build + pip install --user dist/yamllint-*.tar.gz + +Running yamllint +---------------- + +Basic usage: + +.. code:: bash + + yamllint file.yml other-file.yaml + +You can also lint all YAML files in a whole directory: + +.. code:: bash + + yamllint . + +Or lint a YAML stream from standard input: + +.. code:: bash + + echo -e 'this: is\nvalid: YAML' | yamllint - + +The output will look like (colors are not displayed here): + +:: + + file.yml + 1:4 error trailing spaces (trailing-spaces) + 4:4 error wrong indentation: expected 4 but found 3 (indentation) + 5:4 error duplication of key "id-00042" in mapping (key-duplicates) + 6:6 warning comment not indented like content (comments-indentation) + 12:6 error too many spaces after hyphen (hyphens) + 15:12 error too many spaces before comma (commas) + + other-file.yaml + 1:1 warning missing document start "---" (document-start) + 6:81 error line too long (87 > 80 characters) (line-length) + 10:1 error too many blank lines (4 > 2) (empty-lines) + 11:4 error too many spaces inside braces (braces) + +By default, the output of yamllint is colored when run from a terminal, and +pure text in other cases. Add the ``-f standard`` arguments to force +non-colored output. Use the ``-f colored`` arguments to force colored output. + +Add the ``-f parsable`` arguments if you need an output format parsable by a +machine (for instance for :doc:`syntax highlighting in text editors +<text_editors>`). The output will then look like: + +:: + + file.yml:6:2: [warning] missing starting space in comment (comments) + file.yml:57:1: [error] trailing spaces (trailing-spaces) + file.yml:60:3: [error] wrong indentation: expected 4 but found 2 (indentation) + +If you have a custom linting configuration file (see :doc:`how to configure +yamllint <configuration>`), it can be passed to yamllint using the ``-c`` +option: + +.. code:: bash + + yamllint -c ~/myconfig file.yaml + +.. note:: + + If you have a ``.yamllint`` file in your working directory, it will be + automatically loaded as configuration by yamllint. diff --git a/docs/rules.rst b/docs/rules.rst new file mode 100644 index 0000000..eb3bc82 --- /dev/null +++ b/docs/rules.rst @@ -0,0 +1,131 @@ +Rules +===== + +When linting a document with yamllint, a series of rules (such as +``line-length``, ``trailing-spaces``, etc.) are checked against. + +A :doc:`configuration file <configuration>` can be used to enable or disable +these rules, to set their level (*error* or *warning*), but also to tweak their +options. + +This page describes the rules and their options. + +.. contents:: List of rules + :local: + :depth: 1 + +anchors +------- + +.. automodule:: yamllint.rules.anchors + +braces +------ + +.. automodule:: yamllint.rules.braces + +brackets +-------- + +.. automodule:: yamllint.rules.brackets + +colons +------ + +.. automodule:: yamllint.rules.colons + +commas +------ + +.. automodule:: yamllint.rules.commas + +comments +-------- + +.. automodule:: yamllint.rules.comments + +comments-indentation +-------------------- + +.. automodule:: yamllint.rules.comments_indentation + +document-end +------------ + +.. automodule:: yamllint.rules.document_end + +document-start +-------------- + +.. automodule:: yamllint.rules.document_start + +empty-lines +----------- + +.. automodule:: yamllint.rules.empty_lines + +empty-values +------------ + +.. automodule:: yamllint.rules.empty_values + +float-values +------------ + +.. automodule:: yamllint.rules.float_values + + +hyphens +------- + +.. automodule:: yamllint.rules.hyphens + +indentation +----------- + +.. automodule:: yamllint.rules.indentation + +key-duplicates +-------------- + +.. automodule:: yamllint.rules.key_duplicates + +key-ordering +-------------- + +.. automodule:: yamllint.rules.key_ordering + +line-length +----------- + +.. automodule:: yamllint.rules.line_length + +new-line-at-end-of-file +----------------------- + +.. automodule:: yamllint.rules.new_line_at_end_of_file + +new-lines +--------- + +.. automodule:: yamllint.rules.new_lines + +octal-values +------------ + +.. automodule:: yamllint.rules.octal_values + +quoted-strings +-------------- + +.. automodule:: yamllint.rules.quoted_strings + +trailing-spaces +--------------- + +.. automodule:: yamllint.rules.trailing_spaces + +truthy +--------------- + +.. automodule:: yamllint.rules.truthy diff --git a/docs/screenshot.png b/docs/screenshot.png Binary files differnew file mode 100644 index 0000000..6bad6c0 --- /dev/null +++ b/docs/screenshot.png diff --git a/docs/text_editors.rst b/docs/text_editors.rst new file mode 100644 index 0000000..12387e6 --- /dev/null +++ b/docs/text_editors.rst @@ -0,0 +1,52 @@ +Integration with text editors +============================= + +Most text editors support syntax checking and highlighting, to visually report +syntax errors and warnings to the user. yamllint can be used to syntax-check +YAML source, but a bit of configuration is required depending on your favorite +text editor. + +Vim +--- + +Assuming that the `ALE <https://github.com/dense-analysis/ale>`_ plugin is +installed, yamllint is supported by default. It is automatically enabled when +editing YAML files. + +If you instead use the `syntastic <https://github.com/vim-syntastic/syntastic>`_ +plugin, add this to your ``.vimrc``: + +:: + + let g:syntastic_yaml_checkers = ['yamllint'] + +Neovim +------ + +Assuming that the `neomake <https://github.com/neomake/neomake>`_ plugin is +installed, yamllint is supported by default. It is automatically enabled when +editing YAML files. + +Emacs +----- + +If you are `flycheck <https://github.com/flycheck/flycheck>`_ user, you can use +`flycheck-yamllint <https://github.com/krzysztof-magosa/flycheck-yamllint>`_ integration. + +Visual Studio Code +------------------ + +https://marketplace.visualstudio.com/items?itemName=fnando.linter + +IntelliJ +-------- + +https://plugins.jetbrains.com/plugin/15349-yamllint + +Other text editors +------------------ + +.. rubric:: Help wanted! + +Your favorite text editor is not listed here? Help us improve by adding a +section (by opening a pull-request or issue on GitHub). |