Skip to content

fix(analyzer): C-style inline block comments cause infinite comment counting, and python async functions are missed #25

Description

@CodeMaverick-143

Problem Description

  1. C-Style Inline Comments (/* ... */):
    In insight/analyzer.py:

    elif "/*" in line:
        in_block_comment = True
        comment_count += 1
    elif "*/" in line:
        in_block_comment = False
        comment_count += 1
    elif in_block_comment:
        comment_count += 1

    If a single line contains an inline block comment such as int count = 0; /* inline */, the "/*" in line branch executes, setting in_block_comment = True. Because elif "*/" in line is an elif, the closing delimiter on that same line is never checked! in_block_comment remains True for the remainder of the file, causing all subsequent executable lines to be counted as comments.

  2. Async Functions Ignored:
    In analyzer.py:55-56:

    if isinstance(node, ast.FunctionDef):
        stats["functions"] += 1

    In Python, async def my_func() generates an ast.AsyncFunctionDef AST node. Modern asynchronous functions are completely ignored.

  3. Relative Imports Returning None:
    In analyzer.py:61-62:

    elif isinstance(node, ast.ImportFrom):
        stats["imports"].append(node.module)

    For relative imports like from . import utils, node.module is None. Appending None to stats["imports"] can cause unexpected TypeError or render literal None in reports.

Affected Files

  • insight/analyzer.py:38-66

Proposed Solution

  1. Check for single-line block comments ("/*" in line and "*/" in line) before toggling block state.
  2. Check for ast.AsyncFunctionDef:
    if isinstance(node, (ast.FunctionDef, ast.AsyncFunctionDef)):
        stats["functions"] += 1
  3. Handle relative imports when node.module is None (e.g. use f".{node.names[0].name}" or ".").

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workinggood first issueGood for newcomers

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions