platers / obsidian-linter

An Obsidian plugin that formats and styles your notes with a focus on configurability and extensibility.
https://platers.github.io/obsidian-linter/
MIT License
1.24k stars 81 forks source link

FR: Enable Linter to Run on Files That Are Not Currently Open in Obsidian #1137

Open AucklandIO opened 3 months ago

AucklandIO commented 3 months ago

Description:

As an active user of the Obsidian Linter plugin, I find its functionality essential for maintaining consistency and cleanliness in my notes. However, I am encountering a significant limitation in the current implementation in my personal workflow: the Linter can only run on files that are currently open in the editor.

Feature Request:

I would like to request the addition of a feature that allows the Linter to run on files that are not currently open in Obsidian. This functionality would greatly enhance the usability of the plugin, particularly in workflows where batch processing or automated formatting is required.

Use Cases:

_Automated Note Cleanup:_
    Users often have large collections of notes that need consistent formatting. Being able to run the Linter on a selection of files without opening each one individually would save considerable time and effort.

_Background Linting:_
    In scenarios where notes are updated programmatically or through automation tools, the ability to lint those files in the background (without needing to open them) would ensure that all notes adhere to the user's formatting rules without manual intervention.

_Macro Integration:_
    Users who utilize plugins like QuickAdd could include linting as part of their automated workflows, applying Linter rules to files as they are created or modified, even if those files are not open at the time.

Proposed Implementation:

Introduce a new command or API endpoint that allows users to specify a file or a set of files (by path, pattern, or filename template for automated file creation tasks) to be linted without opening them in the editor.
This could be integrated into Obsidian’s command palette, making it easily accessible for users who prefer to run Linter across multiple files in one go.

Conclusion:

This enhancement would align with the plugin’s goal of maintaining note consistency and would significantly improve the efficiency of the note-taking and management process within Obsidian. I believe this feature would be a valuable addition to the Linter plugin and would greatly benefit many users in the community.

Thank you for considering this feature request. I look forward to any feedback or discussion on its feasibility.

If you have any further questions about my particular use case, please feel free to reach out for details!

pjkaufman commented 3 months ago

Hey @AucklandIO .Could you elaborate on what you mean by allowing files to be linted when they are not currently open in a vault? I ask because currently you can lint a specific file that is not open via the context menu when you right click in the file explorer and the same is possible for linting a folder.

There is also the ability to lint the whole vault if you so choose.

AucklandIO commented 3 months ago

I am so sorry, I didn't realize this was already a feature, as I was led to believe it wasn't. Is it possible to bind this to a command? I ask because I want to add it to a Quickadd macro that lints the specific file the macro interacts with in order to clean it up when the macro adds some formatting I can't excise from the command and I don't want to have to open it or manually lint it after every commitment (this is for automating my journaling/task creation/logging etc).

The key point is I want to be able to inject the name of the file (which has automated creation in certain circumstances (for instance, when a new month is detected, a new overall task/log file is created) and I would like to make sure I can template the file to lint based on that macro and some scripting.

pjkaufman commented 3 months ago

I am so sorry, I didn't realize this was already a feature, as I was led to believe it wasn't. Is it possible to bind this to a command? I ask because I want to add it to a Quickadd macro that lints the specific file the macro interacts with in order to clean it up when the macro adds some formatting I can't excise from the command and I don't want to have to open it or manually lint it after every commitment (this is for automating my journaling/task creation/logging etc).

The key point is I want to be able to inject the name of the file (which has automated creation in certain circumstances (for instance, when a new month is detected, a new overall task/log file is created) and I would like to make sure I can template the file to lint based on that macro and some scripting.

I am not sure that it works for the use case in question. I am saying this because I may not fully grasp the problem you are trying to solve. If you are trying to have the Linter run on a specific file, that is feasible when it is the active file or you use the right click context menu. However it is not feasible at this time to specify which file to lint via a name/path or something of the sort.

Now it is feasible to add something like this, however I am not sure I would know how to implement this. I do know how to convert a file path into a TFile which is needed for the Linter to be able to run on a file. However I am not sure how this works with Obsidian commands since I am not aware of how Obsidian commands take arbitrary parameters. Could you point to an example of an Obsidian command that currently operates this way? Or could you explain how the Linter would know which file to update when the Obsidian command is run?

Also, is the expectation that the operation would be synchronous? I ask because I am pretty sure the current way files are linted is asynchronous and there are plans to move linting to a web worker to make it faster which would mean that there is not an easy way to run things synchronously.

Thanks for humoring me as I try to flush out what exactly this would look like assuming this kind of functionality were to be added.