Skip to content

Commit

Permalink
fix: don't replace nonwhitespace characters
Browse files Browse the repository at this point in the history
  • Loading branch information
danielpza authored May 1, 2021
1 parent 7b1e152 commit 033ce15
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 6 deletions.
7 changes: 1 addition & 6 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -223,12 +223,7 @@ function formatCode(
.every((v) => !v.trim() || v.startsWith(beginningSpace))
) {
result = result.replace(
new RegExp(
`\n${beginningSpace
.replace(/[\t]/g, "[\\t]")
.replace(/[^S\r\n]/g, "[^S\\r\\n]")}`,
"g",
),
new RegExp(`\n${beginningSpace.replace(/[\t]/g, "[\\t]")}`, "g"),
"\n",
);
}
Expand Down
10 changes: 10 additions & 0 deletions tests/__snapshots__/main.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -374,6 +374,16 @@ exports[`example 1`] = `
"
`;
exports[`example with tab intention 1`] = `
"/**
* @example
* function Hello() {
* console.log(\\"Hello World\\");
* }
*/
"
`;
exports[`jsdoc tags 1`] = `
"/**
* @namespace
Expand Down
28 changes: 28 additions & 0 deletions tests/main.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -626,3 +626,31 @@ test("example ", () => {

expect(subject(subject(result2))).toMatchSnapshot();
});

test("example with tab intention", () => {
const result2 = subject(
`
/**
* @example
* function Hello() {
* console.log("Hello World");
* }
*/
`,
{
useTabs: true,
},
);

expect(
subject(
subject(result2, {
useTabs: true,
}),
{
useTabs: true,
},
),
).toMatchSnapshot();
});

0 comments on commit 033ce15

Please sign in to comment.