Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: add linter reference page #5032

Merged
merged 3 commits into from
Sep 17, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/reference/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ Reference
changelog
commands
components
linters
plugins
/common/craft-parts/reference/part_properties
parts_steps
Expand Down
62 changes: 62 additions & 0 deletions docs/reference/linters.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
Linters
=======

A *linter* is an analysis tool that checks for common errors or compatibility
issues, usually automatically, or as part of some other process.

Snapcraft (from version 7.2 onwards) includes its own linter functionality when
working with snaps using a ``core22`` or newer :doc:`base</reference/bases>`.
medubelko marked this conversation as resolved.
Show resolved Hide resolved

Snapcraft linters run automatically when a snap is packed unless otherwise
disabled.
medubelko marked this conversation as resolved.
Show resolved Hide resolved

Available linters
medubelko marked this conversation as resolved.
Show resolved Hide resolved
-----------------

Snapcraft runs the following linters:

- `classic`_: verifies binary file parameters for snaps using classic
`confinement`_

- `library`_: verifies that no ELF file dependencies, such as libraries, are
missing and that no extra libraries are included in the snap package
medubelko marked this conversation as resolved.
Show resolved Hide resolved

Disabling linters
~~~~~~~~~~~~~~~~~
medubelko marked this conversation as resolved.
Show resolved Hide resolved

Snapcraft linters run automatically when a snap is packed but specific linters
can be disabled by specifying a ``ignore`` entry in the ``lint`` section of
``snapcraft.yaml``:
medubelko marked this conversation as resolved.
Show resolved Hide resolved

.. code-block:: yaml

lint:
ignore:
- classic
- library

The ``ignore`` entry must include one or more [linter names](#heading--linters)
for those linters to be disabled.
medubelko marked this conversation as resolved.
Show resolved Hide resolved

Ignore specific files
~~~~~~~~~~~~~~~~~~~~~

To omit specific files from a linter, add their snap location under the linter
name:
medubelko marked this conversation as resolved.
Show resolved Hide resolved

.. code-block:: yaml

lint:
ignore:
- classic
- library:
- usr/lib/**/libfoo.so*

In the above example, the ``classic`` linter will be disabled entirely, and the
``library`` linter will not run for the files matching the specified file
pattern.
medubelko marked this conversation as resolved.
Show resolved Hide resolved


.. _classic: https://snapcraft.io/docs/linters-classic
.. _confinement: https://snapcraft.io/docs/snap-confinement
medubelko marked this conversation as resolved.
Show resolved Hide resolved
.. _library: https://snapcraft.io/docs/linters-library
Loading