Skip to content

obsidianmd/eslint-plugin

Repository files navigation

eslint-plugin-obsidianmd

Warning

This is not fully tested yet.

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.js
import obsidianmd from "eslint-plugin-obsidianmd";

export default [
  // The recommended configuration
  ...obsidianmd.configs.recommended,

  // 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.
🔧 Automatically fixable by the --fix CLI option.

Name                                          Description 💼 ⚠️ 🔧
commands/no-command-in-command-id Disallow using the word 'command' in a command ID. ✅ ![badge-recommendedWithLocalesEn][]
commands/no-command-in-command-name Disallow using the word 'command' in a command name. ✅ ![badge-recommendedWithLocalesEn][]
commands/no-default-hotkeys Discourage providing default hotkeys for commands. ✅ ![badge-recommendedWithLocalesEn][]
commands/no-plugin-id-in-command-id Disallow including the plugin ID in a command ID. ✅ ![badge-recommendedWithLocalesEn][]
commands/no-plugin-name-in-command-name Disallow including the plugin name in a command name. ✅ ![badge-recommendedWithLocalesEn][]
detach-leaves Don't detach leaves in onunload. ✅ ![badge-recommendedWithLocalesEn][] 🔧
hardcoded-config-path test ✅ ![badge-recommendedWithLocalesEn][]
no-plugin-as-component Disallow anti-patterns when passing a component to MarkdownRenderer.render to prevent memory leaks. ✅ ![badge-recommendedWithLocalesEn][]
no-sample-code Disallow sample code snippets from the Obsidian plugin template. ✅ ![badge-recommendedWithLocalesEn][] 🔧
no-static-styles-assignment Disallow setting styles directly on DOM elements, favoring CSS classes instead. ✅ ![badge-recommendedWithLocalesEn][]
no-tfile-tfolder-cast Disallow type casting to TFile or TFolder, suggesting instanceof checks instead. ✅ ![badge-recommendedWithLocalesEn][]
no-view-references-in-plugin Disallow storing references to custom views directly in the plugin, which can cause memory leaks. ✅ ![badge-recommendedWithLocalesEn][]
object-assign Object.assign with two parameters instead of 3. ✅ ![badge-recommendedWithLocalesEn][]
platform Disallow use of navigator API for OS detection ✅ ![badge-recommendedWithLocalesEn][]
prefer-abstract-input-suggest Disallow Liam's frequently copied TextInputSuggest implementation in favor of the built-in AbstractInputSuggest. ✅ ![badge-recommendedWithLocalesEn][]
prefer-file-manager-trash-file Prefer FileManager.trashFile() over Vault.trash() or Vault.delete() to respect user settings. ✅ ![badge-recommendedWithLocalesEn][]
regex-lookbehind Using lookbehinds in Regex is not supported in some iOS versions ✅ ![badge-recommendedWithLocalesEn][]
sample-names Rename sample plugin class names ✅ ![badge-recommendedWithLocalesEn][]
settings-tab/no-manual-html-headings Disallow using HTML heading elements for settings headings. ✅ ![badge-recommendedWithLocalesEn][] 🔧
settings-tab/no-problematic-settings-headings Discourage anti-patterns in settings headings. ✅ ![badge-recommendedWithLocalesEn][] 🔧
ui/sentence-case Enforce sentence case for UI strings ✅ ![badge-recommendedWithLocalesEn][] 🔧
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-manifest Validate the structure of manifest.json for Obsidian plugins. ✅ ![badge-recommendedWithLocalesEn][]
vault/iterate Avoid iterating all files to find a file by its path
✅ ![badge-recommendedWithLocalesEn][] 🔧

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.js
import obsidianmd from 'eslint-plugin-obsidianmd';

export default [
  // Base Obsidian rules
  ...obsidianmd.configs.recommended,

  // Or include English locale files (JSON and TS/JS modules)
  // ...obsidianmd.configs.recommendedWithLocalesEn,

  // 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

No packages published

Contributors 6