Skip to content

Commit c3bddb8

Browse files
committed
Assembly files often use tabs, only disallow trailing tabs.
1 parent a3763e5 commit c3bddb8

File tree

2 files changed

+19
-8
lines changed

2 files changed

+19
-8
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,3 +58,4 @@ fujinet_releases/*
5858
*~
5959
*.orig
6060
*.rej
61+
*.lst

coding-standard.py

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,11 @@ class FormatError(Enum):
4646
IllegalTabs = auto()
4747
CodingStandardViolation = auto()
4848

49+
class TabsOk(Enum):
50+
Nope = auto() # Calling it "None" seems confusing
51+
Leading = auto()
52+
AllTabs = auto()
53+
4954
ErrorStrings = {
5055
FormatError.TrailingWhitespace: "Trailing whitespace",
5156
FormatError.IllegalTabs: "Tab characters",
@@ -140,9 +145,11 @@ def __init__(self, path, contents=None):
140145
if contents is None:
141146
raise ValueError("Contents not provided")
142147

143-
self.allowLeadingTab = False
148+
self.allowTabs = TabsOk.Nope
144149
if self.isMakefile:
145-
self.allowLeadingTab = True
150+
self.allowTabs = TabsOk.Leading
151+
elif self.isAssembly:
152+
self.allowTabs = TabsOk.AllTabs
146153

147154
return
148155

@@ -153,7 +160,7 @@ def splitLeadingTab(self, line):
153160
"""
154161
prefix = ""
155162
suffix = line
156-
if self.allowLeadingTab:
163+
if self.allowTabs == TabsOk.Leading:
157164
if line and line[0] == '\t':
158165
prefix = line[:1]
159166
suffix = line[1:]
@@ -177,7 +184,7 @@ def fixupWhitespace(self):
177184
lines = []
178185
for line in self.contents:
179186
line = line.rstrip()
180-
if "\t" in line:
187+
if self.allowTabs != TabsOk.AllTabs and "\t" in line:
181188
prefix, suffix = self.splitLeadingTab(line)
182189
while "\t" in suffix:
183190
column = suffix.index("\t")
@@ -243,9 +250,6 @@ def checkFormatting(self, repo):
243250
else:
244251
formatted = self.fixupWhitespace()
245252

246-
elif self.isMakefile:
247-
formatted = self.fixupWhitespace()
248-
249253
else:
250254
formatted = self.fixupWhitespace()
251255

@@ -268,7 +272,7 @@ def classifyErrors(self):
268272
trailingStart = len(line.rstrip())
269273
line = line[:trailingStart]
270274
prefix, suffix = self.splitLeadingTab(line)
271-
if "\t" in suffix:
275+
if self.allowTabs != TabsOk.AllTabs and "\t" in suffix:
272276
errors.add(FormatError.IllegalTabs)
273277
break
274278

@@ -317,6 +321,12 @@ def isMakefile(self):
317321
return True
318322
return False
319323

324+
@property
325+
def isAssembly(self):
326+
if self.path.suffix in [".asm", ".s"]:
327+
return True
328+
return False
329+
320330
@property
321331
def isPython(self):
322332
if self.path.suffix == ".py" or self.contents[0].startswith("#!/usr/bin/env python"):

0 commit comments

Comments
 (0)