Skip to content

Commit

Permalink
Don't count lines indented with literally one space, and also don't e…
Browse files Browse the repository at this point in the history
…xplode if I still end up with an empty counter. Thanks, @ThePhD!
  • Loading branch information
tabatkins committed Oct 15, 2024
1 parent 6651ded commit eca22d6
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions bikeshed/metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -1105,7 +1105,9 @@ def inferIndent(lines: t.Sequence[Line]) -> IndentInfo:
indentSizes: Counter[int] = Counter()
info = IndentInfo()
for line in lines:
match = re.match("( +)", line.text)
# Purposely require at least two spaces; I don't
# auto-detect single-space indents. Get help.
match = re.match("( {2,})", line.text)
if match:
indentSizes[len(match.group(1))] += 1
info.spaceLines += 1
Expand Down Expand Up @@ -1136,7 +1138,8 @@ def inferIndent(lines: t.Sequence[Line]) -> IndentInfo:
evenDivisions[candidateIndent] += lineCount
if spaceCount == candidateIndent:
evenDivisions[candidateIndent] += lineCount
info.size = evenDivisions.most_common(1)[0][0]
if evenDivisions:
info.size = evenDivisions.most_common(1)[0][0]
return info


Expand Down

1 comment on commit eca22d6

@ThePhD
Copy link

@ThePhD ThePhD commented on eca22d6 Oct 15, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎉!

Please sign in to comment.