Skip to content

Forbid imports whose extracted target matches a forbid regex, within the paths scope — an architectural import firewall (staging-layer isolation, core/providers separation, private-API gates). Matches the import target, not the raw line (so a comment or string mentioning the path doesn’t fire — the low-false-positive specialisation of file_content_forbidden). language (go/python/rust/js/scala/java/dart/nix) supplies a built-in import-line pattern; import_pattern overrides it (capture group 1 = target; required for generic). The js preset (whose pattern is unanchored, to catch dynamic import("m") / require("m")) additionally blanks // and /* … */ comments before matching, so a JSDoc @typedef {import("../x")} type annotation isn’t mistaken for a real import. allow globs exempt sanctioned files. One violation per offending import.

OptionTypeRequiredDefaultDescription
allowlist of string[]File globs inside the scope that are exempt from the gate.
forbidstringyesRegex tested against the extracted import target.
import_patternstringnullExplicit import-line regex (capture group 1 = target). Overrides the language preset.
languageone of go | python | rust | js | scala | java | dart | nix | genericBuilt-in import-line pattern preset (capture group 1 = the imported target). Omit to require an explicit import_pattern.

Plus the common paths, level, id, and when fields. This table is generated from the JSON Schema; option types and defaults are authoritative.

A staging file that imports a forbidden module

Section titled “A staging file that imports a forbidden module”

The rule fires on this repository:

staging/src/k8s.io/api/types.go
staging/src/k8s.io/api/types.go
package api
import (
"fmt"
"k8s.io/kubernetes/pkg/apis/core"
)

With this .alint.yml:

version: 1
rules:
- id: staging-no-main-module
kind: import_gate
paths: "staging/src/k8s.io/**/*.go"
language: go
forbid: "^k8s\\.io/kubernetes/"
level: error

alint check reports:

Terminal window
--- staging/src/k8s.io/api/types.go --------------------------------------------
x error staging-no-main-module
5:1 forbidden import "k8s.io/kubernetes/pkg/apis/core" at this scope
(matches /^k8s\.io/kubernetes//)
Summary (1 violation):
x 1 error
0 passing * 1 failing

This repository is compliant:

staging/src/k8s.io/api/types.go
staging/src/k8s.io/api/types.go
package api
import (
"fmt"
"k8s.io/apimachinery/pkg/runtime"
)

With this .alint.yml:

version: 1
rules:
- id: staging-no-main-module
kind: import_gate
paths: "staging/src/k8s.io/**/*.go"
language: go
forbid: "^k8s\\.io/kubernetes/"
level: error

alint check reports:

Terminal window
v All 1 rule(s) passed.