Coverage for lintro / utils / config_constants.py: 100%
19 statements
« prev ^ index » next coverage.py v7.13.0, created at 2026-04-03 18:53 +0000
« prev ^ index » next coverage.py v7.13.0, created at 2026-04-03 18:53 +0000
1"""Configuration constants for Lintro.
3This module provides constants, enums, and dataclasses used across the
4unified configuration system.
5"""
7from __future__ import annotations
9from dataclasses import dataclass, field
10from enum import StrEnum, auto
11from typing import Any
13from lintro.enums.tool_name import ToolName
16class ToolOrderStrategy(StrEnum):
17 """Strategy for ordering tool execution.
19 Attributes:
20 PRIORITY: Use tool priority values (formatters before linters).
21 ALPHABETICAL: Alphabetical by tool name.
22 CUSTOM: Custom order defined in config.
23 """
25 PRIORITY = auto()
26 ALPHABETICAL = auto()
27 CUSTOM = auto()
30@dataclass
31class ToolConfigInfo:
32 """Information about a tool's configuration sources.
34 Attributes:
35 tool_name: Name of the tool.
36 native_config: Configuration from native tool config files.
37 lintro_tool_config: Configuration from [tool.lintro.<tool>].
38 effective_config: Computed effective configuration.
39 warnings: List of warnings about configuration issues.
40 is_injectable: Whether Lintro can inject config to this tool.
41 """
43 tool_name: str
44 native_config: dict[str, Any] = field(default_factory=dict)
45 lintro_tool_config: dict[str, Any] = field(default_factory=dict)
46 effective_config: dict[str, Any] = field(default_factory=dict)
47 warnings: list[str] = field(default_factory=list)
48 is_injectable: bool = True
51# Global settings that Lintro can manage across tools.
52# Each setting maps to tool-specific config keys and indicates which tools
53# support injection via Lintro config (vs requiring native config files).
54GLOBAL_SETTINGS: dict[str, dict[str, Any]] = {
55 "line_length": {
56 "tools": {
57 ToolName.RUFF: "line-length",
58 ToolName.BLACK: "line-length",
59 ToolName.MARKDOWNLINT: "config.MD013.line_length",
60 ToolName.YAMLLINT: "rules.line-length.max",
61 },
62 "injectable": {
63 ToolName.RUFF,
64 ToolName.BLACK,
65 ToolName.MARKDOWNLINT,
66 ToolName.YAMLLINT,
67 },
68 },
69 "target_python": {
70 "tools": {
71 ToolName.RUFF: "target-version",
72 ToolName.BLACK: "target-version",
73 },
74 "injectable": {ToolName.RUFF, ToolName.BLACK},
75 },
76 "indent_size": {
77 "tools": {
78 ToolName.RUFF: "indent-width",
79 },
80 "injectable": {ToolName.RUFF},
81 },
82 "quote_style": {
83 "tools": {
84 ToolName.RUFF: "quote-style",
85 },
86 "injectable": {ToolName.RUFF},
87 },
88}
90# Default tool priorities (lower = runs first).
91# Formatters run before linters to avoid false positives.
92DEFAULT_TOOL_PRIORITIES: dict[str, int] = {
93 ToolName.BLACK: 15,
94 ToolName.RUFF: 20,
95 ToolName.OXFMT: 25,
96 ToolName.MARKDOWNLINT: 30,
97 ToolName.YAMLLINT: 35,
98 ToolName.BANDIT: 45,
99 ToolName.HADOLINT: 50,
100 ToolName.OXLINT: 50,
101 ToolName.ACTIONLINT: 55,
102 ToolName.MYPY: 82,
103 ToolName.TSC: 82,
104 ToolName.OSV_SCANNER: 90,
105 ToolName.PYTEST: 100,
106}