Code Formatting

Kaapana checks every Python, TypeScript and Vue file and every Dockerfile with two kinds of tools. Every one of them follows the same pattern: one configuration at the repository root, one pinned tool version, a pre-commit hook that fixes what it can on commit, and a CI job that checks the whole repository with the same tool and configuration.

Formatter and linter

A formatter decides how code looks: indentation, line breaks, quotes, semicolons, trailing commas. It rewrites the file and never changes what the code does, so everything it reports is fixed automatically. There is nothing to discuss in review: the formatter’s output is the style.

A linter decides whether code is likely wrong or hard to maintain: an unused variable or import, an undefined name, any where a type belongs, a Vue template that cannot work. Some findings are fixed automatically (for example sorting imports or let → const); the rest must be fixed by hand.

Python

TypeScript / Vue

Dockerfile

Helm chart

Formatter

ruff format

Prettier

none

none

Linter

ruff check

ESLint

hadolint

helm lint, kubeconform

Configuration

ruff.toml

.prettierrc.json, eslint.config.mjs

.hadolint.yaml

build_cli/build_cli/configs/fake-values.yaml

Code quality report

ci/ci-code/lint/ruff-quality.toml

ci/ci-code/lint/eslint-quality.config.mjs

.hadolint.yaml

none, JUnit test report instead

Pre-commit hook

ruff-check, ruff-format

ui-lint

hadolint

helm-lint

CI job

lint: [ruff]

lint: [ui]

lint: [hadolint]

lint: [helm]

The linters leave formatting to the formatters: ESLint’s formatting rules are switched off, so ESLint and Prettier never disagree.

Every linter has two rulesets. The enforced ruleset holds the rules whose findings are bugs; the pre-commit hook and CI fail on it. The advisory ruleset adds the rules the codebase does not meet yet; CI reports its findings in the merge request Code Quality widget and never fails on them. Formatting is always enforced.

One-time setup

From the repository root:

pip install ruff pre-commit
npm ci                  # ESLint and Prettier, into the root node_modules
pre-commit install      # run the hooks on every commit

Ruff

All Python code in Kaapana is formatted and linted with Ruff, which replaced Black, isort and flake8. One file at the repository root, ruff.toml, holds the whole configuration: 120 character lines, Black-compatible formatting, isort-compatible import sorting.

Installation

pip install ruff

VS Code

Install the Ruff extension (charliermarsh.ruff), then in your .vscode/settings.json:

{
  "[python]": {
    "editor.defaultFormatter": "charliermarsh.ruff",
    "editor.formatOnSave": true,
    "editor.codeActionsOnSave": {
      "source.organizeImports.ruff": "explicit"
    }
  }
}

The extension reads ruff.toml from the repository root, so the editor formats exactly the way the pre-commit hook and the lint: [ruff] job do.

The whole codebase

Format and lint the whole repository from its root:

ruff format .          # formatter: rewrite files
ruff check --fix .     # linter: sort imports, drop unused ones, report the rest

ruff format --check --diff .   # what CI runs: report, change nothing
ruff check .

All are safe to run repeatedly. Pass a path to limit them to one file or directory.

Helm charts

Check the chart tree the way the lint: [helm] job does: helm lint, then a render with fake values validated by kubeconform. Both always run, and any lint warning or invalid manifest fails the CI job:

kaapana-build --lint-only

ci/ci-code/lint/helm_lint.sh runs the same and downloads kubeconform when it is missing, so it also works from the pre-commit hook.

Pre-commit hooks

Important

Install the hooks before committing — CI runs the same checks and fails the pipeline on any finding:

pip install pre-commit && pre-commit install

The hooks live in .pre-commit-config.yaml. On commit they run one after the other:

  1. ruff pins the same Ruff version the CI job uses. On commit it formats the staged files and applies the safe lint fixes. When it changes something, review the result and commit again.

  2. helm-lint runs kaapana-build --lint-only when the commit changes a chart. It lints and validates the platform chart tree, exactly what the lint: [helm] CI job does. It needs helm, the same as a local build; build_cli is installed into the hook’s own environment the first time it runs.

