Skip to content

Commit

Permalink
feat: use thrift-lab format
Browse files Browse the repository at this point in the history
  • Loading branch information
Dup4 committed Sep 26, 2022
1 parent 8451547 commit cdb0df9
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 4 deletions.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@
"vitest": "^0.7.13"
},
"dependencies": {
"thrift-fmt-ts": "1.1.2-a1"
"thrift-fmt-ts": "1.1.2-a1",
"thrift-parser-ts": "1.0.6-a1"
}
}
2 changes: 2 additions & 0 deletions pnpm-lock.yaml

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

11 changes: 11 additions & 0 deletions src/internal/ThriftFormatter.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
/* eslint-disable @typescript-eslint/no-unused-vars */
import { ThriftData } from "thrift-parser-ts";
import { PureThriftFormatter } from "thrift-fmt-ts";

import { IOptions } from "../types";

class Options implements IOptions {
Expand Down Expand Up @@ -30,10 +33,18 @@ class ThriftFormatter {
}

public format(content: string): string {
content = this.labFormat(content);
content = this.deleteExtraEmptyLines(content);
return content;
}

private labFormat(content: string): string {
const data = ThriftData.from_string(content);
const fmt = new PureThriftFormatter();
const afterFormatContent = fmt.format_node(data.document);
return afterFormatContent;
}

private deleteExtraEmptyLines(content: string): string {
const c = this.splitByLine(content);
const res: string[] = [];
Expand Down
5 changes: 2 additions & 3 deletions test/__snapshots__/format.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ exports[`should > exported 1`] = `
}
struct B {
1: required string b,
}
"
1: required string b,
}"
`;

0 comments on commit cdb0df9

Please sign in to comment.