fix: wrong activeDocument.createEl() calls#174
Conversation
There was a problem hiding this comment.
Pull request overview
This PR updates the prefer-create-el ESLint rule to avoid generating broken Obsidian DOM-helper calls (notably around activeDocument) and expands handling to cover Document-typed variables, with accompanying test coverage.
Changes:
- Update the rule to classify “Document-like” targets and rewrite
activeDocument.*calls toactiveWindow.*. - Add new invalid/valid test cases to ensure non-Document lookalikes aren’t flagged and to cover Document-typed variable rewrites (
doc.win.*). - Refactor replacement generation to use a shared target classifier (prefix + autofix capability).
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 5 comments.
| File | Description |
|---|---|
| tests/preferCreateEl.test.ts | Adds coverage for non-Document objects and Document-typed variable rewrites; updates expected outputs for activeDocument to use activeWindow. |
| lib/rules/preferCreateEl.ts | Introduces target classification (activeDocument → activeWindow, Document-typed objects → .win.*) and applies it across createElement/createElementNS/createDocumentFragment checks. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
Considering that we have decided that we're moving |
|
Yes, I think all the cases are reasonable here. Do you see any unit tests that you think are unreasonable? |
I ask, because you don't just seem to just update This implies you're addressing something beyond the This is fine if there are additional issues in this rule that you're addressing in this changeset. My question is precisely whether that is the case, because if that is not the case, the changeset is touching more than it claims to fix. However, if you identified additional issues and addressed them in this changeset, then the changes are understandable. Additional meaningful unit test cases are fine regardless. |
|
Current version turns valid Once the referenced obsidian API bug is fixed, this PR becomes redundant |
I assume even if they address the bug today, there is going to be a significant timeframe until adoption. I'll run some verifications and create a new release after this has been merged. Thanks for the PR. |
see https://forum.obsidian.md/t/bug-document-createel-is-broken/115762