Skip to content

fix(codelensignore): honor !-negation patterns for files in ignored directories — closes #120#126

Merged
Wolfvin merged 1 commit into
mainfrom
fix/redteam-120-codelensignore-negation
Jul 1, 2026
Merged

fix(codelensignore): honor !-negation patterns for files in ignored directories — closes #120#126
Wolfvin merged 1 commit into
mainfrom
fix/redteam-120-codelensignore-negation

Conversation

@Wolfvin

@Wolfvin Wolfvin commented Jul 1, 2026

Copy link
Copy Markdown
Owner

What

Fixes RED TEAM issue #120: .codelensignore negation pattern (!) was silently ignored — files that should be re-included via !pattern were not appearing in scan results.

Root cause

When a directory matched a .codelensignore pattern (e.g. src/), scan.py called dirs.clear() to prune the entire subtree. This meant !-negation patterns targeting files inside the ignored directory (e.g. !src/utils.py) were never evaluated — the files were already skipped at the directory level before per-file is_ignored() checks ran.

Fix

When a directory matches a .codelensignore pattern, check whether any pattern in the merged 3-tier list starts with !. If so, keep recursing so per-file is_ignored() checks can honor the negation. If there are no negation patterns, prune as before (preserves the node_modules/ performance optimization).

if _codelensignore_is_ignored is not None and _codelensignore_is_ignored(rel_root, workspace):
    _has_negation = False
    try:
        from codelensignore import load_patterns
        _pats = load_patterns(workspace)
        _has_negation = any(p.startswith('!') for p in _pats)
    except Exception:
        _has_negation = True  # Safe default: keep recursing
    if not _has_negation:
        dirs.clear()
        continue
    # Else: fall through and let per-file checks filter

Verification

Reproduced the bug from #120 and verified the fix:

# Before fix:
$ echo -e 'src/\n!src/utils.py' > .codelensignore
$ codelens scan . | grep python
    "python": 2,  # BUG — src/utils.py missing

# After fix:
$ codelens scan . | grep python
    "python": 3,  # config/settings.py + main.py + src/utils.py ✓

Per-file is_ignored() correctly returns False for src/utils.py (negation honored).

Test plan

Risk

Low. The performance optimization (pruning node_modules/ subtrees) is preserved when there are no negation patterns. Only workspaces that use !-negation will recurse into ignored directories, and that's the correct behavior — the user explicitly asked to re-include specific files.

…irectories — closes #120

Bug: when a directory matched a .codelensignore pattern (e.g. 'src/'),
scan.py called dirs.clear() to prune the entire subtree. This meant
!-negation patterns targeting files inside the ignored directory
(e.g. '!src/utils.py') were never evaluated — the files were already
skipped at the directory level.

Fix: when a directory matches a .codelensignore pattern, check whether
any pattern in the merged 3-tier list starts with '!'. If so, keep
recursing so per-file is_ignored() checks can honor the negation.
If there are no negation patterns, prune as before (preserves the
node_modules/ performance optimization).

Verified: scan on clean_app with 'src/' + '!src/utils.py' now reports
python: 3 (config/settings.py + main.py + src/utils.py) instead of 2.
Per-file is_ignored() correctly returns False for src/utils.py.
@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

@sonarqubecloud

sonarqubecloud Bot commented Jul 1, 2026

Copy link
Copy Markdown

@Wolfvin Wolfvin merged commit ecb8dae into main Jul 1, 2026
5 of 11 checks passed
@Wolfvin Wolfvin deleted the fix/redteam-120-codelensignore-negation branch July 1, 2026 04:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant