Legacy code, tabs vs spaces, neverending story
2017-06-19 22:51:40
import os
def generate_report(start_path, file_extension_to_examine):
list_of_files_to_examine = []
for root, subdirs, files in os.walk(start_path):
for file in files:
if file.endswith(file_extension_to_examine):
list_of_files_to_examine.append(root + "\\" + file)
total_number_of_files = len(list_of_files_to_examine)
tabs_counter = 0
space_counter = 0
for file in list_of_files_to_examine:
with open(file) as open_file:
for line in open_file:
if line.startswith("\t") and line != "":
tabs_counter += 1
elif line.startswith(" ") and line != "":
space_counter += 1
p_tabs = round((100 * tabs_counter) / (tabs_counter + space_counter), 1)
p_space = round((100 * space_counter) / (tabs_counter + space_counter), 1)
print("----------------------------------------------------")
print("Number of files: " + str(total_number_of_files))
print("Number of line started with tab: " + str(tabs_counter) + " = " + str(p_tabs) + "%")
print("Number of line started with space: " + str(space_counter) + " = " + str(p_space) + "%")
generate_report(r"../app/js", ".ts")
generate_report(r"../main/java", ".java")