@@ -8,6 +8,7 @@ def load_excluded_words(file_path):
88
99def scan_for_profanities (directory , log_file , excluded_words_file = None ):
1010 exclude_words = None
11+ profanities = None
1112 if excluded_words_file :
1213 exclude_words = load_excluded_words (excluded_words_file )
1314
@@ -17,23 +18,21 @@ def scan_for_profanities(directory, log_file, excluded_words_file=None):
1718 if file .endswith ('.md' ): # Read only markdown files
1819 file_path = os .path .join (root , file )
1920 with open (file_path , 'r' ) as code_file :
21+ profanities = None
2022 content = code_file .read ()
2123 if exclude_words :
2224 excluded_content = content
2325 for word in exclude_words :
2426 excluded_content = excluded_content .replace (word , '' )
2527 if profanity .contains_profanity (excluded_content ):
26- f .write (f"Profanity found in file: { file_path } \n " )
27- f .write ("Profanities found: " )
2828 profanities = set (word for word in excluded_content .split () if profanity .contains_profanity (word ))
29- f .write (", " .join (profanities ))
30- f .write ("\n \n " )
3129 else :
3230 if profanity .contains_profanity (content ):
33- f .write (f"Profanity found in file: { file_path } \n " )
34- f .write ("Profanities found: " )
3531 profanities = set (word for word in content .split () if profanity .contains_profanity (word ))
36- f .write (", " .join (profanities ))
37- f .write ("\n \n " )
32+ if profanities :
33+ f .write (f"Profanity found in file: { file_path } \n " )
34+ f .write ("Profanities found: " )
35+ f .write (", " .join (profanities ))
36+ f .write ("\n \n " )
3837
39- scan_for_profanities ("./content/" , "./profanity_log.txt" , excluded_words_file = "./.profanity_ignore.yml" )
38+ scan_for_profanities ("./content/" , "./profanity_log.txt" , excluded_words_file = "./.profanity_ignore.yml" )
0 commit comments