Skip to content

Commit f2c4853

Browse files
authored
Preserve relative indentation between lines (#173)
When different lines as part of the same message reference have different line numbers or files (such as messages from a static checker referencing different parts of a document), normalize to the maximum leading length to preserve relative indentation among lines.
1 parent fcd8448 commit f2c4853

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

schema_salad/sourceline.py

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -67,19 +67,26 @@ def strip_dup_lineno(text, maxline=None): # type: (Text, int) -> Text
6767
maxline = int(os.environ.get("COLUMNS", "100"))
6868
pre = None
6969
msg = []
70+
maxno = 0
71+
for l in text.splitlines():
72+
g = lineno_re.match(l)
73+
if not g:
74+
continue
75+
maxno = max(maxno, len(g.group(1)))
76+
7077
for l in text.splitlines():
7178
g = lineno_re.match(l)
7279
if not g:
7380
msg.append(l)
7481
continue
75-
shift = len(g.group(1)) + len(g.group(3))
76-
g2 = reflow(g.group(2), maxline-shift, " " * shift)
7782
if g.group(1) != pre:
83+
shift = maxno + len(g.group(3))
84+
g2 = reflow(g.group(2), maxline-shift, " " * shift)
7885
pre = g.group(1)
79-
msg.append(pre + g2)
86+
msg.append(pre + " " * (maxno-len(g.group(1))) + g2)
8087
else:
81-
g2 = reflow(g.group(2), maxline-len(g.group(1)), " " * (len(g.group(1))+len(g.group(3))))
82-
msg.append(" " * len(g.group(1)) + g2)
88+
g2 = reflow(g.group(2), maxline-maxno, " " * (maxno+len(g.group(3))))
89+
msg.append(" " * maxno + g2)
8390
return "\n".join(msg)
8491

8592
def cmap(d, lc=None, fn=None): # type: (Union[int, float, str, Text, Dict, List], List[int], Text) -> Union[int, float, str, Text, CommentedMap, CommentedSeq]

0 commit comments

Comments
 (0)