Skip to content

fix: false positive on document - #187

Open
saberzero1 wants to merge 1 commit into
masterfrom
fix/prefer-active-doc-false-positives
Open

saberzero1 wants to merge 1 commit into
masterfrom
fix/prefer-active-doc-false-positives

Conversation

@saberzero1

Copy link
Copy Markdown
Collaborator

closes #162
closes #150

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR updates the obsidianmd/prefer-active-doc ESLint rule to reduce false positives around non-global document identifiers (especially in TypeScript type positions) and promotes the rule to warn in the recommended configs, with corresponding documentation updates.

Changes:

  • Refine prefer-active-doc to ignore document identifiers that appear in TypeScript type-level constructs and other non-global contexts (e.g., labels, enum member names).
  • Add regression tests covering previously-reported false positives and ensure certain runtime expressions are still flagged.
  • Enable obsidianmd/prefer-active-doc as warn in recommended / recommendedWithLocalesEn and update docs/README accordingly.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
lib/rules/preferActiveDoc.ts Adds extra AST-context skipping logic to avoid false positives for document in type and declaration-like positions.
tests/preferActiveDoc.test.ts Adds new valid/invalid cases to cover the reported false positives and ensure runtime usages remain reported.
lib/index.ts Switches obsidianmd/prefer-active-doc from off to warn in the recommended config base.
docs/rules/prefer-active-doc.md Updates the rule header to reflect the rule now warning in recommended configs.
README.md Updates the auto-generated rules table/legend to reflect current config status (including prefer-active-doc warning).
Suppressed comments (1)

lib/rules/preferActiveDoc.ts:167

  • TSModuleDeclaration is treated as a type-only context in isInTypeContext, which will also skip warnings inside non-declare namespaces (e.g. namespace Foo { document.title }) even though those are runtime code and should still be flagged. Gate this case on declare === true (ambient modules/namespaces) so runtime namespaces don’t silence the rule.
                    case TSESTree.AST_NODE_TYPES.TSModuleDeclaration:
                        return true;

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment on lines +79 to +83
if (
(node.parent.type === TSESTree.AST_NODE_TYPES.PropertyDefinition ||
node.parent.type === TSESTree.AST_NODE_TYPES.MethodDefinition) &&
node.parent.key === node
) {
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.

false positive Mathjax.document warning False positive for API definition in web worker

2 participants