Skip to main content

Module

You can share and reuse lint rules and Jsonnet codes such as functions. We call this mechanism Module. You can host modules on GitHub repositories.

There are two types of modules.

  1. Lint rule module
  2. Imported module

1. Lint rule module

Lint rule module is same with the normal lint rules.

You can use Lint rule modules by specifying them in configuration files.

function(param) {
targets: [
{
modules: [ // Lint rule modules
'github_archive/github.com/lintnet-modules/nllint/main.jsonnet@8cfc4eae68ec93f9b92d9048ce51b0d9646c976c:v0.1.0',
],
data_files: [
'**/*',
],
},
],
}

2. Imported module

You can share variables and functions as Imported modules. Imported modules are imported by Jsonnet's import statement.

local hello = import 'github_archive/github.com/lintnet/modules/modules/hello/hello.jsonnet@60a46a4fa4c0e7b1b95f57c479e756afa2f376e9:v0.1.0';

You can utilize third party Jsonnet libraries unrelated to lintnet too.

e.g.

Module path format

${type}/${host}/${repository_owner}/${repository_name}/${file_path}@${full_commit_hash}[:${tag}]

Now only github_archive is valid as type, and only github.com is valid as host.

e.g.

github_archive/github.com/lintnet/modules/modules/hello/hello.jsonnet@60a46a4fa4c0e7b1b95f57c479e756afa2f376e9:v0.1.0'

Update modules by Renovate

You can update modules by Renovate using our Renovate Preset.

https://github.com/lintnet/renovate-config

Where to install modules

Modules are installed on the following directory.

${Application Data Directory}/lintnet/modules

${Application Data Directory} is XDG_DATA_HOME in https://github.com/adrg/xdg .

environmentApplication Data Directory
Unix~/.local/share
macOS~/Library/Application Support
WindowsLocalAppData, %LOCALAPPDATA% (Fallback)

Or you can change the directory by the environment variable LINTNET_ROOT_DIR.

You can get the install path by lintnet info -module-root-dir

lintnet info -module-root-dir

💡 Cache modules in CI

You can cache modules in CI such as GitHub Actions.

e.g.

- run: echo "module_root_dir=$(lintnet info -module-root-dir)" >> "$GITHUB_OUTPUT"
id: lintnet

- uses: actions/cache@v3
with:
path: |
${{steps.lintnet.outputs.module_root_dir}}
key: ${{ hashFiles('lintnet.jsonnet') }}

- run: lintnet lint
env:
GITHUB_TOKEN: ${{github.token}}

GitHub Access Tokens

lintnet uses GitHub API to download Modules. To avoid API rate limiting, we recommend setting a GitHub Access Token to the environment variables LINTNET_GITHUB_TOKEN or GITHUB_TOKEN. To use modules hosted on private repositories, GitHub Access Tokens with contents:read permission are necessary.

Official Modules

https://github.com/lintnet-modules

We ported some linters such as ghalint and nllint to lintnet and shared them as official modules.

Find Modules

We recommend adding the topic lintnet-module to Module repositories so that everyone can find modules. So please check the topic lintnet-module.

Develop Modules

  1. Create a GitHub Repository
  2. Write lint rules
  3. (Optional) Add the topic lintnet-module to the repository so that everyone can find your modules
  4. (Optional) Write tests
  5. (Optional) Set up CI running lintnet test
  6. (Optional) Write document
  7. (Optional) Create GitHub Releases

The official modules would be a good reference.

Write document

Of course the format is free, but we recommend writing the following information.

  • Description
  • Example
  • Why is the rule necessary?
  • How to fix
  • config's schema