# Setting Up ESLint for Obsidian Community Plugin Submission The Obsidian community plugin review runs an automated scan that checks your code against a specific set of lint rules. If your local ESLint setup doesn't match what the scanner checks, you'll submit with a clean local lint and get back a wall of violations. This guide covers the complete setup so your local `npx eslint .` catches exactly what the community scanner catches. ## What the Community Scanner Actually Checks The scanner runs `eslint-plugin-obsidianmd`'s recommended config, which bundles the `typescript-eslint` recommended type-checked rules itself (plus `import`, `@microsoft/sdl`, `depend`, `no-unsanitized`, and `eslint-comments`). `...obsidianmd.configs.recommended` alone gives you the same ruleset the scanner uses. Full scanner behavior (rule sets, checks beyond ESLint, Scorecard mechanics) is documented in [community-scanner.md](community-scanner.md). ## Prerequisites ### For New Projects ```bash npm install -D eslint typescript typescript-eslint obsidian eslint-plugin-obsidianmd ``` - **`obsidian` must be installed in your project.** v0.5.0 reads Obsidian's own type definitions and no longer installs `obsidian` for you. Without it, `no-unsupported-api` silently reports nothing. Sample-plugin projects already have it. - `@eslint/js` and `@eslint/json` are **not** needed unless your own config imports them. If it does, `@eslint/json` must be 2.x (see [Upgrading from v0.4.x](#upgrading-from-v04x)). - You don't need `@typescript-eslint/parser` separately — `typescript-eslint` provides the parser. ### Migrating Existing Projects (IMPORTANT) If your project has old ESLint packages (common in plugins created before 2024), you must clean up before installing. #### Quick Migration (One Command) If you have TypeScript 4.x, this single command upgrades everything at once: ```bash npm uninstall @typescript-eslint/eslint-plugin @typescript-eslint/parser eslint && \ npm install -D typescript@5 eslint@9 typescript-eslint obsidian eslint-plugin-obsidianmd ``` Then remove old config files: ```bash rm -f .eslintrc .eslintrc.js .eslintrc.json .eslintrc.yml .eslintrc.yaml ``` #### Step-by-Step Migration If the quick command fails or you prefer more control: **1. Check your current setup:** ```bash grep -E "@typescript-eslint|eslint|typescript" package.json ``` **2. Remove ALL old eslint packages first:** ```bash npm uninstall @typescript-eslint/eslint-plugin @typescript-eslint/parser eslint # Or with pnpm: pnpm remove @typescript-eslint/eslint-plugin @typescript-eslint/parser eslint ``` **3. Install everything together (including TypeScript upgrade):** `typescript-eslint` v8.x requires **TypeScript >=4.8.4** and supports up to TypeScript 6. Include TypeScript in the install to avoid ERESOLVE errors: ```bash npm install -D typescript@5 eslint@9 typescript-eslint obsidian eslint-plugin-obsidianmd ``` > **Why include TypeScript?** If your project has TypeScript 4.7.x or older, npm will refuse to install `typescript-eslint` with `ERESOLVE unable to resolve dependency tree`. Installing TypeScript in the same command resolves this. **Do not install TypeScript 7** — it has no JavaScript API yet, so `typescript-eslint` cannot use it and npm fails with `ERESOLVE`. **4. Remove old config files:** ```bash rm -f .eslintrc .eslintrc.js .eslintrc.json .eslintrc.yml .eslintrc.yaml ``` **5. Verify old packages are gone:** ```bash grep "@typescript-eslint/eslint-plugin" package.json # Should return nothing. If it still shows, run: npm uninstall @typescript-eslint/eslint-plugin ``` #### Why Migration Fails The old `@typescript-eslint/eslint-plugin` and `@typescript-eslint/parser` (v5-7) conflict with the new unified `typescript-eslint` package (v8+). Common errors: - `ERESOLVE unable to resolve dependency tree` — TypeScript too old (or TypeScript 7), or old packages still installed - `TypeError: scopeManager.addGlobals is not a function` — version conflict between old and new packages - `Parsing error: Unexpected character 'e' found` — parser not loading due to version mismatch - `peer eslint@"^6.0.0 || ^7.0.0 || ^8.0.0"` warnings — old @typescript-eslint packages don't support ESLint 9+ ### Version Requirements Versions at time of writing: - `eslint-plugin-obsidianmd` 0.6.0 - **Node.js 20.19+, 22.13+, or 24+** (Node.js 18 is no longer supported — upgrade locally and in CI) - `eslint` 9.19+ (flat config). `defineConfig`/`globalIgnores` from `eslint/config` need 9.22+ - `typescript-eslint` 8.35.1+ (8.70.1+ recommended — fixes a `no-unnecessary-type-assertion` false positive on `{}` asserted to a `Record` alias) - `typescript` 4.8.4+, up to 6.x. **Not TypeScript 7.** - `obsidian` installed as a devDependency - A `minimatch` override in `package.json` until the toolchain ships `minimatch` 11 — see [`npm audit`: moderate vulnerabilities in `minimatch`](#npm-audit-moderate-vulnerabilities-in-minimatch-ghsa-g3hv-75wg-m249) Peer dependencies are `eslint >=9.19.0`, `typescript >=4.8.4`, and `typescript-eslint ^8.35.1`. Everything else the config needs — `@eslint/json`, `eslint-plugin-import`, `@microsoft/eslint-plugin-sdl`, `eslint-plugin-depend`, `eslint-plugin-no-unsanitized`, `eslint-comments` — ships as a dependency of the plugin, so you don't install those yourself. **ESLint 10** works, with caveats: npm prints `ERESOLVE overriding peer dependency` warnings (three bundled plugins don't declare ESLint 10 support yet), `npm ls` reports `invalid: eslint@10…`, and installs with `strict-peer-deps` fail. ESLint 10 also adds `no-unassigned-vars`, `no-useless-assignment`, and `preserve-caught-error` at `error`. `preserve-caught-error` suggests `new Error(msg, { cause })`, which needs `ES2022` in your tsconfig `lib`. ESLint 9 is the conservative choice. **TypeScript notes:** - `moduleResolution: "node"` shows a deprecation warning on 5.9+ and stops `tsc` on TypeScript 6 → use `"bundler"` for esbuild projects - `baseUrl` is deprecated (removed in TS 7.0) → remove if not using path aliases - TypeScript 6 defaults `types` to `[]`, so `eslint.config.mts` linted via `allowDefaultProject` has no Node types and `tsconfigRootDir: import.meta.dirname` is reported by `no-unsafe-assignment`. Add `"types": ["node"]` to `compilerOptions` ## Upgrading from v0.5.1 v0.6.0 fixes findings on correct code, and fixes and suggestions that changed what correct code does or did not compile, found by linting about 10,300 community plugins. The number of findings barely changes (about 0.2% fewer). The only config change you may need is for `acronyms`. | Change | What to do | |--------|------------| | `ui/sentence-case`, `ui/sentence-case-json`, `ui/sentence-case-locale-module`: `acronyms` **adds to** the built-in acronyms instead of replacing them | Drop built-in acronyms you listed again only to add one. If you used `acronyms` to leave some built-in ones out, add `replaceDefaultAcronyms: true` — see [ui-ux.md](ui-ux.md#enforce-sentence-case-for-ui-text) | | New rule `no-await-chainable` (`error`, TypeScript files, needs type information) | Remove `await` from a `Setting` or UI component chain, and don't `return` one from an `async` function — it never settles and the app hangs. See [ui-ux.md](ui-ux.md#dont-await-a-setting-or-ui-component) | | New rule `commands/check-callback-uses-checking` (`warn`) | Read `checking` in every `checkCallback`/`editorCheckCallback` and act only when it is `false`, or switch to `callback`/`editorCallback`. See [ui-ux.md](ui-ux.md#checkcallback-must-read-checking) | | `--fix` changes less: `prefer-window-timers` on an `activeWindow` timer whose ID is kept or cleared, `prefer-instanceof` on a value that may be null behind a type assertion, `prefer-create-el` on a call with comments in its arguments are now suggestions | After `eslint --fix`, resolve the remaining findings by hand or accept the editor suggestion — see [Fixes vs. suggestions](#fixes-vs-suggestions-v0x) | | `no-global-this`/`prefer-window-timers` give no fix or suggestion where TypeScript has narrowed `window` (e.g. the `else` of `if ("requestIdleCallback" in window)`) | Rewrite by hand; the old fix didn't compile (TS2339) | | `settings-tab/no-problematic-settings-headings` reports "General" or plugin-name headings only at the top of the tab | Delete disable comments on lower "General" headings — they are now unused | | `prefer-active-doc` offers `activeDocument.body` for an element put in `document.body` only for a moment (download link, copy textarea) | Accept the suggestion; it moves the element's `appendChild()` **and** `removeChild()`/`remove()` together | | `worker.ts` (any extension) is treated as web worker code, like `*.worker.ts` | Delete overrides you added for it | | Test files and tool configs get the Node globals; every `.cjs` file gets `module`/`exports` | Delete `globals.node` overrides and `no-undef` disables for `jest.config.js`, `release.config.cjs`, scripts | | `no-nodejs-modules` reports `require?.('fs')` (the bundle's `require` exists on mobile) and a `require()` in a `try` whose `catch` always rethrows | Use `window.require?.('fs')` or a `Platform.isDesktop` guard; handle the error in the `catch` instead of rethrowing | | `prefer-file-manager-trash-file` reports `vault.delete(file, force)` with a non-literal `force` | Use `this.app.fileManager.trashFile(file)` | New findings are rare: besides the two new rules, `no-unsupported-api` now reports `activeDocument || document` and `if (activeDocument)` below 0.15.0 (only `typeof activeDocument` checks a global that may not exist), and a used `duplicateLeaf()` result below 0.13.8. It also recognizes more guards: `app.secretStorage?.getSecret(…)`, `?? null` fallbacks, a renamed or namespaced `requireApiVersion()`, and a `readonly` field set from it. ## Upgrading from v0.5.0 v0.5.1 needs no config change. It fixes false positives and fixes/suggestions that changed what correct code does, found by linting 600 community plugins: about 16% fewer findings overall. New findings come from two rules. | Change | What to do | |--------|------------| | `prefer-instanceof` reports `e.target instanceof HTMLElement` (also `relatedTarget`, `currentTarget`, `srcElement`) | Never autofixed. Use `e.targetNode?.instanceOf(HTMLElement)` — see [below](#using-instanceof-on-an-events-target) | | `no-unsupported-api` checks APIs with no `@since` against the first typings that declare them | Guard them or raise `minAppVersion`: `activeDocument`/`activeWindow` 0.15.0, `targetNode`/`instanceOf()`/`el.doc`/`el.win` 0.15.3, `createSvg()` 1.1.0, `setCssStyles()`/`setCssProps()`/`nextFrame()` 1.1.7, `Modal.setTitle()` 1.5.1 | | `validate-manifest` checks `id` only with `checkId: true` | Delete an `allowedWords: { id: [...] }` entry you added for 0.5.0. Turn `checkId` on only for an unpublished plugin | | `no-static-styles-assignment` reports at the first fixed-value property of `setCssStyles()`/`setCssProps()`, not at the call | Move an `eslint-disable-next-line` above a multi-line call to sit above that property | | `prefer-active-doc` reports changes to `document.body`/`documentElement`/`head` with a new message and no suggestion | Apply and undo the change in each window's document — see [below](#using-document-or-window-directly) | | Tool configs, `scripts/`, test setup files and helpers are exempt like test files | Delete overrides you added for them (see [Test, tooling and web worker files](#test-tooling-and-web-worker-files-automatic)) | | `activeDocument.createElement()` is no longer reported by `prefer-create-el` | Delete disable comments for it — they are now reported as unused | Rules that now report nothing below the `minAppVersion` their replacement needs: `prefer-get-language` (1.8.7), `prefer-abstract-input-suggest` (1.4.10), `prefer-file-manager-trash-file` (1.6.6), `prefer-instanceof` (0.15.0; no fix below 0.15.3), and `prefer-create-el` for each helper (`createDiv()` 0.10.0, `createSvg()` 1.1.0). ## Upgrading from v0.4.x v0.5.0 is a breaking release that lints more files and needs newer tooling. Expect new findings, mostly from `prefer-active-doc`, `validate-manifest`, `validate-license`, `no-static-styles-assignment`, and `prefer-instanceof`. Test files no longer get the Obsidian-runtime rules and `no-undef` no longer runs on TypeScript, so most projects see fewer findings overall. | Change | What to do | |--------|------------| | Node.js 18 dropped | Use Node.js 20.19+, 22.13+, or 24+ locally and in CI | | `@eslint/json` 2 | If your config registers `@eslint/json` itself, upgrade it to 2.x — 0.14 fails with `Cannot redefine plugin "json"` | | `obsidian` no longer installed for you | `npm install -D obsidian`, or `no-unsupported-api` reports nothing | | `@eslint/js` no longer installed for you | If your config imports it, add it to `devDependencies` | | `manifest.json` and `LICENSE` are now linted | Run ESLint from the project root (`eslint .`, not `eslint src`). Scope type-checked configs and rule-override blocks with `files` (see [below](#scope-overrides-with-files)) | | `@typescript-eslint/no-misused-promises` replaced by `obsidianmd/no-misused-promises` | Rename disable comments — old ones are now reported as unused. If you layer `strictTypeChecked`/`recommendedTypeChecked`, turn the typescript-eslint rule `off` in that block | | `@typescript-eslint/no-require-imports` is off again | Delete disable comments for it (now reported as unused) | | `no-undef` is off for TypeScript | Delete disable comments for it in `.ts` files | | Implied eval in TS is reported by `@typescript-eslint/no-implied-eval` only | Rename `no-implied-eval` disable comments in `.ts` files | | `ui/sentence-case` is off | Opt back in: `"obsidianmd/ui/sentence-case": ["warn", { enforceCamelCaseLower: true }]` | | `prefer-active-doc` now warns | Replace global `document` with `activeDocument` (or `el.doc`) | | Desktop-only repos: raising `no-nodejs-modules` severity no longer re-enables it | Use `["error", { isDesktopOnly: false }]` | | `ruleConfigs` hold only obsidianmd rules | If you use `ruleConfigs` without `recommended`, add `@typescript-eslint/no-deprecated` yourself; `validate-manifest`/`validate-license` need their own blocks | **From the sample plugin's config:** `npm install -D eslint-plugin-obsidianmd@0.5` and the `eslint.config.mts` works unchanged. You can drop `'manifest.json'` from `allowDefaultProject` and `extraFileExtensions: ['.json']` — both were only needed for v0.4. Remove `'package.json'` from `globalIgnores` so `depend/ban-dependencies` checks it. ## The Complete ESLint Config ### Recommended Config (start here) `obsidianmd.configs.recommended` is self-contained — it bundles the core `js.configs.recommended` rules of your installed ESLint, `typescript-eslint` (`recommendedTypeChecked` for `.ts`, `recommended` for `.js`), all Obsidian rules, plus `import`, `@microsoft/sdl`, `depend`, `no-unsanitized`, and `eslint-comments`, and it injects the Obsidian globals (`activeDocument`, `createDiv`, `sleep`, …). This is the same ruleset the community scanner runs. You add two things: a `globalIgnores` entry for build output, and a `parserOptions` block so the type-checked rules can access your TypeScript project. ✅ **CORRECT** (v0.5.x): ```js // eslint.config.mjs import { defineConfig, globalIgnores } from "eslint/config"; import obsidianmd from "eslint-plugin-obsidianmd"; export default defineConfig([ // Build output and the sample plugin's Node build scripts are not plugin code. globalIgnores(["node_modules", "dist", "main.js", "esbuild.config.mjs", "version-bump.mjs"]), ...obsidianmd.configs.recommended, { languageOptions: { parserOptions: { projectService: { allowDefaultProject: ["eslint.config.*"], }, }, }, }, ]); ``` ```jsonc // package.json "scripts": { "lint": "eslint ." } ``` ❌ **INCORRECT**: ```js export default defineConfig([ { ignores: ["main.js", "*.mjs", "package.json"] }, // hides package.json from depend/ban-dependencies ...obsidianmd.configs.recommended, { languageOptions: { parserOptions: { projectService: true, extraFileExtensions: [".json"], // only needed for v0.4 }, }, }, ]); // with "lint": "eslint src" — never visits manifest.json, LICENSE, or package.json ``` > **Run ESLint from the project root.** The recommended config matches `package.json`, `manifest.json`, and `LICENSE` (also `LICENSE.md`, `LICENSE.txt`) **by name, next to your ESLint config**. `eslint src` never visits them, so `depend/ban-dependencies`, `validate-manifest`, and `validate-license` silently do nothing. Matching is case-sensitive on every OS: `License` or `Manifest.json` is not linted. Rules that read `minAppVersion`/`isDesktopOnly` also read `manifest.json` from the working directory. > **Ignore build output.** `main.js` is esbuild output; `esbuild.config.mjs` and `version-bump.mjs` are Node build scripts. None is in your tsconfig, so without the ignore ESLint fails on them with "was not found by the project service". If your plugin has no build step and `main.js` is your source, don't ignore it — add it to `allowDefaultProject` and declare `module`/`exports` as writable globals for it. > **No separate parser import needed.** The recommended config bundles the typescript-eslint parser. You don't need to import `tseslint` or set `parser` yourself — just provide `parserOptions`. > **`allowDefaultProject`** covers files in no `tsconfig.json`, such as the config file itself (the sample plugin's `eslint.config.mts` matches the recommended config's TypeScript glob). ### Plugins written in JavaScript `.js`/`.cjs`/`.mjs`/`.jsx` files get core rules, typescript-eslint `recommended` (not type-checked), and every obsidianmd rule except the seven that need type information (`no-unsupported-api`, `no-misused-promises`, `prefer-create-el`, `prefer-file-manager-trash-file`, `prefer-instanceof`, `no-plugin-as-component`, `no-view-references-in-plugin`). A JavaScript plugin needs **no** `parserOptions` block — with it and no `jsconfig.json`, every file fails with "was not found by the project service". To enable the type-aware rules, add a `jsconfig.json` that includes your sources and a block with `files: ["src/**/*.js"]`, `extends: [tseslint.configs.recommendedTypeChecked]`, `parserOptions: { projectService: true }`, `...obsidianmd.ruleConfigs.recommendedTypeChecked`, and `"@typescript-eslint/no-misused-promises": "off"`. ### Locale checks: `recommendedWithLocalesEn` Swap `recommended` for `recommendedWithLocalesEn` to add `ui/sentence-case-json` and `ui/sentence-case-locale-module` (both `warn`) for English locale files: JSON files and modules (`.ts`, `.js`, `.cjs`, `.mjs`) named `en`, `en-*`, `en_*`, or `en.*` (e.g. `en.json`, `en-US.ts`, `en.messages.json`, any case), or under a directory named so (`en/`, `en-US/`). `english.json`, `entries.json`, and `env.json` are not matched. Inline `ui/sentence-case` stays off in both configs. ### Customizing rules The recommended set is opinionated, and the scanner forbids disabling certain rules inline (see "Disabling rule `X` is not allowed" below), so prefer config-level overrides over `eslint-disable` comments. #### Scope overrides with `files` Because v0.5.0 also lints `package.json`, `manifest.json`, and `LICENSE`, **every rule-override block needs a `files` glob for your source.** The `@typescript-eslint`, `import`, and other bundled plugins are registered for JS/TS files only. ✅ **CORRECT**: ```js export default defineConfig([ globalIgnores(["node_modules", "dist", "main.js", "esbuild.config.mjs", "version-bump.mjs"]), ...obsidianmd.configs.recommended, { languageOptions: { parserOptions: { projectService: { allowDefaultProject: ["eslint.config.*"] }, }, }, }, { files: ["**/*.{ts,cts,mts,tsx,js,cjs,mjs,jsx}"], rules: { "obsidianmd/sample-names": "off", "obsidianmd/ui/sentence-case": ["warn", { enforceCamelCaseLower: true }], // opt in; off by default "@typescript-eslint/no-unused-vars": ["error", { args: "after-used" }], }, }, ]); ``` ❌ **INCORRECT** — no `files`, so the block reaches `manifest.json`/`LICENSE` and stops the run: ```js { rules: { "@typescript-eslint/no-unused-vars": ["error", { args: "after-used" }], }, } // A configuration object specifies rule "@typescript-eslint/no-unused-vars", // but could not find plugin "@typescript-eslint". ``` The parser-options block and `linterOptions` are meant for every file and stay unscoped. #### Layering stricter typescript-eslint configs Scope `strictTypeChecked`/`stylisticTypeChecked` to TypeScript files, and turn back off the two rules they re-enable that conflict with this plugin: ✅ **CORRECT**: ```js import tseslint from "typescript-eslint"; // after ...obsidianmd.configs.recommended: { files: ["**/*.ts"], extends: [tseslint.configs.strictTypeChecked, tseslint.configs.stylisticTypeChecked], rules: { // obsidianmd/no-misused-promises replaces it; both on = every Promise reported twice, // and Obsidian's chaining `then` (Setting, components) flagged again. "@typescript-eslint/no-misused-promises": "off", // Conflicts with the Platform.isDesktop-guarded require() that no-nodejs-modules asks for. "@typescript-eslint/no-require-imports": "off", }, }, ``` ❌ **INCORRECT** — unscoped, so it reaches `LICENSE` and aborts with "You have used a rule which requires type information": ```js ...obsidianmd.configs.recommended, ...tseslint.configs.strictTypeChecked, ``` `strictTypeChecked` also turns `@typescript-eslint/require-await`, `ban-ts-comment`, and `prefer-const` back on, which the recommended config leaves off. `require-await` reports an `async onOpen()`/`onClose()` that never awaits. #### Disabling rules for non-plugin files ESLint has no `"obsidianmd/*": "off"`. Use `ruleConfigs` to generate the overrides: ```js { files: ["scripts/**"], rules: Object.fromEntries([ ...Object.keys(obsidianmd.ruleConfigs.recommended), ...Object.keys(obsidianmd.ruleConfigs.recommendedTypeChecked), ].map(rule => [rule, "off"])), } ``` For code that only runs on desktop but has no manifest (a CLI, tooling), scope the `isDesktopOnly` option instead of disabling the rule: `{ files: ["cli/**"], rules: { "obsidianmd/no-nodejs-modules": ["warn", { isDesktopOnly: true }] } }`. #### Test, tooling and web worker files (automatic) The recommended config exempts test, tooling and worker files from the rules about code running inside Obsidian — you don't need overrides for the standard paths: - **Test files** — `**/*.{test,tests,spec,specs,e2e,setup,testing}.*`, `**/testUtils*`, anything under `test/`, `tests/`, `__tests__/`, `mocks/`, `__mocks__/`, `e2e/`, `e2e-tests/`, `test-helpers/`, `test_helpers/`, `test-support/`, `test-utils/`, `test_utils/`, top-level `automation/` or `test-vault/`, test runner setup files (`**/test-setup.*`, `**/setupTests.*`, `**/global-setup.*`, `**/*-global-setup.*`), and `wdio.conf.*`, `playwright.config.*`. - **Tooling files** (v0.5.1) — configs named after their tool (`eslint.config.*`, `vite.config.*`, `vitest.config.*`, `jest.config.*`, `rollup.config.*`, `esbuild.config.*`, `webpack.config.*`, `svelte.config.*`, `postcss.config.*`, `tailwind.config.*`, and others; also `vitest.*.config.*` and `.eslintrc.*`/`.prettierrc.*`), `esbuild.*`, `version-bump.*`, and anything under `scripts/`. A plugin's own `config.ts` or `settings.config.ts` is **not** a tooling file. - **Web worker files** — `**/worker.*` (v0.6.0), `**/*.worker.*`, `**/*-worker.*`, `**/*_worker.*` (v0.5.1), and anything under `workers/` (not `worker/`, which may hold the main-thread code that starts the worker). Worker globals replace the browser/Obsidian ones. Since v0.6.0, test and tooling files also get the **Node globals** (`process`, `__dirname`, `module`), even in a plugin that isn't desktop-only, and every `.cjs` file gets `module` and `exports` — so `module.exports` in `jest.config.js` or `release.config.cjs` is no longer reported by `no-undef`. | Rule | Test & tooling files | Worker files | |------|---------------------|--------------| | `no-global-this`, `prefer-active-doc`, `prefer-create-el`, `prefer-instanceof`, `prefer-window-timers`, `platform` | off | off | | `no-nodejs-modules`, `no-tfile-tfolder-cast`, `hardcoded-config-path`, `no-unsupported-api`, `regex-lookbehind`, `no-forbidden-elements`, `no-static-styles-assignment`, `prefer-file-manager-trash-file`, `prefer-get-language` | off | on | | `rule-custom-message` | `no-new-func` only — `console.log` is allowed | full | Security rules, including `no-new-func`, still apply everywhere. Still ignore the sample plugin's `esbuild.config.mjs` and `version-bump.mjs` in `globalIgnores`: they are in no `tsconfig.json`, so otherwise they need `allowDefaultProject`. For tests or tooling under other names (e.g. `integration-tests/`, `tools/`), add the same `"off"` overrides for that path or put it in `globalIgnores`. To allow `console` there without losing `no-new-func`, restate `rule-custom-message` with only its `no-new-func` entry: ❌ **INCORRECT** — also drops the `Function`-constructor check: ```js { files: ["tools/**"], rules: { "obsidianmd/rule-custom-message": "off" } } ``` ✅ **CORRECT**: ```js { files: ["tools/**"], rules: { "obsidianmd/rule-custom-message": ["error", { "no-new-func": { messages: { "The Function constructor is eval": "Using the `Function` constructor is dangerous because it executes arbitrary code, similar to `eval()`", }, }, }], }, } ``` #### Manifest options Since v0.5.1, `validate-manifest` checks the `id` (no "obsidian", not ending in "plugin") **only** with `checkId: true`. A published plugin's id can never change and the scanner doesn't check it, so leave `checkId` off once you've submitted. Turn it on for a plugin you haven't submitted yet. Options live in a block scoped to the manifest (a JSON manifest can't carry a disable comment): ❌ **INCORRECT** — a published plugin; `allowedWords.id` does nothing without `checkId` since v0.5.1: ```js { files: ["manifest.json"], rules: { "obsidianmd/validate-manifest": ["warn", { allowedWords: { id: ["obsidian"] } }], }, } ``` ✅ **CORRECT** — an unsubmitted plugin, so its id can still change: ```js { files: ["manifest.json"], rules: { "obsidianmd/validate-manifest": ["warn", { checkId: true }], }, } ``` `ignore: ["noForbiddenWords"]` or `["descriptionFormat"]` skips a check group entirely. ### Using only obsidianmd rules (without the full config) The plugin exports `ruleConfigs` with two presets you can spread into a `rules` block: - `obsidianmd.ruleConfigs.recommended` — obsidianmd rules that do not require type information - `obsidianmd.ruleConfigs.recommendedTypeChecked` — obsidianmd rules that require type information (includes `obsidianmd/no-misused-promises`) As of v0.5.0 they hold **only** obsidianmd rules for source files: `@typescript-eslint/no-deprecated` moved out, and so did `validate-manifest`/`validate-license` (they need their own `files`/`language` blocks). ```js import obsidianmd from "eslint-plugin-obsidianmd"; { files: ["**/*.ts"], extends: [tseslint.configs.recommendedTypeChecked], plugins: { obsidianmd }, rules: { ...obsidianmd.ruleConfigs.recommended, ...obsidianmd.ruleConfigs.recommendedTypeChecked, "@typescript-eslint/no-misused-promises": "off", // replaced by obsidianmd/no-misused-promises "@typescript-eslint/no-deprecated": "warn", // no longer in ruleConfigs }, } ``` With `ruleConfigs` instead of `configs.recommended`, you must declare Obsidian globals (`activeDocument`, `activeWindow`, `createEl`, `sleep`, etc.) yourself; test, tooling, and worker files are not exempted (and `rule-custom-message` keeps `no-console` there); third-party plugins (`@microsoft/sdl`, `import`, `no-unsanitized`, `depend`, `eslint-comments`) are not included; and `manifest.json`/`LICENSE` need their own blocks (`language: "json/json"` with `@eslint/json` 2.x, and `language: "obsidianmd/plain-text"`). Most users should stick with `configs.recommended`. ### Default severities (v0.6.0) Most Obsidian rules are **`warn`** (warnings are publicly visible on your Scorecard, so fix them too). These are the exceptions: | Severity | Rules | |----------|-------| | **`error`** | `detach-leaves`, `no-await-chainable` (v0.6.0), `no-forbidden-elements`, `no-misused-promises`, `no-plugin-as-component`, `no-sample-code`, `no-static-styles-assignment`, `no-unsupported-api`, `no-view-references-in-plugin`, `platform`, `regex-lookbehind`, `rule-custom-message`, `sample-names`, `settings-tab/no-manual-html-headings`, `settings-tab/no-problematic-settings-headings` | | **`off`** | `ui/sentence-case` (opt in manually) | | **`warn`** | everything else — `commands/*` (including `commands/check-callback-uses-checking`, v0.6.0), `editor-drop-paste`, `hardcoded-config-path`, `no-global-this`, `no-nodejs-modules`†, `no-tfile-tfolder-cast`, `object-assign`, `prefer-abstract-input-suggest`, `prefer-active-doc`, `prefer-create-el`, `prefer-file-manager-trash-file`, `prefer-get-language`, `prefer-instanceof`, `prefer-window-timers`, `validate-license`, `validate-manifest`, `vault/iterate`, all four `settings-tab/*` declarative rules, and (in `recommendedWithLocalesEn`) the two locale sentence-case rules | † `no-nodejs-modules` reads your `manifest.json`: it reports nothing when `"isDesktopOnly": true` (only a literal `true` counts). Override with the `isDesktopOnly` option. ### Fixes vs. suggestions (v0.x) `--fix` applies a rewrite only where it can't break type-checking. Elsewhere the same rewrite is an **editor suggestion** (💡) — review and apply it in your editor; `--fix` never applies suggestions. Rules that only reported now offer suggestions: `prefer-active-doc`, `prefer-file-manager-trash-file`, `prefer-get-language`, `object-assign`, `vault/iterate`, the `commands/*` rules, and `no-default-hotkeys`. Suggestions that need a newer Obsidian than your `minAppVersion` are not offered (`activeDocument` 0.15.0, `instanceOf()` 0.15.3, `getFileByPath()` 1.5.7, `trashFile()` 1.6.6, `getLanguage()` 1.8.7). Where no `minAppVersion` is known, `prefer-instanceof` and `prefer-create-el` still fix, and the suggestion names the version it needs. Renaming a command ID breaks users' hotkeys, `executeCommandById()` calls, `obsidian://` URIs, and other plugins that use the old ID — think before accepting that suggestion. v0.6.0 moves more rewrites from `--fix` to suggestions, because they changed what correct code does: an `activeWindow` timer whose ID is kept or cleared (`prefer-window-timers`), an `instanceof` check on a value that may be `null` behind a cast (`prefer-instanceof` — the fix turned a `false` check into one that throws), a call with comments inside its arguments (`prefer-create-el`, `prefer-instanceof`), and a timer or `globalThis` in a function the file turns into a string for an inline worker. Where TypeScript has narrowed `window`, `no-global-this` and `prefer-window-timers` offer nothing. `settings-tab/no-problematic-settings-headings` no longer removes a heading below the top of the tab. Expect a few more findings left after `eslint --fix`. ❌ **INCORRECT** — assuming `--fix` resolved everything, and committing: ```bash npx eslint . --fix && git commit -am "lint" ``` ✅ **CORRECT** — re-run without `--fix` and resolve what's left (apply 💡 suggestions in your editor): ```bash npx eslint . --fix npx eslint . ``` ### Why type-aware linting matters (now bundled) The recommended config already extends `typescript-eslint`'s **`recommendedTypeChecked`** for `.ts` files, so you get the type-aware rules automatically: | Config | Type-aware | What it catches | |--------|-----------|-----------------| | `recommended` | No | Basic TS issues (no-explicit-any, etc.) | | `recommendedTypeChecked` | Yes | + no-floating-promises, restrict-template-expressions, no-unnecessary-type-assertion, await-thenable, no-base-to-string (`no-misused-promises` is swapped for `obsidianmd/no-misused-promises`) | | `strictTypeChecked` | Yes | + no-unsafe-assignment, no-unsafe-member-access, no-unsafe-return, no-unsafe-call | The only thing you must supply is `parserOptions.projectService` (or `project`) so these rules can load type information — without it ESLint throws "you have used a rule which requires type information". > **Tip:** The recommended config runs `@typescript-eslint/no-deprecated` (`warn`), which catches deprecated Obsidian APIs (e.g., `setWarning()` → `setDestructive()` in 1.13+). This only works when the `obsidian` devDependency typings are current — stale typings silently hide deprecations. Keep `"obsidian": "latest"` in your `package.json`. While `minAppVersion` is below 1.13.0 it allows `display()`, which a settings tab must still call there. ## tsconfig.json Requirements The type-checked rules need `project` in parser options, which means your `tsconfig.json` must cover all linted files: ```json { "compilerOptions": { "module": "ESNext", "target": "ES6", "moduleResolution": "bundler", "strictNullChecks": true, "lib": ["DOM", "ES5", "ES6", "ES7"] }, "include": ["src/**/*.ts"] } ``` > **TypeScript 5.9+ users:** Use `"bundler"` for projects using esbuild/bundlers. The `"node10"` option is deprecated and will be removed in TS 7.0. Also remove `"baseUrl"` if you're not using path aliases — it's deprecated. > **Note:** For bundler projects (esbuild), omit `outDir` entirely — the bundler handles output. Setting `outDir: "./"` causes TypeScript to auto-exclude the project root, breaking type checking. If you get "file not found in project" errors from ESLint, your `include` pattern doesn't match your source files. ### Strict mode recommendation For new projects, enable full strict mode to catch more issues at compile time: ```json { "compilerOptions": { "strict": true } } ``` If migrating an existing project, be aware that your IDE may use stricter settings than your tsconfig. Running `tsc --noEmit --strict` locally catches what the IDE sees. The patterns in this guide (Events callbacks, Setting callbacks) work correctly with strict mode enabled. ### TS2564: Property has no initializer **Error:** `Property 'foo' has no initializer and is not definitely assigned in the constructor.` This occurs when `strictPropertyInitialization` is enabled (part of `strict` mode). Common scenario: your tsconfig only has `strictNullChecks: true`, but your IDE applies full strict mode. **Fix patterns:** ```typescript // Pattern A: Definite assignment assertion (when assigned in onload/lifecycle) export class MyPlugin extends Plugin { settings!: MySettings; // ! tells TS "I'll assign this before use" async onload() { this.settings = await this.loadData(); } } // Pattern B: Initialize with undefined-compatible type export class MyModal extends Modal { result: string | undefined; // Explicitly allow undefined } // Pattern C: Initialize with default value export class MyView extends ItemView { wrapperEl: HTMLElement = createDiv(); } ``` **When to use each:** - **Pattern A (`!`)**: Property assigned in `onload()`, `onOpen()`, or similar lifecycle method. Most common for plugin settings. - **Pattern B (`| undefined`)**: Property may legitimately be unset. Requires null checks when accessing. - **Pattern C (default value)**: Property has a sensible default. Use when the default is cheap to create. **Debugging IDE vs build mismatch:** ```bash # See what strict mode catches (matches most IDEs) tsc --noEmit --strict # Compare against your actual tsconfig tsc --noEmit ``` If errors appear in IDE but build succeeds, either enable `strict: true` in tsconfig or apply the fix patterns above. ## Common Violations and How to Fix Them ### Loading Node.js modules (`require()` vs `import`) **Rules:** `obsidianmd/no-nodejs-modules` (`warn`); `@typescript-eslint/no-require-imports` is **off** in v0.5.0 Node.js modules (`fs`, `path`, `os`, etc.) exist only on desktop. In a plugin that isn't `isDesktopOnly`, a static `import` of a Node built-in is always reported — it loads the module wherever the file runs and can't be guarded. Load it with a dynamic `import()` or a `require()` inside a `Platform.isDesktop` guard: ```typescript // Bad — static import loads on mobile too (reported by no-nodejs-modules) import * as fs from 'fs'; // Good — guarded dynamic import if (Platform.isDesktop) { const fs = await import('fs'); } // Also good — guarded require (no-require-imports is off, so no disable comment needed) if (Platform.isDesktop) { const fs = require('fs') as typeof import('fs'); } ``` In a desktop-only plugin (`"isDesktopOnly": true` in `manifest.json`), top-level `import * as fs from 'fs'` is fine — esbuild converts it to `require()` in the CJS bundle. If you previously had `// eslint-disable-next-line @typescript-eslint/no-require-imports`, delete it: v0.5.0 reports it as an unused directive. For `electron`, add a minimal type declaration file since `@types/electron` is not typically installed: ```typescript // src/electron.d.ts declare module 'electron' { const remote: { dialog: Dialog } | undefined; // ... only the types you actually use } ``` Then import normally: ```typescript import * as electron from 'electron'; ``` ### Unexpected control character in regular expression: `\x1b` **Rule:** `no-control-regex` ANSI escape parsing requires the ESC character in regex. Use the `RegExp` constructor instead of a literal: ```typescript // Bad const re = /\x1b\[[\d;]*m/g; // Good const re = new RegExp('\\x1b\\[[\\d;]*m', 'g'); ``` ### `value` will use Object's default stringification format **Rule:** `@typescript-eslint/no-base-to-string` / `@typescript-eslint/restrict-template-expressions` When accessing `Record` values (common with tool inputs from JSONL), `String(value)` or template literals can produce `[object Object]`: ```typescript // Bad — value is unknown, String() on an object gives [object Object] const filePath = String(block.input['file_path'] || ''); // Good — type-narrow first const filePath = typeof block.input['file_path'] === 'string' ? block.input['file_path'] : ''; ``` ### Promises must be awaited **Rule:** `@typescript-eslint/no-floating-promises` Fire-and-forget promises need explicit `void`: ```typescript // Bad MarkdownRenderer.render(app, md, el, '', component); navigator.clipboard.writeText(text); this.app.workspace.revealLeaf(leaf); // Good void MarkdownRenderer.render(app, md, el, '', component); void navigator.clipboard.writeText(text); void this.app.workspace.revealLeaf(leaf); ``` ### Promise returned where void expected **Rule:** `obsidianmd/no-misused-promises` (`error`; replaced `@typescript-eslint/no-misused-promises` in v0.5.0) Same as typescript-eslint's rule, except Obsidian's chaining `then` (on `Setting` and components) no longer counts as a Promise — so returning a `Setting` chain from a callback is no longer a false positive. Real Promises are still reported. `async onload()` in a `Plugin` subclass is fine (v0.5.1 also accepts it with `obsidian` typings older than 1.7.2); `async onunload()` is still reported, because Obsidian doesn't await it. Async callbacks in `addEventListener` or other void-expecting contexts: ```typescript // Bad btn.addEventListener('click', async () => { await doSomething(); }); // Good — wrap in void IIFE btn.addEventListener('click', () => { void (async () => { await doSomething(); })(); }); // Also good — just void the promise btn.addEventListener('click', () => { void doSomething(); }); ``` Unlike other `obsidianmd/*` rules, this one may be disabled inline. Use the new name — a disable comment naming `@typescript-eslint/no-misused-promises` still suppresses the finding but is reported as an unused directive, and `eslint --fix` deletes it: ```typescript // Bad — reported as unused directive in v0.5.0 // eslint-disable-next-line @typescript-eslint/no-misused-promises -- handler catches its own errors // Good // eslint-disable-next-line obsidianmd/no-misused-promises -- handler catches its own errors ``` ### Async function has no `await` expression **Rule:** `@typescript-eslint/require-await` Note: `eslint-plugin-obsidianmd` **disables** this rule in its recommended config. The community scanner may still flag it. If your function doesn't need `await`, remove `async`: ```typescript // Bad async function listFiles(): Promise { return fs.readdirSync(dir); // sync operation, no await } // Good function listFiles(): string[] { return fs.readdirSync(dir); } ``` For interface overrides (like `ItemView.onOpen()`) that require `Promise` return type but have no async work: ```typescript onOpen(): Promise { // ... sync setup ... return Promise.resolve(); } ``` ### This assertion is unnecessary **Rule:** `@typescript-eslint/no-unnecessary-type-assertion` After `instanceof` or `Array.isArray()`, TypeScript narrows the type automatically: ```typescript // Bad if (view instanceof TimelineView) { (view as TimelineView).doSomething(); // cast is redundant } // Good if (view instanceof TimelineView) { view.doSomething(); } ``` For `querySelectorAll` results, use the generic form instead of casting: ```typescript // Bad const els = el.querySelectorAll('.my-class') as NodeListOf; // Good const els = el.querySelectorAll('.my-class'); ``` ### Disabling rule `X` is not allowed The recommended config forbids `eslint-disable` comments for certain rules via the bundled `eslint-comments/no-restricted-disable` rule, which covers `obsidianmd/*` (**except** `obsidianmd/no-misused-promises`), `no-console`, `no-restricted-globals`, `@typescript-eslint/no-restricted-imports`, `no-alert`, `@typescript-eslint/no-deprecated`, `@typescript-eslint/no-explicit-any`, `no-eval`, `@microsoft/sdl/no-document-write`, `@microsoft/sdl/no-inner-html`, and `obsidianmd/no-nodejs-modules`. Fix the underlying issue instead of suppressing it — or, where a finding can never be acted on, use a config-level override (see [Customizing rules](#customizing-rules)). The scanner enforces these for newly submitted plugins at `error`. Locally, unused disable directives are reported as errors (`reportUnusedDisableDirectives`). v0.5.0 turned off or renamed several rules, so these old comments now fail as unused: `@typescript-eslint/no-misused-promises` (rename to `obsidianmd/no-misused-promises`), `@typescript-eslint/no-require-imports` (delete), `no-undef` in `.ts` files (delete), and `no-implied-eval` in `.ts` files (rename to `@typescript-eslint/no-implied-eval`). ### ESLint directive comments require descriptions All `eslint-disable` comments must include a `-- description` explaining why the suppression is necessary. Directives without descriptions produce warnings. ```typescript // Bad — triggers "Unexpected undescribed directive comment" // eslint-disable-next-line @typescript-eslint/no-non-null-assertion const value = obj.field!; // Good // eslint-disable-next-line @typescript-eslint/no-non-null-assertion -- Guaranteed by earlier null check in parseConfig const value = obj.field!; ``` This applies to all directive forms: `eslint-disable`, `eslint-disable-next-line`, and `eslint-disable-line`. ### Unsafe assignment of `any` value **Rule:** `@typescript-eslint/no-unsafe-assignment` Common with `JSON.parse()`. Add a type assertion: ```typescript // Bad const data = JSON.parse(raw); // Good interface MyData { field: string; count: number } const data = JSON.parse(raw) as MyData; ``` ### Unexpected console statement **Rule:** `no-console` Only `console.warn`, `console.error`, and `console.debug` are allowed. Use `console.debug` instead of `console.log` or `console.info`. ### Using `document` or `window` directly **Rule:** `obsidianmd/prefer-active-doc` (`warn` as of v0.5.0 — it was `off` through v0.4.2) For popout window compatibility, use `activeDocument` (or an element's own `el.doc`) instead of the global `document`: ```typescript // Bad const hit = document.querySelector('.my-plugin'); window.addEventListener('resize', onResize); // not linted, but leaks across popouts // Good const hit = containerEl.doc.querySelector('.my-plugin'); // the element's own document this.registerDomEvent(activeWindow, 'resize', onResize); ``` The rule reports only the bare global `document` — not `window`, `window.document`, type positions, property names, or local bindings named `document`. It has **no autofix**: it offers an editor suggestion (`document` → `activeDocument`), because whether code should follow the focused window or a specific element's window depends on what it does. `document.contains(el)` suggests `el.isConnected` instead. No suggestion is offered after an environment check (`typeof document`), where `document` is compared (`e.target === document`) or handed on as a value (an argument, array element, assignment, return), for `document.dispatchEvent()`, or when `minAppVersion` is below 0.15.0. Test, tooling and web worker files are exempt. Not reported (v0.5.1): `document` in a listener on the main window's `document` or `window` (it handles that window's events, so its `document` is right), `document` as the fallback to `activeDocument` (`activeDocument ?? document`), `document` listed with other documents (`[document, ...popoutDocs]`), and lookups of UI only the main window has (`status-bar`, `workspace-ribbon`, `side-dock-ribbon`, `mod-left-split`, `mod-right-split`). **State of the whole window (v0.5.1).** A lasting change to the main window's ``, ``, or `` — a class, attribute, CSS variable, or appended `