Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ fujinet_releases/*
*~
*.orig
*.rej
*.lst

# espressif managed components
managed_components
26 changes: 18 additions & 8 deletions coding-standard.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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

Expand All @@ -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:]
Expand All @@ -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")
Expand Down Expand Up @@ -243,9 +250,6 @@ def checkFormatting(self, repo):
else:
formatted = self.fixupWhitespace()

elif self.isMakefile:
formatted = self.fixupWhitespace()

else:
formatted = self.fixupWhitespace()

Expand All @@ -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

Expand Down Expand Up @@ -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"):
Expand Down
Loading