Description
The prefer-instanceof rule's autofix produces broken code that fails at runtime. When --fix is run on TypeScript files, the rule transforms valid instanceof operator checks into invalid .instanceOf() method calls, which don't exist in standard JavaScript/TypeScript.
Steps to Reproduce
-
Create a TypeScript file with a standard instanceof check:
if (target instanceof HTMLElement) {
console.log("target is an HTMLElement");
}
-
Run eslint --fix on this file with eslint-plugin-obsidianmd enabled and prefer-instanceof rule enabled for TypeScript files
-
The code is transformed to:
if (target.instanceOf HTMLElement) { // ❌ INVALID - .instanceOf is not a method
console.log("target is an HTMLElement");
}
Expected Behavior
- Either the autofix should be removed/disabled
- Or the autofix should provide a valid alternative (e.g., a custom helper function)
- The rule should not produce code that throws runtime errors like
TypeError: ...instanceOf is not a function
Actual Behavior
The autofix corrupts valid code by replacing the standard instanceof operator with a nonexistent .instanceOf() method call. This breaks type checking and causes runtime failures in any code path that executes the check.
Environment
eslint-plugin-obsidianmd: ^0.3.0
- eslint: ^9.27.0
- TypeScript: 5.9.3
Impact
Projects using this plugin with --fix enabled will have their instanceof checks corrupted, leading to:
- Runtime
TypeError: X is not a function errors
- Broken type guards that fail silently or crash
- Breaking changes on auto-fix runs that require manual cleanup
Additional Context
The issue appears to stem from the rule being intended for linting only, not for autofixing. The transformation doesn't map to any valid JavaScript/TypeScript API.
Workaround
Until this is fixed, the rule should be disabled in eslint config:
{
files: ["**/*.{ts,tsx}"],
rules: {
"obsidianmd/prefer-instanceof": "off",
},
}
Description
The
prefer-instanceofrule's autofix produces broken code that fails at runtime. When--fixis run on TypeScript files, the rule transforms validinstanceofoperator checks into invalid.instanceOf()method calls, which don't exist in standard JavaScript/TypeScript.Steps to Reproduce
Create a TypeScript file with a standard
instanceofcheck:Run
eslint --fixon this file witheslint-plugin-obsidianmdenabled andprefer-instanceofrule enabled for TypeScript filesThe code is transformed to:
Expected Behavior
TypeError: ...instanceOf is not a functionActual Behavior
The autofix corrupts valid code by replacing the standard
instanceofoperator with a nonexistent.instanceOf()method call. This breaks type checking and causes runtime failures in any code path that executes the check.Environment
eslint-plugin-obsidianmd: ^0.3.0Impact
Projects using this plugin with
--fixenabled will have theirinstanceofchecks corrupted, leading to:TypeError: X is not a functionerrorsAdditional Context
The issue appears to stem from the rule being intended for linting only, not for autofixing. The transformation doesn't map to any valid JavaScript/TypeScript API.
Workaround
Until this is fixed, the rule should be disabled in eslint config: