Codebase intelligence for AI and humans: code health scores, auto-generated docs, git analytics, dead code detection, and architectural decisions via MCP.
Python aicode-complexitycode-healthcode-intelligencecode-qualitydead-codedeveloper-toolsdocumentationgit-analyticsmcpopen-sourcepythonrefactoringstatic-analysistechnical-debt
fix(cobol): skip compiler-option cards that start in column 1 (#4491)
zgyb9de01c50bc0
diff --git a/packages/core/src/repowise/core/ingestion/cobol/reference_format.py b/packages/core/src/repowise/core/ingestion/cobol/reference_format.pyindex ca4dffcb8..390c4b974 100644--- a/packages/core/src/repowise/core/ingestion/cobol/reference_format.py+++ b/packages/core/src/repowise/core/ingestion/cobol/reference_format.py@@ -13,6 +13,9 @@ _TEXT_START, _TEXT_END = 7, 72_COMMENT_INDICATORS = frozenset("*/$Dd")# Compiler options before IDENTIFICATION DIVISION (``PROCESS SQL``, ``CBL ...``)._COMPILER_DIRECTIVE = re.compile(r"\s*(PROCESS|CBL)\b", re.IGNORECASE)+# The same when the card starts in column 1: the keyword must end at whitespace+# or the end of the line, so a data name such as ``CBL-REC`` stays a data name.+_COMPILER_DIRECTIVE_COLUMN_1 = re.compile(r"\s*(PROCESS|CBL)(?=\s|$)", re.IGNORECASE)_FREE_FORMAT = re.compile(r">>\s*SOURCE\s+(FORMAT\s+(IS\s+)?)?FREE|SOURCEFORMAT\W+FREE", re.I)@@ -38,7 +41,11 @@ def normalize_fixed_format(text: str) -> str:if indicator in _COMMENT_INDICATORS or not body.strip():out.append(eol)continue- if not seen_division and _COMPILER_DIRECTIVE.match(body):+ if not seen_division and (+ _COMPILER_DIRECTIVE.match(body) or _COMPILER_DIRECTIVE_COLUMN_1.match(line)+ ):+ # A compiler-option card may also start in column 1, where its text+ # is outside the 8-72 program area (#4475).out.append(eol)continueseen_division = Truediff --git a/tests/unit/ingestion/parser/test_cobol_reference_format.py b/tests/unit/ingestion/parser/test_cobol_reference_format.pynew file mode 100644index 000000000..9219fd73f--- /dev/null+++ b/tests/unit/ingestion/parser/test_cobol_reference_format.py@@ -0,0 +1,37 @@+"""Fixed-format masking: compiler-option cards starting in column 1 are skipped (#4475)."""++from repowise.core.ingestion.cobol.reference_format import normalize_fixed_format++PROGRAM = """CBL APOST+ IDENTIFICATION DIVISION.+ PROGRAM-ID. DEMO.+ PROCEDURE DIVISION.+ STOP RUN.+"""+++def test_a_column_one_compiler_directive_is_blanked():+ result = normalize_fixed_format(PROGRAM)++ lines = result.split("\n")+ assert lines[0] == ""+ assert "CBL" not in result+ assert "IDENTIFICATION DIVISION." in lines[1]+ assert len(lines) == len(PROGRAM.split("\n"))+++def test_a_column_one_process_directive_is_blanked():+ result = normalize_fixed_format("PROCESS SQL\n IDENTIFICATION DIVISION.\n")++ assert "PROCESS" not in result+ assert "IDENTIFICATION DIVISION." in result+++def test_a_column_one_data_name_that_starts_like_a_directive_is_kept():+ """A copybook's first code line can be a data name such as CBL-REC."""+ source = "CBL-REC PIC X(8).\n"+ result = normalize_fixed_format(source)++ # Columns 1-7 are the sequence area and are blanked, but the entry stays.+ assert "PIC X(8)." in result+ assert result.strip() != ""