From 138406a1ad69d16158ab926c1eb3d7ad07214647 Mon Sep 17 00:00:00 2001 From: Tab Atkins-Bittner Date: Thu, 9 Jan 2025 14:33:52 -0800 Subject: [PATCH] Simplify handling of too-short indent calculation, and remove the 'couldn't infer' error. Closes #2985 --- bikeshed/Spec.py | 8 -------- bikeshed/metadata.py | 14 ++++++++++---- 2 files changed, 10 insertions(+), 12 deletions(-) diff --git a/bikeshed/Spec.py b/bikeshed/Spec.py index c4af0bb9f0..27d167261e 100644 --- a/bikeshed/Spec.py +++ b/bikeshed/Spec.py @@ -222,14 +222,6 @@ def assembleDocument(self) -> Spec: if "mixed-indents" in self.md.complainAbout: if self.md.indentInfo and self.md.indentInfo.char: checkForMixedIndents(self.lines, self.md.indentInfo) - elif len(self.lines) > 50: - # Only complain about a failed inference if it's long - # enough that I could reasonably infer something. - m.warn( - "`Complain About: mixed-indents yes` is active, but I couldn't infer the document's indentation. Be more consistent, or turn this lint off.", - ) - else: - pass # Deal with further
 blocks, and markdown
         self.lines = datablocks.transformDataBlocks(self, self.lines)
diff --git a/bikeshed/metadata.py b/bikeshed/metadata.py
index fa65cfdcb9..bdcfc0720c 100644
--- a/bikeshed/metadata.py
+++ b/bikeshed/metadata.py
@@ -1096,14 +1096,19 @@ class IndentInfo:
     char: str | None = None
     spaceLines: int = 0
     tabLines: int = 0
-    totalLines: int = 0
+    neitherLines: int = 0
+
+    def tooShort(self) -> bool:
+        return (self.spaceLines + self.tabLines) < 20
 
 
 def inferIndent(lines: t.Sequence[Line]) -> IndentInfo:
+    # Infer what indent character the document is using.
     # If the document uses space indentation,
     # infer what the indent size is by seeing what % of indents
     # are divisible by various values.
-    # (If it uses tabs, or no indents at all, returns None.)
+    # A sufficiently short document, or one with too few indented lines,
+    # will fail to infer anything.
     indentSizes: Counter[int] = Counter()
     info = IndentInfo()
     for line in lines:
@@ -1115,9 +1120,10 @@ def inferIndent(lines: t.Sequence[Line]) -> IndentInfo:
             info.spaceLines += 1
         elif line.text[0:1] == "\t":
             info.tabLines += 1
-        info.totalLines += 1
+        else:
+            info.neitherLines += 1
     # If very few lines are indented at all, just bail
-    if (info.spaceLines + info.tabLines) < info.totalLines / 20:
+    if info.tooShort():
         return info
     # If tab indents predominate, assume tab-indent.
     if info.spaceLines < info.tabLines: