@@ -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+
4954ErrorStrings = {
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