From 1447b422a7cf71c8635f2d5ede027b2e85e4d673 Mon Sep 17 00:00:00 2001 From: Andrew Aldridge Date: Mon, 18 Nov 2019 22:36:00 -0500 Subject: [PATCH] bugfix: search for git markers even when loading files from memory --- snooty/rstparser.py | 5 +---- snooty/test_project.py | 2 +- snooty/types.py | 12 ++++++++---- 3 files changed, 10 insertions(+), 9 deletions(-) diff --git a/snooty/rstparser.py b/snooty/rstparser.py index 6ec2d14d..639529a1 100644 --- a/snooty/rstparser.py +++ b/snooty/rstparser.py @@ -783,10 +783,7 @@ def __init__(self, project_config: ProjectConfig, visitor_class: Type[_V]) -> No def parse(self, path: Path, text: Optional[str]) -> Tuple[_V, str]: diagnostics: List[Diagnostic] = [] - if text is None: - text, diagnostics = self.project_config.read(path) - else: - text, diagnostics = self.project_config.substitute(text) + text, diagnostics = self.project_config.read(path, text) parser = NoTransformRstParser() settings = docutils.frontend.OptionParser( diff --git a/snooty/test_project.py b/snooty/test_project.py index 0fad070e..70651667 100644 --- a/snooty/test_project.py +++ b/snooty/test_project.py @@ -155,7 +155,7 @@ def test_merge_conflict() -> None: assert project_diagnostics[-1].message.startswith( "git merge conflict" - ) and project_diagnostics[-1].start == (69, 0) + ) and project_diagnostics[-1].start == (68, 0) assert project_diagnostics[-2].message.startswith( "git merge conflict" ) and project_diagnostics[-2].start == (35, 0) diff --git a/snooty/types.py b/snooty/types.py index 653f9562..a15003c3 100644 --- a/snooty/types.py +++ b/snooty/types.py @@ -375,14 +375,18 @@ def render_constants(self) -> Tuple["ProjectConfig", List[Diagnostic]]: self.constants = constants return self, all_diagnostics - def read(self, path: Path) -> Tuple[str, List[Diagnostic]]: - text = path.read_text(encoding="utf-8") - source_text, diagnostics = self.substitute(text) + def read( + self, path: Path, text: Optional[str] = None + ) -> Tuple[str, List[Diagnostic]]: + if text is None: + text = path.read_text(encoding="utf-8") + + text, diagnostics = self.substitute(text) match_found = PAT_GIT_MARKER.finditer(text) if match_found: for match in match_found: - lineno = source_text.count("\n", 0, match.start()) + lineno = text.count("\n", 0, match.start()) diagnostics.append(Diagnostic.error("git merge conflict found", lineno)) return (text, diagnostics)