MCPcopy Create free account
hub / github.com/OWASP/APTS / validate_markdown_tables

Function validate_markdown_tables

scripts/validate_markdown_tables.py:100–153  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

98
99
100def validate_markdown_tables() -> int:
101 markdown_files = git_ls_files("*.md")
102
103 if not markdown_files:
104 print("No Markdown files found. Skipping Markdown table validation.")
105 return 0
106
107 failed = False
108
109 for path in markdown_files:
110 display_name = display_path(path)
111
112 lines = masked_fenced_lines(read_text(path))
113 index = 0
114
115 while index < len(lines) - 1:
116 header_line_number, header_line = lines[index]
117 separator_line_number, separator_line = lines[index + 1]
118 parsed_header = parse_table_row(header_line)
119
120 if not is_header_candidate(header_line, parsed_header):
121 index += 1
122 continue
123
124 parsed_separator = parse_table_row(separator_line)
125 if not is_separator_row(parsed_separator):
126 index += 1
127 continue
128
129 expected_columns = len(parsed_header.cells)
130
131 if len(parsed_separator.cells) != expected_columns:
132 print(
133 f"FAILED: {display_name}:{separator_line_number}: "
134 "Markdown table separator column count does not match the header row."
135 )
136 failed = True
137
138 row_index = index + 2
139
140 while row_index < len(lines):
141 row_line_number, row = lines[row_index]
142 if not row.strip():
143 break
144
145 parsed_row = parse_table_row(row)
146 if not is_body_candidate(row, parsed_row, expected_columns):
147 break
148
149 row_index += 1
150
151 index = row_index
152
153 return 1 if failed else 0
154
155
156if __name__ == "__main__":

Callers 1

Calls 8

git_ls_filesFunction · 0.90
display_pathFunction · 0.90
masked_fenced_linesFunction · 0.90
read_textFunction · 0.90
parse_table_rowFunction · 0.85
is_header_candidateFunction · 0.85
is_separator_rowFunction · 0.85
is_body_candidateFunction · 0.85

Tested by

no test coverage detected