Skip to content

Commit 57f43c8

Browse files
committed
objc file detection comments
1 parent 1bb278c commit 57f43c8

File tree

1 file changed

+14
-8
lines changed

1 file changed

+14
-8
lines changed

scripts/format_code.py

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,6 @@ def list_files_from_directory(path, recurse):
130130
in FILE_TYPE_EXTENSIONS.
131131
"""
132132
filenames = []
133-
134133
for root, dirs, files in os.walk(path):
135134
for filename in files:
136135
if filename.endswith(FILE_TYPE_EXTENSIONS):
@@ -177,12 +176,19 @@ def validate_arguments():
177176
return False
178177
return True
179178

180-
def is_file_objc(filename):
181-
# Only detect header files since we already filter out other
182-
# file types by extensions.
179+
def is_file_objc_header(filename):
180+
"""Checks the contents of the file to determine if it contains language
181+
constructs that appear in obj-c but not in C/C++.
182+
183+
Args:
184+
filename (string): the name of the file to check
185+
186+
Returns:
187+
bool: True if the header file contains known obj-c language definitions.
188+
Returns False otherwise.
189+
"""
183190
if '.h' not in filename:
184191
return False
185-
186192
objective_c_tags = [ '@end', '@class', '#import']
187193
for line in open(filename):
188194
for tag in objective_c_tags:
@@ -216,17 +222,17 @@ def main(argv):
216222
count = 0
217223
for filename in filenames:
218224
if does_file_need_formatting(filename):
219-
if is_file_objc(filename):
225+
if is_file_objc_header(filename):
220226
if FLAGS.verbose:
221227
print(' - Ignoring obj header: "{0}"'.format(filename))
222228
else:
223229
if FLAGS.verbose:
224-
print(' - Formatting: "{0}"'.format(filename))
230+
print(' - FRMT: "{0}"'.format(filename))
225231
format_file(filename)
226232
count += 1
227233
else:
228234
if FLAGS.verbose:
229-
print(' - OK: "{0}"'.format(filename))
235+
print(' - OK: "{0}"'.format(filename))
230236
print(' > Formatted {0} file(s).'.format(count))
231237
else:
232238
count = 0

0 commit comments

Comments
 (0)