Skip to content
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

FR: Option for Line Break at Document End to ignore empty files #1228

Closed
jose-elias-alvarez opened this issue Nov 23, 2024 · 4 comments · Fixed by #1229
Closed

FR: Option for Line Break at Document End to ignore empty files #1228

jose-elias-alvarez opened this issue Nov 23, 2024 · 4 comments · Fixed by #1229
Assignees
Labels
markdown General Markdown or Markdown related issue or feature resolution/update-made A change has been made that should resolve this issue or request rule suggestion Suggestion to add or edit a rule

Comments

@jose-elias-alvarez
Copy link
Contributor

jose-elias-alvarez commented Nov 23, 2024

Is Your Feature Request Related to a Problem? Please Describe.

I use the Line Break at Document End option, but I find its behavior annoying in one specific case: when linting an empty file, it adds a new line, meaning that the file is no longer empty. I lint files on document save and on focused file change, so this means that whenever I edit an empty file, even for a second, it ends up containing a single line break.

The current behavior is consistent with the rule description, but apart from the annoyance of having to remove the line when I don't want it, it's also convenient to keep empty files truly empty, since it makes it easy to find them by querying the file system (or Dataview) for files that are 0B in size.

To replicate: enable the Line Break at Document End option, create an empty note, lint it, then check its file size:

ls -lh empty.md | awk '{print $5}' # 1B

Describe the Solution You'd Like

An option to disable the rule on empty files. (Since the option is a toggle, I don't know if a new option would have to be added or if the existing rule can be adapted.)

I’m happy to put in a PR if there’s agreement on a direction.

Describe Alternatives You've Considered

I can of course tweak my search to instead find files that are 1 byte in size, but that's less convenient, inconsistent with other methods of finding empty files, and could also lead to false positives.

I could also disable the specific setting and / or only lint on demand, but this setup works as I want 99% of the time, so that would not be ideal, either.

Additional Context

For comparison, formatters such as Prettier do not add a line break to empty files:

touch empty.js && prettier --log-level=silent --write empty.js && ls -lh empty.js | awk '{print $5}' # 0B

(Also, apologies if there's already an issue about this – it's very hard to search given the sheer number of open issues and the fact that many issues contain debug output.)

@jose-elias-alvarez jose-elias-alvarez added the rule suggestion Suggestion to add or edit a rule label Nov 23, 2024
@pjkaufman
Copy link
Collaborator

Hey @jose-elias-alvarez , thanks for the feedback. I am thinking that this should be fine to integrate into the logic of the existing rule. I was originally thinking that it should be a separate option to prevent a change in user space, but this seems like an edge case where people would not want this to happen. If they do want this to happen, I can see about adding an option to do so down the road.

@pjkaufman pjkaufman self-assigned this Nov 23, 2024
@pjkaufman pjkaufman added the markdown General Markdown or Markdown related issue or feature label Nov 23, 2024
@pjkaufman pjkaufman moved this from Backlog to In Progress in Obsidian Linter Nov 23, 2024
@pjkaufman
Copy link
Collaborator

I have a fix for this that is ready to go. I will see about making a PR and getting it merged.

@pjkaufman
Copy link
Collaborator

The change for this should be on master and go out in the next release. Please let us know if there are issues with it.

@pjkaufman pjkaufman added the resolution/update-made A change has been made that should resolve this issue or request label Nov 23, 2024
@jose-elias-alvarez
Copy link
Contributor Author

Awesome, thanks @pjkaufman!

@pjkaufman pjkaufman moved this from In Next Release to Released in Obsidian Linter Dec 24, 2024
@pjkaufman pjkaufman moved this from Released to Previous Release in Obsidian Linter Feb 13, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
markdown General Markdown or Markdown related issue or feature resolution/update-made A change has been made that should resolve this issue or request rule suggestion Suggestion to add or edit a rule
Projects
Status: Previous Release
2 participants