Skip to content

Commit

Permalink
bugfix: search for git markers even when loading files from memory
Browse files Browse the repository at this point in the history
  • Loading branch information
i80and committed Nov 19, 2019
1 parent c5f980d commit 1447b42
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 9 deletions.
5 changes: 1 addition & 4 deletions snooty/rstparser.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
2 changes: 1 addition & 1 deletion snooty/test_project.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
12 changes: 8 additions & 4 deletions snooty/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 1447b42

Please sign in to comment.