Skip to content

Commit 51a6224

Browse files
committed
Add allowlist for files with tabs
1 parent ffb2a02 commit 51a6224

File tree

1 file changed

+16
-4
lines changed

1 file changed

+16
-4
lines changed

Tools/patchcheck/reindent.py

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,10 @@
5555
# A specified newline to be used in the output (set by --newline option)
5656
spec_newline = None
5757

58+
ALLOWLIST_TABS = {
59+
"Tools/c-analyzer/cpython/_parser.py",
60+
}
61+
5862

5963
def usage(msg=None):
6064
if msg is None:
@@ -125,7 +129,7 @@ def check(file):
125129
return
126130
try:
127131
with open(file, encoding=encoding) as f:
128-
r = Reindenter(f)
132+
r = Reindenter(f, file)
129133
except IOError as msg:
130134
errprint("%s: I/O Error: %s" % (file, str(msg)))
131135
return
@@ -173,7 +177,7 @@ def _rstrip(line, JUNK='\n \t'):
173177

174178
class Reindenter:
175179

176-
def __init__(self, f):
180+
def __init__(self, f, filename=None):
177181
self.find_stmt = 1 # next token begins a fresh stmt?
178182
self.level = 0 # current indent level
179183

@@ -183,8 +187,16 @@ def __init__(self, f):
183187
# File lines, rstripped & tab-expanded. Dummy at start is so
184188
# that we can use tokenize's 1-based line numbering easily.
185189
# Note that a line is all-blank iff it's "\n".
186-
self.lines = [_rstrip(line).expandtabs() + "\n"
187-
for line in self.raw]
190+
self.lines = [
191+
(
192+
_rstrip(line)
193+
if filename in ALLOWLIST_TABS
194+
else _rstrip(line).expandtabs()
195+
)
196+
+ "\n"
197+
for line in self.raw
198+
]
199+
188200
self.lines.insert(0, None)
189201
self.index = 1 # index into self.lines of next line
190202

0 commit comments

Comments
 (0)