config

package
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 15, 2026 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Overview

Package config loads m-cli's project-level configuration — the [lint.*] and fmt sections of a `.m-cli.toml` (preferred) or a `[tool.m-cli]` table in pyproject.toml. It is a faithful port of the Python tool's config.py.

Discovery walks UP from a start directory toward the filesystem root or the nearest `.git` boundary (whichever comes first), mirroring how ruff / black scope a project. Settings layer defaults → config file → CLI flag, with flags always winning; that final layering happens at the call sites (main.go), not here. An absent file yields an empty Config and changes nothing.

Unknown keys are silently ignored (cheap forward-compat). A value that IS present but invalid (a bad severity name, a non-int threshold, an unknown threshold key, a bad target_engine, …) is a HARD error naming the source path — never a silent fallback.

Index

Constants

View Source
const (
	// ConfigFilename is the preferred project-local config file.
	ConfigFilename = ".m-cli.toml"
	// PyprojectFilename is the Python-packaging fallback.
	PyprojectFilename = "pyproject.toml"
)

Variables

View Source
var KnownEngines = []string{"any", "yottadb", "iris"}

KnownEngines are the recognized values for [lint] target_engine. "any" (default) keeps the linter portable; the named engines unlock engine-specific allowlists.

View Source
var KnownThresholds = map[string]int{
	"line_length":         200,
	"code_line_length":    1000,
	"routine_lines":       1000,
	"label_lines":         50,
	"cyclomatic":          15,
	"cognitive":           20,
	"dot_block_depth":     5,
	"argument_count":      7,
	"commands_per_line":   3,
	"comment_density_pct": 10,
}

KnownThresholds maps every configurable threshold name to its default value. It doubles as the allowlist for config-file validation — an unknown key is a likely typo and is rejected at load time. Ported verbatim from the Python tool's lint/thresholds.py (the Go linter only wires a subset today, but the full set validates so a forward-compatible config never errors spuriously).

Functions

func FindConfig

func FindConfig(start string) string

FindConfig walks up from start looking for an m-cli config file, returning the first match's path or "" if none. A .m-cli.toml is preferred over a pyproject.toml at the same level. The walk stops at the filesystem root or at a directory containing .git (whichever comes first) — but the per-level config check runs BEFORE the boundary check, so a config sitting at the .git directory is still found.

Types

type Config

type Config struct {
	LintRules                string            // [lint] rules — profile name or comma-list ("" = unset)
	LintDisable              []string          // [lint] disable — rule ids skipped after selection
	LintSeverityOverrides    map[string]string // [lint.severity] — rule id -> severity name
	LintTargetEngine         string            // [lint] target_engine — normalized; "" = unset
	LintThresholds           map[string]int    // [lint.thresholds] — user overrides only (validated)
	LintTaintFormalsTainted  *bool             // [lint.taint] formals_tainted — nil = use built-in default
	LintTaintExtraSanitizers []string          // [lint.taint] extra_sanitizers — upper-cased
	LintVistaKernelLocals    []string          // [lint.vista] kernel_locals — {"default"} | names | empty (strict)
	LintVistaTrustedRoutines []string          // [lint.vista] trusted_routines — same shape
	FmtRules                 string            // [fmt] rules — "" = unset
	SourcePath               string            // where this Config was loaded from, if any
}

Config is the resolved m-cli configuration. A zero value means "nothing configured"; every CLI / linter falls back to its built-in default for any unset field.

func LoadConfig

func LoadConfig(start string) (Config, error)

LoadConfig finds and loads the config starting from start. Returns an empty Config (no error) when no file is found or the file is unreadable; returns an error only when a found file is malformed or contains an invalid value.

func LoadFile

func LoadFile(path string) (Config, error)

LoadFile loads and validates a specific config file (used for an explicit --config flag, bypassing discovery). An unreadable file yields an empty Config; a malformed/invalid one is an error.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL