Snapcraft 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 the core22 base.

Snapcraft linters run automatically when a snap is packed unless otherwise disabled.

Available linters

Snapcraft provides the following linters:

  • The classic linter verifies binary file parameters for snaps using classic confinement
  • The library linter verifies that no ELF file dependencies, such as libraries, are missing and that no extra libraries are included in the snap package

Disable a linter

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:

lint:
  ignore:
    - classic 
    - library

The ignore entry must include one or more linter names for those linters to be disabled.

Ignore a file

You can tell a linter to ignore specific files. When configured this way, the lint.ignore.<linter> key acts as a blocklist instead of disabling the linter entirely.

To instruct a linter to ignore a specific file:

  • List the path in the lint.ignore.<linter> key. The path can contain glob patterns to match multiple files.

In this example, the classic linter checks no files, and the library linter checks every file except those matching a particular glob pattern:

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

Thanks so much for adding these docs @cmatsuoka (and @mr_cal). These have all now been published:

https://snapcraft.io/docs/linters
https://snapcraft.io/docs/linters-classic
https://snapcraft.io/docs/linters-library

1 Like

I bumped into this page when searching for the review-tools snap. Maybe we can add a page about review-tools and link to it from here?

How can I advise library linter, that i will call dlopen to load a particular library - hence it is not linked in.

Looking at the source, it looks like it matches libraries against the unused-library category:

So you could add something like the following to your snapcraft.yaml:

lint:
  ignore:
    - unused-library:
      - path/to/libignored.so.1

If the shared objects are plugins and not intended to be used as libraries, the best option would be to build them without a soname.

2 Likes