Skip to content

Commit

Permalink
refactor: use trim instead
Browse files Browse the repository at this point in the history
  • Loading branch information
so1ve committed Nov 27, 2023
1 parent 6c942f0 commit 706abde
Showing 1 changed file with 1 addition and 8 deletions.
9 changes: 1 addition & 8 deletions packages/toml/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,6 @@ async function format(code: string, options: TaploOptions) {
return taplo.format(code, { options })
}

function removeBeginningTrailingNewline(code: string) {
code = code.replace(/^(?:\r?\n)+/, '')
code = code.replace(/(?:\r?\n)+$/, '')

return code
}

const TomlPlugin: Plugin<string> = {
languages,
parsers: {
Expand All @@ -33,7 +26,7 @@ const TomlPlugin: Plugin<string> = {
? '\t'

Check warning on line 26 in packages/toml/src/index.ts

View check run for this annotation

Codecov / codecov/patch

packages/toml/src/index.ts#L26

Added line #L26 was not covered by tests
: ' '.repeat(options.tabWidth)

return await format(removeBeginningTrailingNewline(code), {
return await format(code.trim(), {
...options,
columnWidth: options.printWidth,
indentString,
Expand Down

0 comments on commit 706abde

Please sign in to comment.