Skip to content

Commit 138406a

Browse files
committed
Simplify handling of too-short indent calculation, and remove the 'couldn't infer' error. Closes #2985
1 parent 2623e7a commit 138406a

File tree

2 files changed

+10
-12
lines changed

2 files changed

+10
-12
lines changed

bikeshed/Spec.py

-8
Original file line numberDiff line numberDiff line change
@@ -222,14 +222,6 @@ def assembleDocument(self) -> Spec:
222222
if "mixed-indents" in self.md.complainAbout:
223223
if self.md.indentInfo and self.md.indentInfo.char:
224224
checkForMixedIndents(self.lines, self.md.indentInfo)
225-
elif len(self.lines) > 50:
226-
# Only complain about a failed inference if it's long
227-
# enough that I could reasonably infer something.
228-
m.warn(
229-
"`Complain About: mixed-indents yes` is active, but I couldn't infer the document's indentation. Be more consistent, or turn this lint off.",
230-
)
231-
else:
232-
pass
233225

234226
# Deal with further <pre> blocks, and markdown
235227
self.lines = datablocks.transformDataBlocks(self, self.lines)

bikeshed/metadata.py

+10-4
Original file line numberDiff line numberDiff line change
@@ -1096,14 +1096,19 @@ class IndentInfo:
10961096
char: str | None = None
10971097
spaceLines: int = 0
10981098
tabLines: int = 0
1099-
totalLines: int = 0
1099+
neitherLines: int = 0
1100+
1101+
def tooShort(self) -> bool:
1102+
return (self.spaceLines + self.tabLines) < 20
11001103

11011104

11021105
def inferIndent(lines: t.Sequence[Line]) -> IndentInfo:
1106+
# Infer what indent character the document is using.
11031107
# If the document uses space indentation,
11041108
# infer what the indent size is by seeing what % of indents
11051109
# are divisible by various values.
1106-
# (If it uses tabs, or no indents at all, returns None.)
1110+
# A sufficiently short document, or one with too few indented lines,
1111+
# will fail to infer anything.
11071112
indentSizes: Counter[int] = Counter()
11081113
info = IndentInfo()
11091114
for line in lines:
@@ -1115,9 +1120,10 @@ def inferIndent(lines: t.Sequence[Line]) -> IndentInfo:
11151120
info.spaceLines += 1
11161121
elif line.text[0:1] == "\t":
11171122
info.tabLines += 1
1118-
info.totalLines += 1
1123+
else:
1124+
info.neitherLines += 1
11191125
# If very few lines are indented at all, just bail
1120-
if (info.spaceLines + info.tabLines) < info.totalLines / 20:
1126+
if info.tooShort():
11211127
return info
11221128
# If tab indents predominate, assume tab-indent.
11231129
if info.spaceLines < info.tabLines:

0 commit comments

Comments
 (0)