Skip to content

Commit ac79ef0

Browse files
committed
refactor(markdown_lint): extract repeated message into constant
Extract the frequently used message about fenced code block spacing into a class constant to improve maintainability and reduce duplication. This makes the code more DRY by referencing the constant in three locations instead of repeating the string.
1 parent c842bfb commit ac79ef0

1 file changed

Lines changed: 6 additions & 3 deletions

File tree

tools/markdown_lint/linter.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,9 @@ class MarkdownLinter:
4444
r"(?<![<\[\(])([a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,})(?![>\]\)])"
4545
)
4646
CLOSED_ATX_HEADING_PATTERN = re.compile(r"^#{1,6}\s+[^\s]{1,1000}(?:\s+[^\s]+)*\s+#{1,6}\s*$")
47+
48+
# Constants for repeated messages
49+
MSG_FENCED_CODE_BLOCKS_SPACING = "Fenced code blocks should be surrounded by blank lines"
4750

4851
def __init__(self, config: Optional[dict] = None):
4952
"""Initialize the linter with the given configuration."""
@@ -434,7 +437,7 @@ def _check_fenced_code_block_start(
434437
self._add_issue(
435438
report,
436439
line_num,
437-
"Fenced code blocks should be surrounded by blank lines",
440+
self.MSG_FENCED_CODE_BLOCKS_SPACING,
438441
"MD031",
439442
severity=IssueSeverity.WARNING,
440443
fix=lambda content: content, # Handled by _apply_spacing_fixes
@@ -469,7 +472,7 @@ def _check_fenced_code_block_end(
469472
self._add_issue(
470473
report,
471474
line_num + 1,
472-
"Fenced code blocks should be surrounded by blank lines",
475+
self.MSG_FENCED_CODE_BLOCKS_SPACING,
473476
"MD031",
474477
severity=IssueSeverity.WARNING,
475478
fix=lambda content: content, # Handled by _apply_spacing_fixes
@@ -747,7 +750,7 @@ def _apply_spacing_fixes(self, lines: List[str], spacing_issues: List[LintIssue]
747750
insertions.append((line_idx, "before")) # Insert before the non-list line
748751

749752
elif issue.code == "MD031": # Fenced code block spacing
750-
if "Fenced code blocks should be surrounded by blank lines" in issue.message:
753+
if self.MSG_FENCED_CODE_BLOCKS_SPACING in issue.message:
751754
# Check if this is a start or end of code block
752755
if line_idx < len(lines) and lines[line_idx].strip().startswith("```"):
753756
# Check if previous line needs spacing (start of code block)

0 commit comments

Comments
 (0)