Warning
This is not fully tested yet.
You'll first need to install ESLint:
npm i eslint --save-dev
Next, install eslint-plugin-obsidianmd
:
npm install eslint-plugin-obsidianmd --save-dev
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.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",
},
},
];
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"
}
}
Name | |
---|---|
✅ | recommended |
💼 Configurations enabled 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. | ✅ | ||
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. | ✅ | 🔧 | |
hardcoded-config-path | test | ✅ | ||
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-view-references-in-plugin | Disallow storing references to custom views directly in the plugin, which can cause memory leaks. | ✅ | ||
object-assign | Object.assign with two parameters instead of 3. | ✅ | ||
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-file-manager-trash-file | Prefer FileManager.trashFile() over Vault.trash() or Vault.delete() to respect user settings. | ✅ | ||
regex-lookbehind | Using lookbehinds in Regex is not supported in some iOS versions | ✅ | ||
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. | ✅ | 🔧 | |
validate-manifest | Validate the structure of manifest.json for Obsidian plugins. | ✅ | ||
vault-iterate | Avoid iterating all files to find a file by its path |
✅ | 🔧 | |
vault/iterate | Avoid iterating all files to find a file by its path |
✅ | 🔧 |