diff --git a/README.md b/README.md index 2b28ed0..a6bc95f 100644 --- a/README.md +++ b/README.md @@ -30,6 +30,7 @@ import obsidianmd from "eslint-plugin-obsidianmd"; export default defineConfig([ ...obsidianmd.configs.recommended, + ...obsidianmd.configs.packageJson, { files: ["**/*.ts"], languageOptions: { @@ -82,8 +83,11 @@ You can also override or add rules: | | Name | | :--- | :------------------------- | +| | `packageJson` | +| ⚛️ | `react` | | ✅ | `recommended` | | 🇬🇧 | `recommendedWithLocalesEn` | +| 🔥 | `svelte` | @@ -160,6 +164,7 @@ import obsidianmd from "eslint-plugin-obsidianmd"; export default defineConfig([ ...obsidianmd.configs.recommended, + ...obsidianmd.configs.packageJson, // Or include English locale files (JSON and TS/JS modules) // ...obsidianmd.configs.recommendedWithLocalesEn, diff --git a/docs/rules/commands/no-command-in-command-id.md b/docs/rules/commands/no-command-in-command-id.md index 31fa7d6..d7b8f7a 100644 --- a/docs/rules/commands/no-command-in-command-id.md +++ b/docs/rules/commands/no-command-in-command-id.md @@ -2,6 +2,6 @@ 📝 Disallow using the word 'command' in a command ID. -💼 This rule is enabled in the following configs: ✅ `recommended`, 🇬🇧 `recommendedWithLocalesEn`. +💼 This rule is enabled in the following configs: `react`, ✅ `recommended`, 🇬🇧 `recommendedWithLocalesEn`, `svelte`. diff --git a/docs/rules/commands/no-command-in-command-name.md b/docs/rules/commands/no-command-in-command-name.md index 2cbb43b..d895efb 100644 --- a/docs/rules/commands/no-command-in-command-name.md +++ b/docs/rules/commands/no-command-in-command-name.md @@ -2,6 +2,6 @@ 📝 Disallow using the word 'command' in a command name. -💼 This rule is enabled in the following configs: ✅ `recommended`, 🇬🇧 `recommendedWithLocalesEn`. +💼 This rule is enabled in the following configs: `react`, ✅ `recommended`, 🇬🇧 `recommendedWithLocalesEn`, `svelte`. diff --git a/docs/rules/commands/no-default-hotkeys.md b/docs/rules/commands/no-default-hotkeys.md index 628003c..9e29013 100644 --- a/docs/rules/commands/no-default-hotkeys.md +++ b/docs/rules/commands/no-default-hotkeys.md @@ -2,6 +2,6 @@ 📝 Discourage providing default hotkeys for commands. -💼 This rule is enabled in the following configs: ✅ `recommended`, 🇬🇧 `recommendedWithLocalesEn`. +💼 This rule is enabled in the following configs: `react`, ✅ `recommended`, 🇬🇧 `recommendedWithLocalesEn`, `svelte`. diff --git a/docs/rules/commands/no-plugin-id-in-command-id.md b/docs/rules/commands/no-plugin-id-in-command-id.md index f1a76cd..ee9ccff 100644 --- a/docs/rules/commands/no-plugin-id-in-command-id.md +++ b/docs/rules/commands/no-plugin-id-in-command-id.md @@ -2,7 +2,7 @@ 📝 Disallow including the plugin ID in a command ID. -💼 This rule is enabled in the following configs: ✅ `recommended`, 🇬🇧 `recommendedWithLocalesEn`. +💼 This rule is enabled in the following configs: `react`, ✅ `recommended`, 🇬🇧 `recommendedWithLocalesEn`, `svelte`. diff --git a/docs/rules/commands/no-plugin-name-in-command-name.md b/docs/rules/commands/no-plugin-name-in-command-name.md index 7c18243..35a1182 100644 --- a/docs/rules/commands/no-plugin-name-in-command-name.md +++ b/docs/rules/commands/no-plugin-name-in-command-name.md @@ -2,7 +2,7 @@ 📝 Disallow including the plugin name in a command name. -💼 This rule is enabled in the following configs: ✅ `recommended`, 🇬🇧 `recommendedWithLocalesEn`. +💼 This rule is enabled in the following configs: `react`, ✅ `recommended`, 🇬🇧 `recommendedWithLocalesEn`, `svelte`. diff --git a/docs/rules/detach-leaves.md b/docs/rules/detach-leaves.md index fa2114a..95c3bb8 100644 --- a/docs/rules/detach-leaves.md +++ b/docs/rules/detach-leaves.md @@ -2,7 +2,7 @@ 📝 Don't detach leaves in onunload. -💼 This rule is enabled in the following configs: ✅ `recommended`, 🇬🇧 `recommendedWithLocalesEn`. +💼 This rule is enabled in the following configs: `react`, ✅ `recommended`, 🇬🇧 `recommendedWithLocalesEn`, `svelte`. 🔧 This rule is automatically fixable by the [`--fix` CLI option](https://eslint.org/docs/latest/user-guide/command-line-interface#--fix). diff --git a/docs/rules/editor-drop-paste.md b/docs/rules/editor-drop-paste.md index f2ccc12..cd814b3 100644 --- a/docs/rules/editor-drop-paste.md +++ b/docs/rules/editor-drop-paste.md @@ -2,6 +2,6 @@ 📝 Require checking `evt.defaultPrevented` and calling `evt.preventDefault()` in editor-drop/editor-paste handlers. -💼 This rule is enabled in the following configs: ✅ `recommended`, 🇬🇧 `recommendedWithLocalesEn`. +💼 This rule is enabled in the following configs: `react`, ✅ `recommended`, 🇬🇧 `recommendedWithLocalesEn`, `svelte`. diff --git a/docs/rules/hardcoded-config-path.md b/docs/rules/hardcoded-config-path.md index c8efee1..0983dff 100644 --- a/docs/rules/hardcoded-config-path.md +++ b/docs/rules/hardcoded-config-path.md @@ -2,6 +2,6 @@ 📝 Test. -💼 This rule is enabled in the following configs: ✅ `recommended`, 🇬🇧 `recommendedWithLocalesEn`. +💼 This rule is enabled in the following configs: `react`, ✅ `recommended`, 🇬🇧 `recommendedWithLocalesEn`, `svelte`. diff --git a/docs/rules/no-forbidden-elements.md b/docs/rules/no-forbidden-elements.md index 54ae913..8f83fe3 100644 --- a/docs/rules/no-forbidden-elements.md +++ b/docs/rules/no-forbidden-elements.md @@ -2,6 +2,6 @@ 📝 Disallow attachment of forbidden elements to the DOM in Obsidian plugins. -💼 This rule is enabled in the following configs: ✅ `recommended`, 🇬🇧 `recommendedWithLocalesEn`. +💼 This rule is enabled in the following configs: `react`, ✅ `recommended`, 🇬🇧 `recommendedWithLocalesEn`, `svelte`. diff --git a/docs/rules/no-global-this.md b/docs/rules/no-global-this.md index caaed77..1b2a715 100644 --- a/docs/rules/no-global-this.md +++ b/docs/rules/no-global-this.md @@ -2,8 +2,6 @@ 📝 Disallow `global` and `globalThis`. Use `window` or `activeWindow` for popout window compatibility. -💼 This rule is enabled in the following configs: ✅ `recommended`, 🇬🇧 `recommendedWithLocalesEn`. - 🔧 This rule is automatically fixable by the [`--fix` CLI option](https://eslint.org/docs/latest/user-guide/command-line-interface#--fix). diff --git a/docs/rules/no-nodejs-modules.md b/docs/rules/no-nodejs-modules.md index 31d3ca3..9b9b629 100644 --- a/docs/rules/no-nodejs-modules.md +++ b/docs/rules/no-nodejs-modules.md @@ -2,6 +2,6 @@ 📝 Disallow importing Node.js built-in modules unless guarded by Platform.isDesktop. -💼 This rule is enabled in the following configs: ✅ `recommended`, 🇬🇧 `recommendedWithLocalesEn`. +💼 This rule is enabled in the following configs: `react`, ✅ `recommended`, 🇬🇧 `recommendedWithLocalesEn`, `svelte`. diff --git a/docs/rules/no-plugin-as-component.md b/docs/rules/no-plugin-as-component.md index f3c0f97..2b13dd2 100644 --- a/docs/rules/no-plugin-as-component.md +++ b/docs/rules/no-plugin-as-component.md @@ -2,6 +2,6 @@ 📝 Disallow anti-patterns when passing a component to MarkdownRenderer.render to prevent memory leaks. -💼 This rule is enabled in the following configs: ✅ `recommended`, 🇬🇧 `recommendedWithLocalesEn`. +💼 This rule is enabled in the following configs: `react`, ✅ `recommended`, 🇬🇧 `recommendedWithLocalesEn`, `svelte`. diff --git a/docs/rules/no-sample-code.md b/docs/rules/no-sample-code.md index 9258667..b07f6b4 100644 --- a/docs/rules/no-sample-code.md +++ b/docs/rules/no-sample-code.md @@ -2,7 +2,7 @@ 📝 Disallow sample code snippets from the Obsidian plugin template. -💼 This rule is enabled in the following configs: ✅ `recommended`, 🇬🇧 `recommendedWithLocalesEn`. +💼 This rule is enabled in the following configs: `react`, ✅ `recommended`, 🇬🇧 `recommendedWithLocalesEn`, `svelte`. 🔧 This rule is automatically fixable by the [`--fix` CLI option](https://eslint.org/docs/latest/user-guide/command-line-interface#--fix). diff --git a/docs/rules/no-static-styles-assignment.md b/docs/rules/no-static-styles-assignment.md index 4c3ddf3..187d1a3 100644 --- a/docs/rules/no-static-styles-assignment.md +++ b/docs/rules/no-static-styles-assignment.md @@ -2,6 +2,6 @@ 📝 Disallow setting styles directly on DOM elements, favoring CSS classes instead. -💼 This rule is enabled in the following configs: ✅ `recommended`, 🇬🇧 `recommendedWithLocalesEn`. +💼 This rule is enabled in the following configs: `react`, ✅ `recommended`, 🇬🇧 `recommendedWithLocalesEn`, `svelte`. diff --git a/docs/rules/no-tfile-tfolder-cast.md b/docs/rules/no-tfile-tfolder-cast.md index 0390606..b59fc24 100644 --- a/docs/rules/no-tfile-tfolder-cast.md +++ b/docs/rules/no-tfile-tfolder-cast.md @@ -2,6 +2,6 @@ 📝 Disallow type casting to TFile or TFolder, suggesting instanceof checks instead. -💼 This rule is enabled in the following configs: ✅ `recommended`, 🇬🇧 `recommendedWithLocalesEn`. +💼 This rule is enabled in the following configs: `react`, ✅ `recommended`, 🇬🇧 `recommendedWithLocalesEn`, `svelte`. diff --git a/docs/rules/no-unsupported-api.md b/docs/rules/no-unsupported-api.md index 82e9b62..9983492 100644 --- a/docs/rules/no-unsupported-api.md +++ b/docs/rules/no-unsupported-api.md @@ -2,7 +2,7 @@ 📝 Disallow usage of Obsidian APIs not available in the plugin's minimum app version. -💼 This rule is enabled in the following configs: ✅ `recommended`, 🇬🇧 `recommendedWithLocalesEn`. +💼 This rule is enabled in the following configs: `react`, ✅ `recommended`, 🇬🇧 `recommendedWithLocalesEn`, `svelte`. diff --git a/docs/rules/no-view-references-in-plugin.md b/docs/rules/no-view-references-in-plugin.md index b5ab16f..1b112ff 100644 --- a/docs/rules/no-view-references-in-plugin.md +++ b/docs/rules/no-view-references-in-plugin.md @@ -2,6 +2,6 @@ 📝 Disallow storing references to custom views directly in the plugin, which can cause memory leaks. -💼 This rule is enabled in the following configs: ✅ `recommended`, 🇬🇧 `recommendedWithLocalesEn`. +💼 This rule is enabled in the following configs: `react`, ✅ `recommended`, 🇬🇧 `recommendedWithLocalesEn`, `svelte`. diff --git a/docs/rules/object-assign.md b/docs/rules/object-assign.md index b8a1151..61944c9 100644 --- a/docs/rules/object-assign.md +++ b/docs/rules/object-assign.md @@ -2,6 +2,6 @@ 📝 Discourage using `Object.assign` with two arguments. -💼 This rule is enabled in the following configs: ✅ `recommended`, 🇬🇧 `recommendedWithLocalesEn`. +💼 This rule is enabled in the following configs: `react`, ✅ `recommended`, 🇬🇧 `recommendedWithLocalesEn`, `svelte`. diff --git a/docs/rules/platform.md b/docs/rules/platform.md index aa8ce6f..ed8b47d 100644 --- a/docs/rules/platform.md +++ b/docs/rules/platform.md @@ -2,6 +2,6 @@ 📝 Disallow use of navigator API for OS detection. -💼 This rule is enabled in the following configs: ✅ `recommended`, 🇬🇧 `recommendedWithLocalesEn`. +💼 This rule is enabled in the following configs: `react`, ✅ `recommended`, 🇬🇧 `recommendedWithLocalesEn`, `svelte`. diff --git a/docs/rules/prefer-abstract-input-suggest.md b/docs/rules/prefer-abstract-input-suggest.md index 2093a0c..9493553 100644 --- a/docs/rules/prefer-abstract-input-suggest.md +++ b/docs/rules/prefer-abstract-input-suggest.md @@ -2,6 +2,6 @@ 📝 Disallow Liam's frequently copied `TextInputSuggest` implementation in favor of the built-in `AbstractInputSuggest`. -💼 This rule is enabled in the following configs: ✅ `recommended`, 🇬🇧 `recommendedWithLocalesEn`. +💼 This rule is enabled in the following configs: `react`, ✅ `recommended`, 🇬🇧 `recommendedWithLocalesEn`, `svelte`. diff --git a/docs/rules/prefer-active-doc.md b/docs/rules/prefer-active-doc.md index 9704624..28cb988 100644 --- a/docs/rules/prefer-active-doc.md +++ b/docs/rules/prefer-active-doc.md @@ -2,6 +2,6 @@ 📝 Prefer `activeDocument` over `document` for popout window compatibility. -⚠️ This rule _warns_ in the following configs: ✅ `recommended`, 🇬🇧 `recommendedWithLocalesEn`. +🚫 This rule is _disabled_ in the following configs: `react`, ✅ `recommended`, 🇬🇧 `recommendedWithLocalesEn`, `svelte`. diff --git a/docs/rules/prefer-create-el.md b/docs/rules/prefer-create-el.md index bd40f60..d5dabec 100644 --- a/docs/rules/prefer-create-el.md +++ b/docs/rules/prefer-create-el.md @@ -2,7 +2,7 @@ 📝 Prefer Obsidian DOM helpers (`createEl`, `createDiv`, `createSpan`, `createSvg`, `createFragment`) over native DOM methods. -💼 This rule is enabled in the following configs: ✅ `recommended`, 🇬🇧 `recommendedWithLocalesEn`. +💼 This rule is enabled in the following configs: `react`, ✅ `recommended`, 🇬🇧 `recommendedWithLocalesEn`, `svelte`. 🔧 This rule is automatically fixable by the [`--fix` CLI option](https://eslint.org/docs/latest/user-guide/command-line-interface#--fix). diff --git a/docs/rules/prefer-file-manager-trash-file.md b/docs/rules/prefer-file-manager-trash-file.md index 1791144..582cd38 100644 --- a/docs/rules/prefer-file-manager-trash-file.md +++ b/docs/rules/prefer-file-manager-trash-file.md @@ -2,6 +2,6 @@ 📝 Prefer FileManager.trashFile() over Vault.trash() or Vault.delete() to respect user settings. -⚠️ This rule _warns_ in the following configs: ✅ `recommended`, 🇬🇧 `recommendedWithLocalesEn`. +⚠️ This rule _warns_ in the following configs: `react`, ✅ `recommended`, 🇬🇧 `recommendedWithLocalesEn`, `svelte`. diff --git a/docs/rules/prefer-get-language.md b/docs/rules/prefer-get-language.md index 65aad49..1cc75f3 100644 --- a/docs/rules/prefer-get-language.md +++ b/docs/rules/prefer-get-language.md @@ -2,6 +2,6 @@ 📝 Prefer Obsidian's `getLanguage()` over `localStorage.getItem('language')` and `i18next-browser-languagedetector` for detecting the user's language. -💼 This rule is enabled in the following configs: ✅ `recommended`, 🇬🇧 `recommendedWithLocalesEn`. +💼 This rule is enabled in the following configs: `react`, ✅ `recommended`, 🇬🇧 `recommendedWithLocalesEn`, `svelte`. diff --git a/docs/rules/prefer-instanceof.md b/docs/rules/prefer-instanceof.md index 27b80ec..41ec190 100644 --- a/docs/rules/prefer-instanceof.md +++ b/docs/rules/prefer-instanceof.md @@ -2,7 +2,7 @@ 📝 Prefer `.instanceOf(T)` over `instanceof T` for cross-window safe type checks on DOM Nodes and UIEvents. -💼 This rule is enabled in the following configs: ✅ `recommended`, 🇬🇧 `recommendedWithLocalesEn`. +💼 This rule is enabled in the following configs: `react`, ✅ `recommended`, 🇬🇧 `recommendedWithLocalesEn`, `svelte`. 🔧 This rule is automatically fixable by the [`--fix` CLI option](https://eslint.org/docs/latest/user-guide/command-line-interface#--fix). diff --git a/docs/rules/prefer-window-timers.md b/docs/rules/prefer-window-timers.md index 4993e52..14c6dd1 100644 --- a/docs/rules/prefer-window-timers.md +++ b/docs/rules/prefer-window-timers.md @@ -2,8 +2,6 @@ 📝 Prefer `window.setTimeout()` and related timer functions over bare global calls for popout window compatibility. -💼 This rule is enabled in the following configs: ✅ `recommended`, 🇬🇧 `recommendedWithLocalesEn`. - 🔧 This rule is automatically fixable by the [`--fix` CLI option](https://eslint.org/docs/latest/user-guide/command-line-interface#--fix). diff --git a/docs/rules/regex-lookbehind.md b/docs/rules/regex-lookbehind.md index c7e50d6..4f79ceb 100644 --- a/docs/rules/regex-lookbehind.md +++ b/docs/rules/regex-lookbehind.md @@ -2,7 +2,7 @@ 📝 Using lookbehinds in Regex is not supported in some iOS versions. -💼 This rule is enabled in the following configs: ✅ `recommended`, 🇬🇧 `recommendedWithLocalesEn`. +💼 This rule is enabled in the following configs: `react`, ✅ `recommended`, 🇬🇧 `recommendedWithLocalesEn`, `svelte`. diff --git a/docs/rules/rule-custom-message.md b/docs/rules/rule-custom-message.md index 6382037..a9ba59b 100644 --- a/docs/rules/rule-custom-message.md +++ b/docs/rules/rule-custom-message.md @@ -2,7 +2,7 @@ 📝 Allows redefining error messages from other ESLint rules that don't provide this functionality natively. -💼 This rule is enabled in the following configs: ✅ `recommended`, 🇬🇧 `recommendedWithLocalesEn`. +💼 This rule is enabled in the following configs: `react`, ✅ `recommended`, 🇬🇧 `recommendedWithLocalesEn`, `svelte`. diff --git a/docs/rules/sample-names.md b/docs/rules/sample-names.md index 05ae6a3..6fe1626 100644 --- a/docs/rules/sample-names.md +++ b/docs/rules/sample-names.md @@ -2,6 +2,6 @@ 📝 Rename sample plugin class names. -💼 This rule is enabled in the following configs: ✅ `recommended`, 🇬🇧 `recommendedWithLocalesEn`. +💼 This rule is enabled in the following configs: `react`, ✅ `recommended`, 🇬🇧 `recommendedWithLocalesEn`, `svelte`. diff --git a/docs/rules/settings-tab/no-manual-html-headings.md b/docs/rules/settings-tab/no-manual-html-headings.md index 85a468a..820f357 100644 --- a/docs/rules/settings-tab/no-manual-html-headings.md +++ b/docs/rules/settings-tab/no-manual-html-headings.md @@ -2,7 +2,7 @@ 📝 Disallow using HTML heading elements for settings headings. -💼 This rule is enabled in the following configs: ✅ `recommended`, 🇬🇧 `recommendedWithLocalesEn`. +💼 This rule is enabled in the following configs: `react`, ✅ `recommended`, 🇬🇧 `recommendedWithLocalesEn`, `svelte`. 🔧 This rule is automatically fixable by the [`--fix` CLI option](https://eslint.org/docs/latest/user-guide/command-line-interface#--fix). diff --git a/docs/rules/settings-tab/no-problematic-settings-headings.md b/docs/rules/settings-tab/no-problematic-settings-headings.md index 494b0ff..1949c02 100644 --- a/docs/rules/settings-tab/no-problematic-settings-headings.md +++ b/docs/rules/settings-tab/no-problematic-settings-headings.md @@ -2,7 +2,7 @@ 📝 Discourage anti-patterns in settings headings. -💼 This rule is enabled in the following configs: ✅ `recommended`, 🇬🇧 `recommendedWithLocalesEn`. +💼 This rule is enabled in the following configs: `react`, ✅ `recommended`, 🇬🇧 `recommendedWithLocalesEn`, `svelte`. 🔧 This rule is automatically fixable by the [`--fix` CLI option](https://eslint.org/docs/latest/user-guide/command-line-interface#--fix). diff --git a/docs/rules/ui/sentence-case.md b/docs/rules/ui/sentence-case.md index daeeed6..7e81135 100644 --- a/docs/rules/ui/sentence-case.md +++ b/docs/rules/ui/sentence-case.md @@ -2,7 +2,7 @@ 📝 Enforce sentence case for UI strings. -💼 This rule is enabled in the following configs: ✅ `recommended`, 🇬🇧 `recommendedWithLocalesEn`. +💼 This rule is enabled in the following configs: `react`, ✅ `recommended`, 🇬🇧 `recommendedWithLocalesEn`, `svelte`. 🔧 This rule is automatically fixable by the [`--fix` CLI option](https://eslint.org/docs/latest/user-guide/command-line-interface#--fix). diff --git a/docs/rules/validate-license.md b/docs/rules/validate-license.md index 37f6730..073a518 100644 --- a/docs/rules/validate-license.md +++ b/docs/rules/validate-license.md @@ -2,7 +2,7 @@ 📝 Validate the structure of copyright notices in LICENSE files for Obsidian plugins. -💼 This rule is enabled in the following configs: ✅ `recommended`, 🇬🇧 `recommendedWithLocalesEn`. +💼 This rule is enabled in the following configs: `react`, ✅ `recommended`, 🇬🇧 `recommendedWithLocalesEn`, `svelte`. diff --git a/docs/rules/validate-manifest.md b/docs/rules/validate-manifest.md index 1468e5b..5b0694c 100644 --- a/docs/rules/validate-manifest.md +++ b/docs/rules/validate-manifest.md @@ -2,6 +2,6 @@ 📝 Validate the structure of manifest.json for Obsidian plugins. -💼 This rule is enabled in the following configs: ✅ `recommended`, 🇬🇧 `recommendedWithLocalesEn`. +💼 This rule is enabled in the following configs: `react`, ✅ `recommended`, 🇬🇧 `recommendedWithLocalesEn`, `svelte`. diff --git a/docs/rules/vault/iterate.md b/docs/rules/vault/iterate.md index 886891d..e247d02 100644 --- a/docs/rules/vault/iterate.md +++ b/docs/rules/vault/iterate.md @@ -2,7 +2,7 @@ 📝 Avoid iterating all files to find a file by its path. -💼 This rule is enabled in the following configs: ✅ `recommended`, 🇬🇧 `recommendedWithLocalesEn`. +💼 This rule is enabled in the following configs: `react`, ✅ `recommended`, 🇬🇧 `recommendedWithLocalesEn`, `svelte`. 🔧 This rule is automatically fixable by the [`--fix` CLI option](https://eslint.org/docs/latest/user-guide/command-line-interface#--fix). diff --git a/eslint.config.mjs b/eslint.config.mjs index 8efa0ec..425d5aa 100644 --- a/eslint.config.mjs +++ b/eslint.config.mjs @@ -1,16 +1,16 @@ import obsidianmd from "./dist/lib/index.js"; export default [ - obsidianmd.configs.all, - { - files: ["**/*.ts"], - languageOptions: { - parser: (await import("@typescript-eslint/parser")).default, - ecmaVersion: 2020, - sourceType: "module", - parserOptions: { - project: "./tsconfig.json", - }, - }, - }, + ...obsidianmd.configs.recommended, + { + files: ["**/*.ts"], + languageOptions: { + parser: (await import("@typescript-eslint/parser")).default, + ecmaVersion: 2020, + sourceType: "module", + parserOptions: { + project: "./tsconfig.json", + }, + }, + }, ]; diff --git a/index.d.ts b/index.d.ts index e4d9bcd..f57bae3 100644 --- a/index.d.ts +++ b/index.d.ts @@ -8,6 +8,9 @@ declare module 'eslint-plugin-obsidianmd' { export const configs: { recommended: Linter.Config; recommendedWithLocalesEn: Linter.Config; + packageJson: Linter.Config; + react: Linter.Config; + svelte: Linter.Config; }; export const rules: { [key: string]: Rule.RuleModule; diff --git a/lib/index.ts b/lib/index.ts index 0326a39..a968b22 100644 --- a/lib/index.ts +++ b/lib/index.ts @@ -100,50 +100,58 @@ const plugin = { } as unknown as Record>, configs: { recommended: [] as Config[], - recommendedWithLocalesEn: [] as Config[] + recommendedWithLocalesEn: [] as Config[], + packageJson: [] as Config[], + react: [] as Config[], + svelte: [] as Config[] } } satisfies ESLint.Plugin; -// Rules that require type information (call getParserServices). -// These must only run on files parsed by @typescript-eslint/parser. -const recommendedTypedRulesConfig: RulesConfig = { - "obsidianmd/no-plugin-as-component": "error", - "obsidianmd/no-view-references-in-plugin": "error", - "obsidianmd/no-unsupported-api": "error", - "obsidianmd/prefer-file-manager-trash-file": "warn", - "obsidianmd/prefer-instanceof": "error", +// Rules that don't require TypeScript type information (can apply to JS and TS files) +const recommendedPluginRulesConfigBase: RulesConfig = { + "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/editor-drop-paste": "error", + "obsidianmd/hardcoded-config-path": "error", + "obsidianmd/no-forbidden-elements": "error", + "obsidianmd/no-sample-code": "error", + "obsidianmd/no-tfile-tfolder-cast": "error", + "obsidianmd/no-static-styles-assignment": "error", + "obsidianmd/object-assign": "error", + "obsidianmd/platform": "error", + "obsidianmd/prefer-get-language": "error", + "obsidianmd/prefer-abstract-input-suggest": "error", + "obsidianmd/prefer-active-window-timers": "error", + "obsidianmd/prefer-active-doc": "off", + "obsidianmd/prefer-create-el": "error", + "obsidianmd/regex-lookbehind": "error", + "obsidianmd/sample-names": "error", + "obsidianmd/validate-manifest": "error", + "obsidianmd/validate-license": ["error"], + "obsidianmd/ui/sentence-case": ["error", { enforceCamelCaseLower: true }], }; +// Rules that require TypeScript type information (TypeScript-only) +const recommendedPluginRulesConfigTypeChecked: RulesConfig = { + "obsidianmd/no-plugin-as-component": "error", + "obsidianmd/no-view-references-in-plugin": "error", + "obsidianmd/no-unsupported-api": "error", + "obsidianmd/prefer-file-manager-trash-file": "warn", + "obsidianmd/prefer-instanceof": "error", +}; + +// Combined rules for TypeScript files const recommendedPluginRulesConfig: RulesConfig = { - "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/editor-drop-paste": "error", - "obsidianmd/hardcoded-config-path": "error", - "obsidianmd/no-forbidden-elements": "error", - "obsidianmd/no-global-this": "error", - "obsidianmd/no-plugin-as-component": "error", - "obsidianmd/no-sample-code": "error", - "obsidianmd/no-tfile-tfolder-cast": "error", - "obsidianmd/no-static-styles-assignment": "error", - "obsidianmd/object-assign": "error", - "obsidianmd/platform": "error", - "obsidianmd/prefer-get-language": "error", - "obsidianmd/prefer-abstract-input-suggest": "error", - "obsidianmd/prefer-window-timers": "error", - "obsidianmd/prefer-active-doc": "warn", - "obsidianmd/regex-lookbehind": "error", - "obsidianmd/sample-names": "error", - "obsidianmd/validate-manifest": "error", - "obsidianmd/validate-license": ["error"], - "obsidianmd/ui/sentence-case": ["error", { enforceCamelCaseLower: true }], -} + ...recommendedPluginRulesConfigBase, + ...recommendedPluginRulesConfigTypeChecked, +}; import { restrictedGlobalsOptions, restrictedImportsOptions, noUnusedExpressionsOptions } from "./ruleOptions.js"; @@ -189,97 +197,104 @@ const flatRecommendedGeneralRules: RulesConfig = { }; const flatRecommendedConfig: Config[] = defineConfig([ - js.configs.recommended, - { - plugins: { - obsidianmd: plugin - } - }, - { - plugins: { - import: importPlugin, - "@microsoft/sdl": sdl, - depend, - noUnsanitizedPlugin - }, - files: ['**/*.js', "**/*.jsx"], - extends: [...(tseslint.configs.recommended as Config[]), noUnsanitizedPlugin.configs.recommended], - rules: { - ...flatRecommendedGeneralRules, - ...recommendedPluginRulesConfig - } - }, - { - plugins: { - import: importPlugin, - "@microsoft/sdl": sdl, - depend, - noUnsanitizedPlugin - }, - files: ['**/*.ts', "**/*.tsx"], - extends: [...(tseslint.configs.recommendedTypeChecked as Config[]), noUnsanitizedPlugin.configs.recommended], - rules: { - ...flatRecommendedGeneralRules, - ...recommendedPluginRulesConfig, - ...recommendedTypedRulesConfig - }, - }, - { - files: ['package.json'], - language: 'json/json', - extends: [tseslint.configs.disableTypeChecked as Config], - plugins: { - depend, - json - }, - rules: { - "no-irregular-whitespace": "off", - "depend/ban-dependencies": [ - "error", { - "presets": ["native", "microutilities", "preferred"] - } - ] - } - }, - { - languageOptions: { - globals: { - ...globals.browser, - ...(manifest?.isDesktopOnly ? { - ...globals.node, - NodeJS: "readonly" - } : {}), - DomElementInfo: "readonly", - SvgElementInfo: "readonly", - activeDocument: "readonly", - activeWindow: "readonly", - ajax: "readonly", - ajaxPromise: "readonly", - createDiv: "readonly", - createEl: "readonly", - createFragment: "readonly", - createSpan: "readonly", - createSvg: "readonly", - fish: "readonly", - fishAll: "readonly", - isBoolean: "readonly", - nextFrame: "readonly", - ready: "readonly", - sleep: "readonly" - } - }, - } -]); + // Base ESLint recommended rules + js.configs.recommended, + + // Extract TypeScript plugin and configs for reuse + // TypeScript ESLint's recommendedTypeChecked is an array of 3 configs: + // [0] - Base config with plugin and parser + // [1] - ESLint recommended overrides for TS files + // [2] - TypeScript-specific recommended rules + ...((() => { + const tsConfigs = tseslint.configs.recommendedTypeChecked as any[]; + const tsPlugin = tsConfigs[0].plugins['@typescript-eslint']; + const tsLanguageOptions = tsConfigs[0].languageOptions; + const tsEslintRecommendedRules = tsConfigs[1].rules; + const tsRecommendedRules = tsConfigs[2].rules; + + return [ + // JavaScript files configuration + { + files: ['**/*.js', '**/*.jsx', '**/*.cjs', '**/*.mjs'], + plugins: { + obsidianmd: plugin, + import: importPlugin, + "@microsoft/sdl": sdl, + depend, + "no-unsanitized": noUnsanitizedPlugin, + '@typescript-eslint': tsPlugin + }, + rules: { + ...flatRecommendedGeneralRules, + ...noUnsanitizedPlugin.configs.recommended.rules, + // Only apply base rules (no type-checked rules) for JavaScript + ...recommendedPluginRulesConfigBase + } + }, + + // TypeScript files configuration + // Manually apply TypeScript rules with proper file scoping + { + files: ['**/*.ts', '**/*.tsx', '**/*.mts', '**/*.cts'], + plugins: { + obsidianmd: plugin, + import: importPlugin, + "@microsoft/sdl": sdl, + depend, + "no-unsanitized": noUnsanitizedPlugin, + '@typescript-eslint': tsPlugin + }, + languageOptions: { + ...tsLanguageOptions, + }, + rules: { + ...flatRecommendedGeneralRules, + // Merge TypeScript recommended rules + ...tsEslintRecommendedRules, + ...tsRecommendedRules, + ...noUnsanitizedPlugin.configs.recommended.rules, + // Apply all obsidianmd rules (including type-checked) for TypeScript + ...recommendedPluginRulesConfig + }, + } + ]; + })()), + + // Global language options for JS/TS files + { + files: ['**/*.js', '**/*.jsx', '**/*.cjs', '**/*.mjs', '**/*.ts', '**/*.tsx', '**/*.mts', '**/*.cts'], + languageOptions: { + globals: { + ...globals.browser, + require: "readonly", + ...(manifest?.isDesktopOnly ? { + ...globals.node, + NodeJS: "readonly" + } : {}), + DomElementInfo: "readonly", + SvgElementInfo: "readonly", + activeDocument: "readonly", + activeWindow: "readonly", + ajax: "readonly", + ajaxPromise: "readonly", + createDiv: "readonly", + createEl: "readonly", + createFragment: "readonly", + createSpan: "readonly", + createSvg: "readonly", + fish: "readonly", + fishAll: "readonly", + isBoolean: "readonly", + nextFrame: "readonly", + ready: "readonly", + sleep: "readonly" + } + }, + } +] as any); const hybridRecommendedConfig: Config[] = defineConfig([ - { - rules: recommendedPluginRulesConfig, - extends: flatRecommendedConfig - }, - { - files: ['**/*.ts', '**/*.tsx'], - rules: recommendedTypedRulesConfig - }, + ...flatRecommendedConfig ]); const recommendedWithLocalesEnBase: Config[] = defineConfig([ @@ -328,19 +343,44 @@ const recommendedWithLocalesEnBase: Config[] = defineConfig([ ]); const recommendedWithLocalesEn: Config[] = defineConfig([ - { - rules: recommendedPluginRulesConfig, - extends: recommendedWithLocalesEnBase - }, - { - files: ['**/*.ts', '**/*.tsx'], - rules: recommendedTypedRulesConfig - }, + ...recommendedWithLocalesEnBase +]); + +const packageJsonConfig: Config[] = defineConfig([ + { + files: ['package.json'], + language: 'json/json', + languageOptions: (tseslint.configs.disableTypeChecked as any).languageOptions, + plugins: { + depend, + json + }, + rules: { + ...(tseslint.configs.disableTypeChecked as any).rules, + "no-irregular-whitespace": "off", + "depend/ban-dependencies": [ + "error", { + "presets": ["native", "microutilities", "preferred"] + } + ] + } + }, +]); + +const reactConfig: Config[] = defineConfig([ + ...hybridRecommendedConfig, +]); + +const svelteConfig: Config[] = defineConfig([ + ...hybridRecommendedConfig, ]); plugin.configs = { recommended: hybridRecommendedConfig, - recommendedWithLocalesEn + recommendedWithLocalesEn, + packageJson: packageJsonConfig, + react: reactConfig, + svelte: svelteConfig }; export default plugin; diff --git a/lib/shim.d.ts b/lib/shim.d.ts index c747ba1..695adcd 100644 --- a/lib/shim.d.ts +++ b/lib/shim.d.ts @@ -25,6 +25,19 @@ declare module "eslint-plugin-import" { } +declare module "@eslint/json" { + import type { ESLint } from "eslint"; + const plugin: ESLint.Plugin; + export default plugin; +} + +declare module "eslint-plugin-depend" { + import type { ESLint, Rule } from "eslint"; + const plugin: ESLint.Plugin; + export const rules: Record; + export default plugin; +} + declare module "eslint-plugin-no-unsanitized" { import type { ESLint, Linter, Rule } from "eslint";