Skip to content

obsidianmd/eslint-plugin

Repository files navigation

eslint-plugin-obsidianmd

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.

Flat Config (eslint.config.js) - Recommended for ESLint v9+

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-id Disallow using the word 'command' in a command ID. βœ… πŸ‡¬πŸ‡§
commands/no-command-in-command-name Disallow using the word 'command' in a command name. βœ… πŸ‡¬πŸ‡§
commands/no-default-hotkeys Discourage providing default hotkeys for commands. βœ… πŸ‡¬πŸ‡§
commands/no-plugin-id-in-command-id Disallow including the plugin ID in a command ID. βœ… πŸ‡¬πŸ‡§
commands/no-plugin-name-in-command-name Disallow including the plugin name in a command name. βœ… πŸ‡¬πŸ‡§
detach-leaves Don't detach leaves in onunload. βœ… πŸ‡¬πŸ‡§ πŸ”§
editor-drop-paste Require checking evt.defaultPrevented and calling evt.preventDefault() in editor-drop/editor-paste handlers. βœ… πŸ‡¬πŸ‡§
hardcoded-config-path test βœ… πŸ‡¬πŸ‡§
no-forbidden-elements Disallow attachment of forbidden elements to the DOM in Obsidian plugins. βœ… πŸ‡¬πŸ‡§
no-plugin-as-component Disallow anti-patterns when passing a component to MarkdownRenderer.render to prevent memory leaks. βœ… πŸ‡¬πŸ‡§
no-sample-code Disallow sample code snippets from the Obsidian plugin template. βœ… πŸ‡¬πŸ‡§ πŸ”§
no-static-styles-assignment Disallow setting styles directly on DOM elements, favoring CSS classes instead. βœ… πŸ‡¬πŸ‡§
no-tfile-tfolder-cast Disallow type casting to TFile or TFolder, suggesting instanceof checks instead. βœ… πŸ‡¬πŸ‡§
no-unsupported-api Disallow usage of Obsidian APIs not available in the plugin's minimum app version βœ… πŸ‡¬πŸ‡§
no-view-references-in-plugin Disallow storing references to custom views directly in the plugin, which can cause memory leaks. βœ… πŸ‡¬πŸ‡§
object-assign Discourage using Object.assign with two arguments βœ… πŸ‡¬πŸ‡§
platform Disallow use of navigator API for OS detection βœ… πŸ‡¬πŸ‡§
prefer-abstract-input-suggest Disallow Liam's frequently copied TextInputSuggest implementation in favor of the built-in AbstractInputSuggest. βœ… πŸ‡¬πŸ‡§
prefer-active-doc Prefer activeDocument and activeWindow over document and window for popout window compatibility. βœ… πŸ‡¬πŸ‡§ πŸ”§
prefer-active-window-timers Prefer activeWindow.setTimeout() and related timer functions over bare global calls for popout window compatibility. βœ… πŸ‡¬πŸ‡§ πŸ”§
prefer-file-manager-trash-file Prefer FileManager.trashFile() over Vault.trash() or Vault.delete() to respect user settings. βœ… πŸ‡¬πŸ‡§
prefer-instanceof Prefer .instanceOf(T) over instanceof T for cross-window safe type checks on DOM Nodes and UIEvents. βœ… πŸ‡¬πŸ‡§ πŸ”§
regex-lookbehind Using lookbehinds in Regex is not supported in some iOS versions βœ… πŸ‡¬πŸ‡§
rule-custom-message Allows redefining error messages from other ESLint rules that don't provide this functionality natively. βœ… πŸ‡¬πŸ‡§
sample-names Rename sample plugin class names βœ… πŸ‡¬πŸ‡§
settings-tab/no-manual-html-headings Disallow using HTML heading elements for settings headings. βœ… πŸ‡¬πŸ‡§ πŸ”§
settings-tab/no-problematic-settings-headings Discourage anti-patterns in settings headings. βœ… πŸ‡¬πŸ‡§ πŸ”§
ui/sentence-case Enforce sentence case for UI strings βœ… πŸ‡¬πŸ‡§ πŸ”§
ui/sentence-case-json Enforce sentence case for English JSON locale strings πŸ‡¬πŸ‡§ πŸ”§
ui/sentence-case-locale-module Enforce sentence case for English TS/JS locale module strings πŸ‡¬πŸ‡§ πŸ”§
validate-license Validate the structure of copyright notices in LICENSE files for Obsidian plugins. βœ… πŸ‡¬πŸ‡§
validate-manifest Validate the structure of manifest.json for Obsidian plugins. βœ… πŸ‡¬πŸ‡§
vault/iterate Avoid 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.

About

No description, website, or topics provided.

Resources

License

Contributing

Stars

Watchers

Forks

Packages

 
 
 

Contributors