eslint-plugin-obsidianmd

May 12, 2026 Β· View on GitHub

Installation

You'll first need to install ESLint:

npm i eslint --save-dev

Next, install eslint-plugin-obsidianmd:

npm install eslint-plugin-obsidianmd --save-dev

Usage

With the release of ESLint v9, the default configuration file is now eslint.config.js.

To use the recommended configuration, add it to your eslint.config.js file. This will enable all the recommended rules.

// eslint.config.mjs
import tsparser from "@typescript-eslint/parser";
import { defineConfig } from "eslint/config";
import obsidianmd from "eslint-plugin-obsidianmd";

export default defineConfig([
  ...obsidianmd.configs.recommended,
  {
    files: ["**/*.ts"],
    languageOptions: {
      parser: tsparser,
      parserOptions: { project: "./tsconfig.json" },
    },

    // You can add your own configuration to override or add rules
    rules: {
      // example: turn off a rule from the recommended set
      "obsidianmd/sample-names": "off",
      // example: add a rule not in the recommended set and set its severity
      "obsidianmd/prefer-file-manager-trash": "error",
    },
  },
]);

Legacy Config (.eslintrc)

Click here for ESLint v8 and older

To use the recommended configuration, extend it in your .eslintrc file:

{
  "extends": ["plugin:obsidianmd/recommended"]
}

You can also override or add rules:

{
  "extends": ["plugin:obsidianmd/recommended"],
  "rules": {
    "obsidianmd/sample-names": "off",
    "obsidianmd/prefer-file-manager-trash": "error"
  }
}

Configurations

Name
βœ…recommended
πŸ‡¬πŸ‡§recommendedWithLocalesEn

Rules

πŸ’Ό Configurations enabled in.
⚠️ Configurations set to warn in.
βœ… Set in the recommended configuration.
πŸ‡¬πŸ‡§ Set in the recommendedWithLocalesEn configuration.
πŸ”§ Automatically fixable by the --fix CLI option.

