@@ -19,14 +19,24 @@ def __init__(self):
1919 self .sections_with_non_existing_paths = []
2020 self .non_existing_paths = {}
2121 self .duplicated_sections = []
22+ self .lines_with_trailing_whitespace = []
2223
2324
24- def check (codeowners_data ):
25+ def check (codeowners_data , file_path ):
2526 violations = CodeownersViolations ()
2627
2728 if _is_codeowners_empty (codeowners_data ):
2829 return violations
2930
31+ # Are there trailing whitespaces
32+ violations .lines_with_trailing_whitespace = _get_lines_with_trailing_whitespace (
33+ file_path ,
34+ )
35+ if violations .lines_with_trailing_whitespace :
36+ violations .violation_error_messages .append (
37+ f'Lines with trailing whitespace: { violations .lines_with_trailing_whitespace } ' ,
38+ )
39+
3040 # Are custom section names sorted?
3141 sort_sections_names_key = cmp_to_key (sort_section_names )
3242 if codeowners_data [1 :] != sorted (codeowners_data [1 :], key = sort_sections_names_key ):
@@ -82,6 +92,15 @@ def _is_codeowners_empty(codeowners_data):
8292 return empty
8393
8494
95+ def _get_lines_with_trailing_whitespace (file_path ):
96+ lines_with_trailing_whitespace = []
97+ with open (file_path ) as f :
98+ for i , line in enumerate (f , 1 ):
99+ if line .endswith (' \n ' ) or line .endswith ('\t \n ' ):
100+ lines_with_trailing_whitespace .append (i )
101+ return lines_with_trailing_whitespace
102+
103+
85104def _get_duplicated_sections (codeowners_data ):
86105 all_sections_name = list (
87106 section .codeowner_section for section in codeowners_data )
0 commit comments