docstring-format-checker 0.3.0__tar.gz → 0.4.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: docstring-format-checker
3
- Version: 0.3.0
3
+ Version: 0.4.0
4
4
  Summary: A CLI tool to check and validate Python docstring formatting and completeness
5
5
  Author: Chris Mahoney
6
6
  Author-email: Chris Mahoney <docstring-format-checker@data-science-extensions.com>
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "docstring-format-checker"
3
- version = "v0.3.0"
3
+ version = "v0.4.0"
4
4
  description = "A CLI tool to check and validate Python docstring formatting and completeness"
5
5
  readme = "README.md"
6
6
  license = "MIT"
@@ -4,7 +4,7 @@ Docstring Format Checker.
4
4
  A CLI tool to check and validate Python docstring formatting and completeness.
5
5
  """
6
6
 
7
- __version__ = "v0.3.0"
7
+ __version__ = "v0.4.0"
8
8
  __author__ = "Chris Mahoney"
9
9
  __email__ = "docstring-format-checker@data-science-extensions.com"
10
10
 
@@ -302,6 +302,29 @@ def _show_check_examples_callback(ctx: Context, param: CallbackParam, value: boo
302
302
  raise Exit()
303
303
 
304
304
 
305
+ def _format_error_messages(error_message: str) -> str:
306
+ """
307
+ !!! note "Summary"
308
+ Format error messages for better readability in CLI output.
309
+
310
+ Params:
311
+ error_message (str):
312
+ The raw error message that may contain semicolon-separated errors
313
+
314
+ Returns:
315
+ (str):
316
+ Formatted error message with each error prefixed with "- " and separated by ";\n"
317
+ """
318
+ if "; " in error_message:
319
+ # Split by semicolon and rejoin with proper formatting
320
+ errors: list[str] = error_message.split("; ")
321
+ formatted_errors: list[str] = [f"- {error.strip()}" for error in errors if error.strip()]
322
+ return ";\n".join(formatted_errors) + "."
323
+ else:
324
+ # Single error message
325
+ return f"- {error_message.strip()}."
326
+
327
+
305
328
  def _display_results(results: dict[str, list[DocstringError]], quiet: bool, verbose: bool) -> int:
306
329
  """
307
330
  !!! note "Summary"
@@ -340,12 +363,16 @@ def _display_results(results: dict[str, list[DocstringError]], quiet: bool, verb
340
363
  for file_path, errors in results.items():
341
364
  for i, error in enumerate(errors):
342
365
  file_display: str = file_path if i == 0 else ""
366
+
367
+ # Format error message with improved formatting
368
+ formatted_error_message: str = _format_error_messages(error.message)
369
+
343
370
  table.add_row(
344
371
  file_display,
345
372
  str(error.line_number) if error.line_number > 0 else "",
346
373
  error.item_name,
347
374
  error.item_type,
348
- error.message,
375
+ formatted_error_message,
349
376
  )
350
377
  console.print(table)
351
378
 
@@ -354,12 +381,15 @@ def _display_results(results: dict[str, list[DocstringError]], quiet: bool, verb
354
381
  for file_path, errors in results.items():
355
382
  console.print(f"{NEW_LINE}[cyan]{file_path}[/cyan]")
356
383
  for error in errors:
384
+ # Format error message with improved formatting
385
+ formatted_error_message: str = _format_error_messages(error.message)
386
+
357
387
  if error.line_number > 0:
358
388
  console.print(
359
- f" [red]Line {error.line_number}[/red] - {error.item_type} '{error.item_name}': {error.message}"
389
+ f" [red]Line {error.line_number}[/red] - {error.item_type} '{error.item_name}': {formatted_error_message}"
360
390
  )
361
391
  else:
362
- console.print(f" [red]Error[/red]: {error.message}")
392
+ console.print(f" [red]Error[/red]: {formatted_error_message}")
363
393
 
364
394
  # Summary
365
395
  console.print(f"{NEW_LINE}[red]Found {total_errors} error(s) in {total_files} file(s)[/red]")
@@ -860,7 +860,7 @@ class DocstringChecker:
860
860
  if has_colon:
861
861
  errors.append(
862
862
  f"Section '{section_title_clean}' is an admonition, therefore it should not end with ':', "
863
- f"see: {match.group(0)}"
863
+ f"see: '{match.group(0)}'"
864
864
  )
865
865
 
866
866
  # Check non-admonition sections (should end with colon)
@@ -878,7 +878,7 @@ class DocstringChecker:
878
878
  if not has_colon:
879
879
  errors.append(
880
880
  f"Section '{section_name}' is non-admonition, therefore it must end with ':', "
881
- f"see: {line}"
881
+ f"see: '{line}'"
882
882
  )
883
883
 
884
884
  return errors
@@ -976,8 +976,8 @@ class DocstringChecker:
976
976
  # Pattern: name (type): or (type):
977
977
  if not re.search(r"\([^)]+\):", stripped_line):
978
978
  errors.append(
979
- f"Section '{current_section.name}' (type: {current_section.type}) requires "
980
- f"parenthesized types, missing in: '{stripped_line}'"
979
+ f"Section '{current_section.name}' (type: '{current_section.type}') requires "
980
+ f"parenthesized types, see: '{stripped_line}'"
981
981
  )
982
982
 
983
983
  # For list_type sections, check format like "(Type):"
@@ -985,8 +985,8 @@ class DocstringChecker:
985
985
  # Pattern: (Type):
986
986
  if not re.search(r"^\s*\([^)]+\):", stripped_line):
987
987
  errors.append(
988
- f"Section '{current_section.name}' (type: {current_section.type}) requires "
989
- f"parenthesized types, missing in: '{stripped_line}'"
988
+ f"Section '{current_section.name}' (type: '{current_section.type}') requires "
989
+ f"parenthesized types, see: '{stripped_line}'"
990
990
  )
991
991
 
992
992
  return errors