The commits that migrated the codebase to Ruff are listed in .git-blame-ignore-revs, so git blame skips them. To make your local git use that list:

git config blame.ignoreRevsFile .git-blame-ignore-revs

Rules

ruff check enforces pycodestyle errors, pyflakes (unused imports and variables, undefined names) and import order.

Code quality report

The lint: [ruff] job also runs a wider ruleset, ci/ci-code/lint/ruff-quality.toml, that never fails a pipeline, and reports it in the merge request Code Quality widget. The same run locally:

ruff check --config ci/ci-code/lint/ruff-quality.toml --statistics .   # counts per rule
ruff check --config ci/ci-code/lint/ruff-quality.toml .                # the findings
ruff check --config ci/ci-code/lint/ruff-quality.toml --select UP006 --fix .   # one rule

ESLint / Prettier

All TypeScript and Vue code in Kaapana is formatted with Prettier and linted with ESLint. The repository root holds the whole toolchain, the same way ruff.toml does for Python:

  • package.json and package-lock.json pin Prettier, ESLint and the ESLint plugins. They hold nothing else; no app depends on them.

  • .prettierrc.json is the one Prettier style: no semicolons, single quotes, 100 character lines.

  • eslint.config.mjs is the one ESLint configuration for every app.

  • .prettierignore and the ignores in eslint.config.mjs keep build output and third-party code out.

The apps carry no lint configuration or lint dependencies of their own, so a new app is covered as soon as its files are committed.

Installation

From the repository root, once and again after every change to package-lock.json:

npm ci

This needs Node.js 20.19 or newer. The pre-commit hook and ci/ci-code/lint/ui_lint.sh run npm ci themselves when node_modules is missing or older than the lockfile.

VS Code

Install the Prettier (esbenp.prettier-vscode), ESLint (dbaeumer.vscode-eslint) and Vue (Official) (Vue.volar) extensions, then in your .vscode/settings.json:

{
  "[typescript][vue]": {
    "editor.defaultFormatter": "esbenp.prettier-vscode",
    "editor.formatOnSave": true,
    "editor.codeActionsOnSave": {
      "source.fixAll.eslint": "explicit"
    }
  }
}

On save, Prettier formats the file and ESLint applies its automatic fixes; the remaining ESLint findings are underlined in the editor. Open the repository root as the workspace folder and run npm ci there first: both extensions take their configuration and their tool version from the root, so the editor formats and lints exactly the way the pre-commit hook and the lint: [ui] job do.

The whole codebase

Format and lint the whole repository from its root:

npm run format         # formatter: prettier --write on every .ts/.mts/.tsx/.vue file
npm run lint           # linter: eslint --fix, fixes what it safely can, reports the rest

npm run format:check   # report, change nothing
npm run lint:check
npm run lint:quality   # the advisory ruleset, never enforced
ci/ci-code/lint/ui_lint.sh   # exactly what CI runs: both checks on the committed files

All are safe to run repeatedly. For one file or directory, call the tools directly:

npx prettier --write "services/base/portal-ui/**/*.{ts,mts,tsx,vue}"
npx eslint --fix services/base/portal-ui

Note

Do not run npx prettier --write .: without a file pattern Prettier also rewrites every YAML, JSON and Markdown file in the repository. npm run format limits it to TypeScript and Vue.

Rules

eslint.config.mjs enforces the rules whose findings are bugs:

  • eslint-plugin-vue essential: errors that break a Vue component, such as an invalid v-for, a mutated prop or a ref used without .value. valid-v-slot allows Vuetify’s #item.<key> slot names. Unused components and template variables and single-word component names are left to the advisory ruleset.

  • A few ESLint core rules: no-debugger, no-dupe-else-if, no-duplicate-case, no-self-assign, no-unsafe-finally, use-isnan, valid-typeof.

  • Formatting rules are off: Prettier owns formatting.

