Skip to content

Commit

Permalink
Feature: Trim end of line (#190)
Browse files Browse the repository at this point in the history
  • Loading branch information
kyklish committed Jul 31, 2022
1 parent 61aebfe commit f2f1e70
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/providers/formattingProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,11 @@ export class FormatProvider implements vscode.DocumentFormattingEditProvider {
/** The line comment. Empty string if no line comment exists */
const comment = /;.+/.exec(originalLine)?.[0] ?? '';
const formattedLine = originalLine
.replace(/^\s*/, '')
.replace(/;.+/, '')
.replace(/ {2,}/g, ' ')
.concat(comment);
.trim()
.concat(' ' + comment)
.trim();

atTopLevel = true;

Expand Down
1 change: 1 addition & 0 deletions src/test/suite/format/format.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ const formatTests: FormatTest[] = [
{ filenameRoot: '25-multiline-string' },
{ filenameRoot: '58-parentheses-indentation' },
{ filenameRoot: '72-paren-hotkey' },
{ filenameRoot: '189-space-at-end-of-line' },
{ filenameRoot: 'ahk-explorer' },
{ filenameRoot: 'demo' },
{
Expand Down
3 changes: 3 additions & 0 deletions src/test/suite/format/samples/189-space-at-end-of-line.in.ahk
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
; [Issue #189](https://github.com/mark-wiemer/vscode-autohotkey-plus-plus/issues/189)
foo()
foo(a, b) ; comment
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
; [Issue #189](https://github.com/mark-wiemer/vscode-autohotkey-plus-plus/issues/189)
foo()
foo(a, b) ; comment

0 comments on commit f2f1e70

Please sign in to comment.