cki_lint.sh

Wrapper to run a set of common linters across all of CKI

Overview

The cki_lint.sh script supports two modes of operation:

Code Linting (default)

Runs ruff and, where installed, mypy. The script automatically handles environment preparation including dependency installation via pip. Ruff checks lint rules and sorts import order (see [lint.isort] in ruff.toml). Formatting via ruff format is available with --fix (see [format] in ruff.toml).

The default lint path does not enforce formatting with ruff format --check; formatting is applied only when --fix is specified.

The experimental --fix parameter can be used to automatically fix some of the detected issues. At the moment, this will invoke ruff format and ruff check --fix (which includes import sorting). To skip ruff format, set CKI_DISABLED_LINTERS=ruff_format.

Markdown Linting

Performs linting and link checking for markdown files. It uses the markdownlint tool to check for markdown errors and lychee to check for broken links in all markdown files.

Lychee results are a warning only. External links can be temporarily or permanently broken for reasons outside of CKI control, so broken links do not fail the linting.

Markdownlint uses the repo .markdownlint.yaml when present; otherwise it downloads the cki-lib default from production (same pattern as ruff.toml).

Usage

# Code linting (default mode)
cki_lint.sh [code] <package_name>

# Markdown linting with explicit mode
cki_lint.sh markdownlint <glob_pattern>

# Using environment variables
CKI_LINT_MODE=markdownlint CKI_MARKDOWN_GLOB="**/*.md" cki_lint.sh

# Show help
cki_lint.sh help

For correct editor integration, line length, formatting, and import order are configured in ruff.toml (see line-length, [format], and [lint.isort]).

When run in a GitLab CI/CD pipeline for a merge request, the script tries to determine the previous code coverage and will fail if code coverage decreased. This can be skipped by adding [skip coverage check] with an explanation to the merge request description.

Automatic Preparation

The script automatically sources and executes cki_prepare.sh to handle dependency installation, version management, and package overrides. This includes automatic cki-lib version checking in CI/MR environments and support for custom package overrides via *_pip_url environment variables.

For detailed information about preparation and environment variables, see the cki_prepare documentation.

For a comprehensive overview of the entire linting and testing pipeline, see the cki tox pipeline documentation.

Environment variables

Mode Control

Environment variable Description
CKI_LINT_MODE Set to code or markdownlint to specify the linting mode
CKI_MARKDOWN_GLOB Glob pattern for markdown files (default: **/README.*.md)

Linting Control

Environment variable Description
CKI_DISABLED_LINTERS linters to disable or all
CKI_IGNORED_LINTERS space-separated list of linters where results are ignored, or all

Preparation Control

Environment variable Description
CKI_SKIP_PREPARE true if Python package installation should be skipped
cki_lib_pip_url Override cki-lib with custom Git URL (see cki_prepare docs)

Running Python tests and code linting

To run both Python tests and linting, execute the following command:

tox

To run only code linting, use the lint tox environment:

tox -e lint

Running markdown linting

To run only markdown linting, use the markdownlint mode:

cki_lint.sh markdownlint "**/README.*.md"

Disabling linters

To skip certain linters, specify them in the CKI_DISABLED_LINTERS variable as a space-separated list. For example:

TOX_OVERRIDE=tool.tox.env_run_base.pass_env+=CKI_DISABLED_LINTERS \
    CKI_DISABLED_LINTERS="mypy" \
    tox -e lint

The above command skips the mypy linter when running tox.