You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
linter pass that checks nursery rule namespaces against existing directory structure #3112
not sure if this should fail the check or not, since a misspelling is bad, but a brand-new namespace is ok. not sure how we can tell this apart, aside from edit distance or something.
Hi @williballenthin, maybe I can help in this issue. Please find below, the proposed design and solution for this issue.
Design Overview
Problem faced
The existing ‘NamespaceDoesntMatchRulePath’ lint ([lint.py#L131-L146] explicitly skips nursery rules (‘if is_nursery_rule(rule): return False’). This means that nursery rules with typos or invalid namespaces (like 'host-interation' instead of 'host-interaction' in previous issue) go undetected.
Proposed Solution
Add a new lint class NurseryNamespaceDoesntExist in scripts/lint.py that only applies to nursery rules and validates that their namespace value corresponds to an existing directory path within the non-nursery rules directory structure.
I am thinking to use edit distance (will use Python's ‘difflib.get_close_matches’) to differentiate these two cases:
• If the namespace is close to an existing one, then WARN as a likely typo, and suggest closest match
• If the namespace is far from all existing ones, then it’s likely intentional, don't flag it
This means the lint would only warn when there's a probable typo, not when someone introduces a genuinely new namespace.
how working goes: -
collecting valid namespaces – when lint starts, walk the rules directory and collect paths as valid namespaces, normalized as ‘/’-separated paths(relative to roots)
check each segment - For each nursery rule with a namespace, split it by / and compare each segment against the corresponding level of existing directory names.
match with threshold - Use ‘difflib.get_close_matches’ function, where a 0.8 cutoff means we only flag strings that are very similar(like typos), if different then new namespaces.
File to be working on: -
‘scripts/lint.py’: Add ‘NurseryNamespaceTypo’ lint class and update ‘Context’ dataclass.
My initial idea is to add a dedicated linter pass for nursery rules that validates their namespaces against the existing rule directory structure. Rather than failing immediately, I'd treat likely typos (based on similarity to existing namespaces) as warnings while allowing genuinely new namespaces to pass. This should help catch common mistakes without blocking intentional additions.
If this approach aligns with your expectations, I'll proceed with the implementation and open a PR referencing this issue.
I'd like to take this on. I'll add a linter pass that validates nursery rule namespaces against the actual directory structure in capa-rules. The approach will be to extend the existing linter framework, add a check that compares each nursery rule's namespace prefix with its file path, and include test fixtures covering both valid and invalid cases (such as a nursery rule incorrectly claiming a top-level namespace). I'll make sure the implementation follows the patterns already established in the codebase and that CI passes cleanly.
Activity
williballenthin commentedon Jun 19, 2026
not sure if this should fail the check or not, since a misspelling is bad, but a brand-new namespace is ok. not sure how we can tell this apart, aside from edit distance or something.
MannXo commentedon Jun 19, 2026
I'll work on this one , can I get assigned?
williballenthin commentedon Jun 19, 2026
@MannXo please provide an overview of your idea/design so we can agree on the strategy.
then when approved, feel free to open a PR referencing this issue.
jatinkumar300403 commentedon Jun 20, 2026
Hi @williballenthin, maybe I can help in this issue. Please find below, the proposed design and solution for this issue.
Design Overview
Problem faced
The existing ‘NamespaceDoesntMatchRulePath’ lint ([lint.py#L131-L146] explicitly skips nursery rules (‘if is_nursery_rule(rule): return False’). This means that nursery rules with typos or invalid namespaces (like 'host-interation' instead of 'host-interaction' in previous issue) go undetected.
Proposed Solution
Add a new lint class NurseryNamespaceDoesntExist in scripts/lint.py that only applies to nursery rules and validates that their namespace value corresponds to an existing directory path within the non-nursery rules directory structure.
I am thinking to use edit distance (will use Python's ‘difflib.get_close_matches’) to differentiate these two cases:
• If the namespace is close to an existing one, then WARN as a likely typo, and suggest closest match
• If the namespace is far from all existing ones, then it’s likely intentional, don't flag it
This means the lint would only warn when there's a probable typo, not when someone introduces a genuinely new namespace.
how working goes: -
File to be working on: -
Would be happy to hear back from you on this!
abhinav-phi commentedon Jul 15, 2026
Hi @williballenthin, I'd like to work on this issue.
My initial idea is to add a dedicated linter pass for nursery rules that validates their namespaces against the existing rule directory structure. Rather than failing immediately, I'd treat likely typos (based on similarity to existing namespaces) as warnings while allowing genuinely new namespaces to pass. This should help catch common mistakes without blocking intentional additions.
If this approach aligns with your expectations, I'll proceed with the implementation and open a PR referencing this issue.
asucodes commentedon Oct 25, 2026
I'd like to take this on. I'll add a linter pass that validates nursery rule namespaces against the actual directory structure in capa-rules. The approach will be to extend the existing linter framework, add a check that compares each nursery rule's namespace prefix with its file path, and include test fixtures covering both valid and invalid cases (such as a nursery rule incorrectly claiming a top-level namespace). I'll make sure the implementation follows the patterns already established in the codebase and that CI passes cleanly.