Code quality report

The lint: [ui] job also runs a wider ruleset, ci/ci-code/lint/eslint-quality.config.mjs, that never fails a pipeline, and reports it in the merge request Code Quality widget. It adds:

  • typescript-eslint recommended: unused variables, any, prefer-const and similar. No rule needs type information, so ESLint never resolves an app’s dependencies.

  • @vitest/eslint-plugin for src/**/__tests__ and eslint-plugin-playwright for e2e/ and tests/ui.

The same run locally:

npm run lint:quality
npx eslint --config ci/ci-code/lint/eslint-quality.config.mjs services/base/portal-ui

Each rule is documented on its own page, linked from the Code Quality widget.

Hadolint

Every Dockerfile in Kaapana is linted with hadolint. It checks Dockerfile best practice (pinned package versions, WORKDIR instead of cd, --no-install-recommends, COPY instead of ADD) and runs ShellCheck over the shell in every RUN. There is no established Dockerfile formatter, so there is no formatting check. One file at the repository root, .hadolint.yaml, holds the whole configuration.

Installation

The pre-commit hook installs hadolint itself. For the editor and for running it by hand:

pip install hadolint-py     # or download the binary from the hadolint releases page

VS Code

Install the hadolint extension (exiasr.hadolint). It runs the hadolint on your PATH and reads .hadolint.yaml from the repository root, so findings are underlined in the editor exactly as the pre-commit hook and the lint: [hadolint] job report them.

The whole codebase

From the repository root:

pre-commit run hadolint --all-files                # no installation needed
git ls-files -z -- '*Dockerfile' | xargs -0 hadolint   # with hadolint on your PATH

Pass a path to check one Dockerfile: hadolint services/base/portal-ui/docker/Dockerfile.

Rules

All of hadolint’s rules apply, except three that Kaapana’s build conventions trigger on every image; .hadolint.yaml ignores them:

  • DL3007: FROM local-only/<image>:latest is an image kaapana-build produces in the same build, not a floating upstream tag.

  • DL3022: COPY --from=constraints (and lib, charts) are build contexts kaapana-build passes in, not stages.

  • DL3048: LABEL IMAGE, VERSION and BUILD_IGNORE are the uppercase keys kaapana-build reads.

.hadolint.yaml sets failure-threshold: error and raises the rules that catch a broken Dockerfile to error; only these fail the pre-commit hook and lint: [hadolint]:

  • DL1000: the Dockerfile cannot be parsed.

  • DL3000: WORKDIR is not an absolute path.

  • DL3011: an EXPOSE port is out of range.

  • DL3012, DL4003, DL4004: more than one HEALTHCHECK, CMD or ENTRYPOINT; only the last one takes effect.

  • DL3021: COPY with several sources to a destination not ending in /.

  • DL3023: COPY --from refers to its own stage.

  • DL3024: two stages share a name.

  • DL3044: an ENV refers to itself.

  • DL3061: an instruction comes before FROM or ARG.

ShellCheck findings of level error (shell in a RUN that cannot be parsed) fail as well. Every other rule is advisory: hadolint’s own error rules that are not in this list (DL3004, DL3020, DL3026, DL3043, DL4000) are lowered to warning, and all findings are published to the merge request Code Quality widget. To silence one finding where it is intended, put # hadolint ignore=DL3008 on the line above the instruction.

Pre-commit hooks

Important

Install the hooks before committing — CI runs the same checks and the lint job fails on any difference:

pip install pre-commit && pre-commit install

The hooks live in .pre-commit-config.yaml and run on the staged files only:

  • ruff-check and ruff-format lint and format Python files. ruff-check applies the safe fixes of the enforced ruleset. pre-commit installs the pinned Ruff version into its own environment.

  • ui-lint runs ci/ci-code/lint/ui_lint.sh on staged TypeScript and Vue files: eslint --fix, then prettier --write. It needs node and npm on your PATH; the script installs the root toolchain on first use.

  • helm-lint runs ci/ci-code/lint/helm_lint.sh on the staged chart files. It always lints and validates the whole chart tree, but only findings in the charts you changed fail the commit; warnings in other charts are only counted (the full list is in helm-reports/helm-lint.xml). Invalid manifests fail wherever they are. It needs helm; the script downloads kubeconform.

  • hadolint lints staged Dockerfiles and fails on the enforced (error) rules. pre-commit installs the pinned hadolint version into its own environment.

Loose and strict hooks

Formatting and automatic fixes come first; the advanced rulesets are enforced only after that. The default hooks above are the loose set. The strict set is .pre-commit-config.strict.yaml: ruff and ESLint with their advisory rulesets (with fixes applied), hadolint failing on every finding, and helm lint failing on warnings. Both files pin the same tool versions.

The strict hooks are meant for commits: they run on the staged files only and keep new code-quality findings out of the repository, so the backlog shrinks file by file as files are touched. Do not run them over the whole repository; clean the backlog with the loose hooks and the fixes they apply.

pre-commit run --all-files                            # loose: fix and list the essential issues
pre-commit install -c .pre-commit-config.strict.yaml  # strict hooks on every commit
pre-commit install                                    # back to the loose hooks

When a hook changes a file, the commit stops: review the change, stage it and commit again. When a hook reports a linter finding it cannot fix, fix it by hand and commit again.

Run the hooks without committing:

pre-commit run                     # on the staged files
pre-commit run --all-files         # on the whole repository
pre-commit run ui-lint --all-files # one hook only

Skip hooks for a single commit with SKIP, a comma-separated list of hook ids:

SKIP=hadolint,helm-lint git commit -m "..."

SKIP applies to pre-commit run too. git commit --no-verify skips every hook, but CI still runs the enforced checks.

CI

The lint job in ci/pipeline/lint.yml is a matrix with one entry per linter, shown as one lint group in the pipeline. Each entry publishes its advisory findings to the merge request Code Quality widget; GitLab merges the reports of all entries into one widget. Each entry fails the pipeline on formatting drift or an enforced rule.

Until the TypeScript/Vue codebase is formatted and meets the enforced ruleset, lint: [ui] is allowed to fail and only warns. lint: [helm] is allowed to fail until the existing chart warnings are fixed.

Job

Checks

Code Quality report

Run it locally

lint: [ruff]

ruff format --check, ruff check

the wider ci/ci-code/lint/ruff-quality.toml ruleset, advisory

ruff format --check --diff . && ruff check .

lint: [ui]

prettier --check, eslint

the wider ci/ci-code/lint/eslint-quality.config.mjs ruleset, advisory

ci/ci-code/lint/ui_lint.sh

lint: [hadolint]

hadolint, error level only

the hadolint findings, all levels, advisory

pre-commit run hadolint --all-files

lint: [helm]

helm lint (warnings fail), kubeconform

none; JUnit reports in the merge request test tab

ci/ci-code/lint/helm_lint.sh

Every entry runs ci/ci-code/lint/<linter>_lint.sh, which installs its own tool (into ~/.cache/kaapana-ci, or as a pip or npm package) and runs the same checks locally and in CI. The versions cannot drift between your machine and CI: the ruff and hadolint scripts check that their RUFF_VERSION and HADOLINT_VERSION match the rev of their hooks in .pre-commit-config.yaml, and ESLint and Prettier come from the root package-lock.json everywhere.

To add a linter, add its name to the LINTER matrix and a matching ci/ci-code/lint/<linter>_lint.sh; if the tool can produce a Code Quality report, write it to gl-code-quality-report.json.