Skip to content

Commit

Permalink
Merge pull request #134 from netux/feature/xml-formatter-preserve-new…
Browse files Browse the repository at this point in the history
…line

Preserve new lines of documents formatted via the XMLFormatter
  • Loading branch information
iljapostnovs authored Oct 10, 2023
2 parents 2d8f11e + 7ecb8d7 commit 21a941b
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 4 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 1.11.0 (10-10-2023)

- Make XML Formatter preserve newlines

## 1.10.0 (08-10-2023)

- `--tagSpaceBeforeSelfClose` option added to XML Formatter
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ui5plugin-linter",
"version": "1.10.0",
"version": "1.11.0",
"description": "UI5 Class linter",
"main": "dist/index.js",
"scripts": {
Expand Down
8 changes: 7 additions & 1 deletion src/classes/formatter/xml/XMLFormatter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@ export class XMLFormatter {
return;
}

const documentNewline = document.getText()
.match(/\r?\n/)?.[0] ?? "\n";
const documentNewlineEnding = document.getText()
.slice(-2)
.match(/\r?\n$/)?.[0] ?? "";

let indentationLevel = 0;
const formattedTags = allTags
.map(currentTag => {
Expand All @@ -36,7 +42,7 @@ export class XMLFormatter {
})
.reduce(this._removeUnnecessaryTags.bind(this), []);

return formattedTags.join("\n");
return formattedTags.join(documentNewline) + documentNewlineEnding;
}

private _removeUnnecessaryTags(accumulator: string[], currentTag: string): string[] {
Expand Down

0 comments on commit 21a941b

Please sign in to comment.