NameΒ Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β DescriptionπŸ’Όβš οΈπŸ”§
commands/no-command-in-command-idDisallow using the word 'command' in a command ID.βœ… πŸ‡¬πŸ‡§
commands/no-command-in-command-nameDisallow using the word 'command' in a command name.βœ… πŸ‡¬πŸ‡§
commands/no-default-hotkeysDiscourage providing default hotkeys for commands.βœ… πŸ‡¬πŸ‡§
commands/no-plugin-id-in-command-idDisallow including the plugin ID in a command ID.βœ… πŸ‡¬πŸ‡§
commands/no-plugin-name-in-command-nameDisallow including the plugin name in a command name.βœ… πŸ‡¬πŸ‡§
detach-leavesDon't detach leaves in onunload.βœ… πŸ‡¬πŸ‡§πŸ”§
editor-drop-pasteRequire checking evt.defaultPrevented and calling evt.preventDefault() in editor-drop/editor-paste handlers.βœ… πŸ‡¬πŸ‡§
hardcoded-config-pathtestβœ… πŸ‡¬πŸ‡§
no-forbidden-elementsDisallow attachment of forbidden elements to the DOM in Obsidian plugins.βœ… πŸ‡¬πŸ‡§
no-global-thisDisallow global and globalThis. Use window or activeWindow for popout window compatibility.βœ… πŸ‡¬πŸ‡§πŸ”§
no-nodejs-modulesDisallow importing Node.js built-in modules unless guarded by Platform.isDesktopβœ… πŸ‡¬πŸ‡§
no-plugin-as-componentDisallow anti-patterns when passing a component to MarkdownRenderer.render to prevent memory leaks.βœ… πŸ‡¬πŸ‡§
no-sample-codeDisallow sample code snippets from the Obsidian plugin template.βœ… πŸ‡¬πŸ‡§πŸ”§
no-static-styles-assignmentDisallow setting styles directly on DOM elements, favoring CSS classes instead.βœ… πŸ‡¬πŸ‡§
no-tfile-tfolder-castDisallow type casting to TFile or TFolder, suggesting instanceof checks instead.βœ… πŸ‡¬πŸ‡§
no-unsupported-apiDisallow usage of Obsidian APIs not available in the plugin's minimum app versionβœ… πŸ‡¬πŸ‡§
no-view-references-in-pluginDisallow storing references to custom views directly in the plugin, which can cause memory leaks.βœ… πŸ‡¬πŸ‡§
object-assignDiscourage using Object.assign with two argumentsβœ… πŸ‡¬πŸ‡§
platformDisallow use of navigator API for OS detectionβœ… πŸ‡¬πŸ‡§
prefer-abstract-input-suggestDisallow Liam's frequently copied TextInputSuggest implementation in favor of the built-in AbstractInputSuggest.βœ… πŸ‡¬πŸ‡§
prefer-active-docPrefer activeDocument over document for popout window compatibility.βœ… πŸ‡¬πŸ‡§
prefer-file-manager-trash-filePrefer FileManager.trashFile() over Vault.trash() or Vault.delete() to respect user settings.βœ… πŸ‡¬πŸ‡§
prefer-get-languagePrefer Obsidian's getLanguage() over localStorage.getItem('language') and i18next-browser-languagedetector for detecting the user's language.βœ… πŸ‡¬πŸ‡§
prefer-instanceofPrefer .instanceOf(T) over instanceof T for cross-window safe type checks on DOM Nodes and UIEvents.βœ… πŸ‡¬πŸ‡§πŸ”§
prefer-window-timersPrefer window.setTimeout() and related timer functions over bare global calls for popout window compatibility.βœ… πŸ‡¬πŸ‡§πŸ”§
regex-lookbehindUsing lookbehinds in Regex is not supported in some iOS versionsβœ… πŸ‡¬πŸ‡§
rule-custom-messageAllows redefining error messages from other ESLint rules that don't provide this functionality natively.βœ… πŸ‡¬πŸ‡§
sample-namesRename sample plugin class namesβœ… πŸ‡¬πŸ‡§
settings-tab/no-manual-html-headingsDisallow using HTML heading elements for settings headings.βœ… πŸ‡¬πŸ‡§πŸ”§
settings-tab/no-problematic-settings-headingsDiscourage anti-patterns in settings headings.βœ… πŸ‡¬πŸ‡§πŸ”§
ui/sentence-caseEnforce sentence case for UI stringsβœ… πŸ‡¬πŸ‡§πŸ”§
ui/sentence-case-jsonEnforce sentence case for English JSON locale stringsπŸ‡¬πŸ‡§πŸ”§
ui/sentence-case-locale-moduleEnforce sentence case for English TS/JS locale module stringsπŸ‡¬πŸ‡§πŸ”§
validate-licenseValidate the structure of copyright notices in LICENSE files for Obsidian plugins.βœ… πŸ‡¬πŸ‡§
validate-manifestValidate the structure of manifest.json for Obsidian plugins.βœ… πŸ‡¬πŸ‡§
vault/iterateAvoid iterating all files to find a file by its pathβœ… πŸ‡¬πŸ‡§πŸ”§

UI sentence case

Checks UI strings for sentence case. The rule reports warnings but doesn't change text unless you run ESLint with --fix and enable allowAutoFix.

  • Included at warn level in recommended config
  • Extended locale checks available via recommendedWithLocalesEn
  • By default allows CamelCase words like AutoReveal
  • Set enforceCamelCaseLower: true to flag CamelCase as incorrect

Usage (flat config)

// eslint.config.mjs
import tsparser from "@typescript-eslint/parser";
import { defineConfig } from "eslint/config";
import obsidianmd from "eslint-plugin-obsidianmd";

export default defineConfig([
  ...obsidianmd.configs.recommended,
  // Or include English locale files (JSON and TS/JS modules)
  // ...obsidianmd.configs.recommendedWithLocalesEn,

  {
    files: ["**/*.ts"],
    languageOptions: {
      parser: tsparser,
      parserOptions: { project: "./tsconfig.json" },
    },

    // Optional project overrides
    rules: {
      "obsidianmd/ui/sentence-case": [
        "warn",
        {
          brands: ["YourBrand"],
          acronyms: ["OK"],
          enforceCamelCaseLower: true,
        },
      ],
    },
  },
]);

Notes

  • Hyphenated words: Auto-Reveal becomes auto-reveal
  • Locale file patterns in recommendedWithLocalesEn: en*.json, en*.ts, en*.js, en/**/*

Known limitations

Sentence detection may incorrectly split on abbreviations (Dr., Inc., etc.). Use single sentences or adjust rule options when needed.