diff --git a/.gitignore b/.gitignore index 59747d3ed..bf6a7993a 100644 --- a/.gitignore +++ b/.gitignore @@ -58,6 +58,7 @@ fujinet_releases/* *~ *.orig *.rej +*.lst # espressif managed components managed_components diff --git a/coding-standard.py b/coding-standard.py index db1921735..6468aa8e8 100755 --- a/coding-standard.py +++ b/coding-standard.py @@ -46,6 +46,11 @@ class FormatError(Enum): IllegalTabs = auto() CodingStandardViolation = auto() +class TabsOk(Enum): + Nope = auto() # Calling it "None" seems confusing + Leading = auto() + AllTabs = auto() + ErrorStrings = { FormatError.TrailingWhitespace: "Trailing whitespace", FormatError.IllegalTabs: "Tab characters", @@ -140,9 +145,11 @@ def __init__(self, path, contents=None): if contents is None: raise ValueError("Contents not provided") - self.allowLeadingTab = False + self.allowTabs = TabsOk.Nope if self.isMakefile: - self.allowLeadingTab = True + self.allowTabs = TabsOk.Leading + elif self.isAssembly: + self.allowTabs = TabsOk.AllTabs return @@ -153,7 +160,7 @@ def splitLeadingTab(self, line): """ prefix = "" suffix = line - if self.allowLeadingTab: + if self.allowTabs == TabsOk.Leading: if line and line[0] == '\t': prefix = line[:1] suffix = line[1:] @@ -177,7 +184,7 @@ def fixupWhitespace(self): lines = [] for line in self.contents: line = line.rstrip() - if "\t" in line: + if self.allowTabs != TabsOk.AllTabs and "\t" in line: prefix, suffix = self.splitLeadingTab(line) while "\t" in suffix: column = suffix.index("\t") @@ -243,9 +250,6 @@ def checkFormatting(self, repo): else: formatted = self.fixupWhitespace() - elif self.isMakefile: - formatted = self.fixupWhitespace() - else: formatted = self.fixupWhitespace() @@ -268,7 +272,7 @@ def classifyErrors(self): trailingStart = len(line.rstrip()) line = line[:trailingStart] prefix, suffix = self.splitLeadingTab(line) - if "\t" in suffix: + if self.allowTabs != TabsOk.AllTabs and "\t" in suffix: errors.add(FormatError.IllegalTabs) break @@ -317,6 +321,12 @@ def isMakefile(self): return True return False + @property + def isAssembly(self): + if self.path.suffix in [".asm", ".s"]: + return True + return False + @property def isPython(self): if self.path.suffix == ".py" or self.contents[0].startswith("#!/usr/bin/env python"):