Skip to content

Commit 5063adb

Browse files
authored
Merge pull request #1229 from pjkaufman/master
Feat: `Line Break at Document End` No Longer Adds Blank Line at End of Empty Notes
2 parents e4f7b6a + fc068d6 commit 5063adb

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

src/lang/locale/en.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -510,7 +510,7 @@ export default {
510510
// line-break-at-document-end.ts
511511
'line-break-at-document-end': {
512512
'name': 'Line Break at Document End',
513-
'description': 'Ensures that there is exactly one line break at the end of a document.',
513+
'description': 'Ensures that there is exactly one line break at the end of a document if the note is not empty.',
514514
},
515515
// move-footnotes-to-the-bottom.ts
516516
'move-footnotes-to-the-bottom': {

src/rules/line-break-at-document-end.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@ export default class LineBreakAtDocumentEnd extends RuleBuilder<LineBreakAtDocum
1717
return LineBreakAtDocumentEndOptions;
1818
}
1919
apply(text: string, options: LineBreakAtDocumentEndOptions): string {
20+
if (text.length === 0) {
21+
return text;
22+
}
23+
2024
text = text.replace(/\n+$/g, '');
2125
text += '\n';
2226
return text;
@@ -46,6 +50,11 @@ export default class LineBreakAtDocumentEnd extends RuleBuilder<LineBreakAtDocum
4650
${''}
4751
`,
4852
}),
53+
new ExampleBuilder({ // https://github.com/platers/obsidian-linter/issues/1228
54+
description: 'Empty files will not have a blank line added',
55+
before: dedent``,
56+
after: dedent``,
57+
}),
4958
];
5059
}
5160
get optionBuilders(): OptionBuilderBase<LineBreakAtDocumentEndOptions>[] {

0 commit comments

Comments
 (0)