Skip to content

Commit

Permalink
scripts: indent using 4 spaces
Browse files Browse the repository at this point in the history
  • Loading branch information
antonv6 committed Jul 28, 2018
1 parent 7ee81c9 commit f85e011
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 49 deletions.
24 changes: 12 additions & 12 deletions scripts/check_language_files_not_BOM.py
Expand Up @@ -14,27 +14,27 @@


def is_BOM_encoded_file(path):
""" Returns whether |path| is a file that is encoded in UTF-8 with BOM. """
with open(path, 'rb') as f:
raw = f.read(4)
return raw.startswith(codecs.BOM_UTF8)
""" Returns whether |path| is a file that is encoded in UTF-8 with BOM. """
with open(path, 'rb') as f:
raw = f.read(4)
return raw.startswith(codecs.BOM_UTF8)


if len(sys.argv) > 2:
sys.exit('Usage: {} [root]'.format(sys.argv[0]))
sys.exit('Usage: {} [root]'.format(sys.argv[0]))

top = os.getcwd()
if len(sys.argv) == 2:
top = os.path.join(top, sys.argv[1])
top = os.path.join(top, sys.argv[1])

offending_files = []
for root, dirs, files in os.walk(top):
for f in files:
if f.endswith('.lua'):
path = os.path.join(root, f)
if is_BOM_encoded_file(path):
offending_files.append(f)
for f in files:
if f.endswith('.lua'):
path = os.path.join(root, f)
if is_BOM_encoded_file(path):
offending_files.append(f)

if offending_files:
sys.exit('Found files with UTF-8 with BOM encoding: ' + str(offending_files))
sys.exit('Found files with UTF-8 with BOM encoding: ' + str(offending_files))
sys.exit(0)
36 changes: 18 additions & 18 deletions scripts/check_lua_classes.py
Expand Up @@ -15,25 +15,25 @@
ignored = os.listdir(os.path.join(script_dir, "languages"))
problem_found = False
for root, _, files in os.walk(script_dir):
for script in files:
if script.endswith(".lua") and script not in ignored:
script_string = open(os.path.join(root, script), 'r').read()
for found_class in re.findall(regex, script_string, re.MULTILINE):
if not problem_found:
print("******* CHECK CLASS DECLARATIONS *******")
problem_found = True
print("Invalid/Improper Class Declarations Found:")
path = print_root_regex.search(root).group(0)
print("*{}:{}".format(os.path.join(path, script), found_class))
for script in files:
if script.endswith(".lua") and script not in ignored:
script_string = open(os.path.join(root, script), 'r').read()
for found_class in re.findall(regex, script_string, re.MULTILINE):
if not problem_found:
print("******* CHECK CLASS DECLARATIONS *******")
problem_found = True
print("Invalid/Improper Class Declarations Found:")
path = print_root_regex.search(root).group(0)
print("*{}:{}".format(os.path.join(path, script), found_class))

if problem_found:
print("\nReason: The class declaration(s) didn't begin as follows:")
print("")
print("class \"Name\" / class \"Name\" (Parent)")
print("")
print("---@type Name")
print("local Name = _G[\"Name\"]")
print("-----------------------------------------\n")
sys.exit(1)
print("\nReason: The class declaration(s) didn't begin as follows:")
print("")
print("class \"Name\" / class \"Name\" (Parent)")
print("")
print("---@type Name")
print("local Name = _G[\"Name\"]")
print("-----------------------------------------\n")
sys.exit(1)

sys.exit(0)
38 changes: 19 additions & 19 deletions scripts/check_trailing_whitespaces.py
Expand Up @@ -13,32 +13,32 @@


def has_trailing_whitespaces(path):
""" Returns whether |path| has trailing whitespaces. """
handle = open(path, 'r')
for line in handle:
for idx in range(-1, -len(line) - 1, -1):
if line[idx] in ('\n', '\r'):
continue
if line[idx] in (' ', '\t'):
handle.close()
return True
break
handle.close()
return False
""" Returns whether |path| has trailing whitespaces. """
handle = open(path, 'r')
for line in handle:
for idx in range(-1, -len(line) - 1, -1):
if line[idx] in ('\n', '\r'):
continue
if line[idx] in (' ', '\t'):
handle.close()
return True
break
handle.close()
return False


if len(sys.argv) > 2:
sys.exit('Usage: {} [root]'.format(sys.argv[0]))
sys.exit('Usage: {} [root]'.format(sys.argv[0]))

top = os.getcwd()
if len(sys.argv) == 2:
top = os.path.join(top, sys.argv[1])
top = os.path.join(top, sys.argv[1])

for root, dirs, files in os.walk(top):
for f in files:
if f.endswith(('.py', '.lua', '.h', '.cpp', '.cc', '.c')):
path = os.path.join(root, f)
if has_trailing_whitespaces(path):
sys.exit('Found a file with trailing whitespaces: ' + path)
for f in files:
if f.endswith(('.py', '.lua', '.h', '.cpp', '.cc', '.c')):
path = os.path.join(root, f)
if has_trailing_whitespaces(path):
sys.exit('Found a file with trailing whitespaces: ' + path)

sys.exit(0)

0 comments on commit f85e011

Please sign in to comment.