chore: add option to run Obsidian Linter before formatting

This commit is contained in:
Kodai Nakamura 2025-11-28 00:36:50 +09:00
parent 72be0ca238
commit 39a2c418ed
3 changed files with 24 additions and 4 deletions

View file

@ -378,10 +378,13 @@ export default class AutomaticLinkerPlugin extends Plugin {
if (checking) {
return saveCallback?.(checking);
} else {
//@ts-expect-error
await this.app?.commands?.executeCommandById(
"obsidian-linter:lint-file",
);
// Run Obsidian Linter before formatting if enabled
if (this.settings.runLinterBeforeFormatting) {
//@ts-expect-error
await this.app?.commands?.executeCommandById(
"obsidian-linter:lint-file",
);
}
await this.formatOnSave();
}
};

View file

@ -18,6 +18,7 @@ export type AutomaticLinkerSettings = {
excludeDirsFromAutoLinking: string[]; // Optional: List of directories to exclude from auto-linking
preventSelfLinking: boolean; // Prevent linking text to its own file
removeAliasInDirs: string[]; // Remove aliases for links in specified directories
runLinterBeforeFormatting: boolean; // Run Obsidian Linter before automatic linker formatting
};
export const DEFAULT_SETTINGS: AutomaticLinkerSettings = {
@ -40,4 +41,5 @@ export const DEFAULT_SETTINGS: AutomaticLinkerSettings = {
excludeDirsFromAutoLinking: [], // Default: no excluded directories
preventSelfLinking: false, // Default: allow self-linking (backward compatibility)
removeAliasInDirs: [], // Default: no directories for alias removal
runLinterBeforeFormatting: false, // Default: do not run linter before formatting
};

View file

@ -29,6 +29,21 @@ export class AutomaticLinkerPluginSettingsTab extends PluginSettingTab {
});
});
// Toggle for running linter before formatting
new Setting(containerEl)
.setName("Run Obsidian Linter before formatting")
.setDesc(
"When enabled, Obsidian Linter will be executed before Automatic Linker formatting. This requires the Obsidian Linter plugin to be installed.",
)
.addToggle((toggle) => {
toggle
.setValue(this.plugin.settings.runLinterBeforeFormatting)
.onChange(async (value) => {
this.plugin.settings.runLinterBeforeFormatting = value;
await this.plugin.saveData(this.plugin.settings);
});
});
// Setting for base directories.
new Setting(containerEl)
.setName("Base directory")