fix: false positive on document - #187
Open
saberzero1 wants to merge 1 commit into
Open
saberzero1 wants to merge 1 commit into
saberzero1 wants to merge 1 commit into
Conversation
There was a problem hiding this comment.
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-docto ignoredocumentidentifiers 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-docaswarninrecommended/recommendedWithLocalesEnand 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
TSModuleDeclarationis treated as a type-only context inisInTypeContext, which will also skip warnings inside non-declarenamespaces (e.g.namespace Foo { document.title }) even though those are runtime code and should still be flagged. Gate this case ondeclare === 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 | ||
| ) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
closes #162
closes #150