Skip to content

Split existing rules into separate rulesets #43

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 22 additions & 24 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,25 +23,20 @@ Add `obsidianmd` to the plugins section of your `.eslintrc` configuration file.

```json
{
"plugins": [
"obsidianmd"
]
"plugins": ["obsidianmd"]
}
```


Then configure the rules you want to use under the rules section.

```json
{
"rules": {
"obsidian/rule-name": 2
}
"rules": {
"obsidian/rule-name": 2
}
}
```



## Configurations

<!-- begin auto-generated configs list -->
Expand All @@ -52,8 +47,6 @@ Then configure the rules you want to use under the rules section.

<!-- end auto-generated configs list -->



## Rules

<!-- begin auto-generated rules list -->
Expand All @@ -62,18 +55,23 @@ Then configure the rules you want to use under the rules section.
✅ Set in the `recommended` configuration.\
🔧 Automatically fixable by the [`--fix` CLI option](https://eslint.org/docs/user-guide/command-line-interface#--fix).

| Name                         | Description | 💼 | 🔧 |
| :------------------------------------------------------------------------- | :------------------------------------------------------------------------------------------------ | :- | :- |
| [commands](docs/rules/commands.md) | Command guidelines | ✅ | |
| [detach-leaves](docs/rules/detach-leaves.md) | Don't detach leaves in onunload. | ✅ | 🔧 |
| [hardcoded-config-path](docs/rules/hardcoded-config-path.md) | test | ✅ | |
| [no-tfile-tfolder-cast](docs/rules/no-tfile-tfolder-cast.md) | Disallow type casting to TFile or TFolder, suggesting instanceof checks instead. | ✅ | |
| [no-view-references-in-plugin](docs/rules/no-view-references-in-plugin.md) | Disallow storing references to custom views directly in the plugin, which can cause memory leaks. | ✅ | |
| [object-assign](docs/rules/object-assign.md) | Object.assign with two parameters instead of 3. | ✅ | |
| [platform](docs/rules/platform.md) | Disallow use of navigator API for OS detection | ✅ | |
| [regex-lookbehind](docs/rules/regex-lookbehind.md) | Using lookbehinds in Regex is not supported in some iOS versions | ✅ | |
| [sample-names](docs/rules/sample-names.md) | Rename sample plugin class names | ✅ | |
| [settings-tab](docs/rules/settings-tab.md) | Discourage common anti-patterns in plugin settings tabs. | ✅ | 🔧 |
| [vault-iterate](docs/rules/vault-iterate.md) | Avoid iterating all files to find a file by its path<br/> | ✅ | 🔧 |
| Name                                          | Description | 💼 | 🔧 |
| :----------------------------------------------------------------------------------------------------------- | :------------------------------------------------------------------------------------------------ | :- | :- |
| [commands/no-command-in-command-id](docs/rules/commands/no-command-in-command-id.md) | Disallow using the word 'command' in a command ID. | ✅ | |
| [commands/no-command-in-command-name](docs/rules/commands/no-command-in-command-name.md) | Disallow using the word 'command' in a command name. | ✅ | |
| [commands/no-default-hotkeys](docs/rules/commands/no-default-hotkeys.md) | Discourage providing default hotkeys for commands. | ✅ | |
| [commands/no-plugin-id-in-command-id](docs/rules/commands/no-plugin-id-in-command-id.md) | Disallow including the plugin ID in a command ID. | ✅ | |
| [commands/no-plugin-name-in-command-name](docs/rules/commands/no-plugin-name-in-command-name.md) | Disallow including the plugin name in a command name. | ✅ | |
| [detach-leaves](docs/rules/detach-leaves.md) | Don't detach leaves in onunload. | ✅ | 🔧 |
| [hardcoded-config-path](docs/rules/hardcoded-config-path.md) | test | ✅ | |
| [no-tfile-tfolder-cast](docs/rules/no-tfile-tfolder-cast.md) | Disallow type casting to TFile or TFolder, suggesting instanceof checks instead. | ✅ | |
| [no-view-references-in-plugin](docs/rules/no-view-references-in-plugin.md) | Disallow storing references to custom views directly in the plugin, which can cause memory leaks. | ✅ | |
| [object-assign](docs/rules/object-assign.md) | Object.assign with two parameters instead of 3. | ✅ | |
| [platform](docs/rules/platform.md) | Disallow use of navigator API for OS detection | ✅ | |
| [regex-lookbehind](docs/rules/regex-lookbehind.md) | Using lookbehinds in Regex is not supported in some iOS versions | ✅ | |
| [sample-names](docs/rules/sample-names.md) | Rename sample plugin class names | ✅ | |
| [settings-tab/no-manual-html-headings](docs/rules/settings-tab/no-manual-html-headings.md) | Disallow using HTML heading elements for settings headings. | ✅ | 🔧 |
| [settings-tab/no-problematic-settings-headings](docs/rules/settings-tab/no-problematic-settings-headings.md) | Discourage anti-patterns in settings headings. | ✅ | 🔧 |
| [vault/iterate](docs/rules/vault/iterate.md) | Avoid iterating all files to find a file by its path<br/> | ✅ | 🔧 |

<!-- end auto-generated rules list -->
5 changes: 5 additions & 0 deletions docs/rules/commands/no-command-in-command-id.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Disallow using the word 'command' in a command ID (`obsidianmd/commands/no-command-in-command-id`)

💼 This rule is enabled in the ✅ `recommended` config.

<!-- end auto-generated rule header -->
5 changes: 5 additions & 0 deletions docs/rules/commands/no-command-in-command-name.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Disallow using the word 'command' in a command name (`obsidianmd/commands/no-command-in-command-name`)

💼 This rule is enabled in the ✅ `recommended` config.

<!-- end auto-generated rule header -->
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Command guidelines (`obsidianmd/commands`)
# Discourage providing default hotkeys for commands (`obsidianmd/commands/no-default-hotkeys`)

💼 This rule is enabled in the ✅ `recommended` config.

Expand Down
5 changes: 5 additions & 0 deletions docs/rules/commands/no-plugin-id-in-command-id.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Disallow including the plugin ID in a command ID (`obsidianmd/commands/no-plugin-id-in-command-id`)

💼 This rule is enabled in the ✅ `recommended` config.

<!-- end auto-generated rule header -->
5 changes: 5 additions & 0 deletions docs/rules/commands/no-plugin-name-in-command-name.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Disallow including the plugin name in a command name (`obsidianmd/commands/no-plugin-name-in-command-name`)

💼 This rule is enabled in the ✅ `recommended` config.

<!-- end auto-generated rule header -->
7 changes: 7 additions & 0 deletions docs/rules/settings-tab/no-manual-html-headings.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Disallow using HTML heading elements for settings headings (`obsidianmd/settings-tab/no-manual-html-headings`)

💼 This rule is enabled in the ✅ `recommended` config.

🔧 This rule is automatically fixable by the [`--fix` CLI option](https://eslint.org/docs/latest/user-guide/command-line-interface#--fix).

<!-- end auto-generated rule header -->
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Discourage common anti-patterns in plugin settings tabs (`obsidianmd/settings-tab`)
# Discourage anti-patterns in settings headings (`obsidianmd/settings-tab/no-problematic-settings-headings`)

💼 This rule is enabled in the ✅ `recommended` config.

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Avoid iterating all files to find a file by its path
(`obsidianmd/vault-iterate`)
(`obsidianmd/vault/iterate`)

💼 This rule is enabled in the ✅ `recommended` config.

Expand Down
34 changes: 25 additions & 9 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import commands from "./lib/rules/commands.ts";
import { commands } from "./lib/rules/commands";
import { settingsTab } from "./lib/rules/settingsTab";
import { vault } from "./lib/rules/vault";
import detachLeaves from "./lib/rules/detachLeaves.ts";
import hardcodedConfigPath from "./lib/rules/hardcodedConfigPath.ts";
import noTFileTFolderCast from "./lib/rules/noTFileTFolderCast.ts";
Expand All @@ -7,8 +9,6 @@ import objectAssign from "./lib/rules/objectAssign.ts";
import platform from "./lib/rules/platform.ts";
import regexLookbehind from "./lib/rules/regexLookbehind.ts";
import sampleNames from "./lib/rules/sampleNames.ts";
import settingsTab from "./lib/rules/settingsTab.ts";
import vaultIterate from "./lib/rules/vault/iterate.ts";

export default [
{
Expand All @@ -24,7 +24,20 @@ export default [
plugins: {
obsidianmd: {
rules: {
commands: commands,
"commands/no-command-in-command-id":
commands.noCommandInCommandId,
"commands/no-command-in-command-name":
commands.noCommandInCommandName,
"commands/no-default-hotkey": commands.noDefaultHotkeys,
"commands/no-plugin-id-in-command-id":
commands.noPluginIdInCommandId,
"commands/no-plugin-id-in-command-name":
commands.noPluginNameInCommandName,
"settings-tab/no-manual-html-headings":
settingsTab.noManualHtmlHeadings,
"settings-tab/no-problematic-settings-headings":
settingsTab.noProblematicSettingsHeadings,
"vault/iterate": vault.iterate,
"detach-leaves": detachLeaves,
"hardcoded-config-path": hardcodedConfigPath,
"no-tfile-tfolder-cast": noTFileTFolderCast,
Expand All @@ -33,13 +46,18 @@ export default [
platform: platform,
"regex-lookbehind": regexLookbehind,
"sample-names": sampleNames,
"settings-tab": settingsTab,
"vault-iterate": vaultIterate,
},
},
},
rules: {
"obsidianmd/commands": "error",
"obsidianmd/commands/no-command-in-command-id": "error",
"obsidianmd/commands/no-command-in-command-name": "error",
"obsidianmd/commands/no-default-hotkey": "error",
"obsidianmd/commands/no-plugin-id-in-command-id": "error",
"obsidianmd/commands/no-plugin-id-in-command-name": "error",
"obsidianmd/settings-tab/no-manual-html-headings": "error",
"obsidianmd/settings-tab/no-problematic-settings-headings": "error",
"obsidianmd/vault/iterate": "error",
"obsidianmd/detach-leaves": "error",
"obsidianmd/hardcoded-config-path": "error",
"obsidianmd/no-tfile-tfolder-cast": "error",
Expand All @@ -48,8 +66,6 @@ export default [
"obsidianmd/platform": "error",
"obsidianmd/regex-lookbehind": "error",
"obsidianmd/sample-names": "error",
"obsidianmd/settings-tab": "error",
"obsidianmd/vault-iterate": "error",
},
},
];
32 changes: 23 additions & 9 deletions lib/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import commands from "./rules/commands.js";
import { commands } from "./rules/commands/index.js";
import { settingsTab } from "./rules/settingsTab/index.js";
import { vault } from "./rules/vault/index.js";
import detachLeaves from "./rules/detachLeaves.js";
import hardcodedConfigPath from "./rules/hardcodedConfigPath.js";
import noTFileTFolderCast from "./rules/noTFileTFolderCast.js";
Expand All @@ -7,8 +9,6 @@ import objectAssign from "./rules/objectAssign.js";
import platform from "./rules/platform.js";
import regexLookbehind from "./rules/regexLookbehind.js";
import sampleNames from "./rules/sampleNames.js";
import settingsTab from "./rules/settingsTab.js";
import vaultIterate from "./rules/vault/iterate.js";
import { manifest } from "./readManifest.js";

export default {
Expand All @@ -17,7 +17,17 @@ export default {
version: "0.0.2",
},
rules: {
commands: commands,
"commands/no-command-in-command-id": commands.noCommandInCommandId,
"commands/no-command-in-command-name": commands.noCommandInCommandName,
"commands/no-default-hotkeys": commands.noDefaultHotkeys,
"commands/no-plugin-id-in-command-id": commands.noPluginIdInCommandId,
"commands/no-plugin-name-in-command-name":
commands.noPluginNameInCommandName,
"settings-tab/no-manual-html-headings":
settingsTab.noManualHtmlHeadings,
"settings-tab/no-problematic-settings-headings":
settingsTab.noProblematicSettingsHeadings,
"vault/iterate": vault.iterate,
"detach-leaves": detachLeaves,
"hardcoded-config-path": hardcodedConfigPath,
"no-tfile-tfolder-cast": noTFileTFolderCast,
Expand All @@ -26,8 +36,6 @@ export default {
platform: platform,
"regex-lookbehind": regexLookbehind,
"sample-names": sampleNames,
"settings-tab": settingsTab,
"vault-iterate": vaultIterate,
},
configs: {
recommended: {
Expand Down Expand Up @@ -143,7 +151,15 @@ export default {
manifest && manifest.isDesktopOnly ? "off" : "error",
"import/no-extraneous-dependencies": "error",

"obsidianmd/commands": "error",
"obsidianmd/commands/no-command-in-command-id": "error",
"obsidianmd/commands/no-command-in-command-name": "error",
"obsidianmd/commands/no-default-hotkeys": "error",
"obsidianmd/commands/no-plugin-id-in-command-id": "error",
"obsidianmd/commands/no-plugin-name-in-command-name": "error",
"obsidianmd/settings-tab/no-manual-html-headings": "error",
"obsidianmd/settings-tab/no-problematic-settings-headings":
"error",
"obsidianmd/vault/iterate": "error",
"obsidianmd/detach-leaves": "error",
"obsidianmd/hardcoded-config-path": "error",
"obsidianmd/no-tfile-tfolder-cast": "error",
Expand All @@ -152,8 +168,6 @@ export default {
"obsidianmd/platform": "error",
"obsidianmd/regex-lookbehind": "error",
"obsidianmd/sample-names": "error",
"obsidianmd/settings-tab": "error",
"obsidianmd/vault-iterate": "error",
},
},
},
Expand Down
114 changes: 0 additions & 114 deletions lib/rules/commands.ts

This file was deleted.

13 changes: 13 additions & 0 deletions lib/rules/commands/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import noCommandInCommandId from "./noCommandInCommandId.js";
import noCommandInCommandName from "./noCommandInCommandName.js";
import noDefaultHotkeys from "./noDefaultHotkey.js";
import noPluginIdInCommandId from "./noPluginIdInCommandId.js";
import noPluginNameInCommandName from "./noPluginNameInCommandName.js";

export const commands = {
noCommandInCommandId,
noCommandInCommandName,
noDefaultHotkeys,
noPluginIdInCommandId,
noPluginNameInCommandName,
};
Loading