summaryrefslogtreecommitdiffstats
path: root/tests/lint_tests/lint_tutil.py
diff options
context:
space:
mode:
Diffstat (limited to 'tests/lint_tests/lint_tutil.py')
-rw-r--r--tests/lint_tests/lint_tutil.py30
1 files changed, 24 insertions, 6 deletions
diff --git a/tests/lint_tests/lint_tutil.py b/tests/lint_tests/lint_tutil.py
index 267f669..c16fde3 100644
--- a/tests/lint_tests/lint_tutil.py
+++ b/tests/lint_tests/lint_tutil.py
@@ -1,5 +1,5 @@
import collections
-from typing import List, Optional, Mapping, Any, Callable
+from typing import List, Optional, Mapping, Any, Callable, Sequence
import pytest
@@ -9,11 +9,14 @@ from debputy.linting.lint_util import (
LintStateImpl,
LintState,
)
-from debputy.lsp.style_prefs import StylePreferenceTable, EffectivePreference
+from debputy.lsp.maint_prefs import (
+ MaintainerPreferenceTable,
+ EffectiveFormattingPreference,
+)
from debputy.packages import DctrlParser
from debputy.plugin.api.feature_set import PluginProvidedFeatureSet
-from debputy.lsprotocol.types import Diagnostic, DiagnosticSeverity
+from debputy.lsprotocol.types import Diagnostic, DiagnosticSeverity, Range
try:
@@ -42,8 +45,8 @@ class LintWrapper:
self.path = path
self._dctrl_parser = dctrl_parser
self.source_root: Optional[VirtualPathBase] = None
- self.lint_style_preference_table = StylePreferenceTable({}, {})
- self.effective_preference: Optional[EffectivePreference] = None
+ self.lint_maint_preference_table = MaintainerPreferenceTable({}, {})
+ self.effective_preference: Optional[EffectiveFormattingPreference] = None
def __call__(self, lines: List[str]) -> Optional[List["Diagnostic"]]:
source_package = None
@@ -59,7 +62,7 @@ class LintWrapper:
debian_dir = source_root.get("debian") if source_root is not None else None
state = LintStateImpl(
self._debputy_plugin_feature_set,
- self.lint_style_preference_table,
+ self.lint_maint_preference_table,
source_root,
debian_dir,
self.path,
@@ -108,3 +111,18 @@ def group_diagnostics_by_severity(
by_severity[severity].append(diagnostic)
return by_severity
+
+
+def diag_range_to_text(lines: Sequence[str], range_: "Range") -> str:
+ parts = []
+ for line_no in range(range_.start.line, range_.end.line + 1):
+ line = lines[line_no]
+ chunk = line
+ if line_no == range_.start.line and line_no == range_.end.line:
+ chunk = line[range_.start.character : range_.end.character]
+ elif line_no == range_.start.line:
+ chunk = line[range_.start.character :]
+ elif line_no == range_.end.line:
+ chunk = line[: range_.end.character]
+ parts.append(chunk)
+ return "".join(parts)