Skip to content

Commit 0a5304b

Browse files
author
Soc Sieng
committed
Fix custom indents for type literal signatures
1 parent d474f4f commit 0a5304b

File tree

5 files changed

+24
-3
lines changed

5 files changed

+24
-3
lines changed

src/render/reflection-formatter.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ export const sortMapping: { [key: string]: ReflectionSortFlags | undefined } = {
2525

2626
export default class ReflectionFormatter {
2727
public static sortOption: ReflectionSortFlags = ReflectionSortFlags.none;
28-
public static indentString: string = ' ';
2928

3029
public render(reflection?: Reflection, terminatorCharacter?: string): string {
3130
if (reflection) {

src/render/type-literal-renderer.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ export default class TypeLiteralRenderer extends ContainerRenderer {
3333
let signature = ReflectionFormatter.instance().render(member.signatures[0]);
3434
if (indent) {
3535
lines.push('');
36-
signature = signature.split('\n').map(l => ` ${l}`).join('\n');
36+
signature = signature.split('\n').map(l => `${this._indentor.getIndent(1)}${l}`).join('\n');
3737
}
3838
lines.push(signature);
3939
} else if (member.name === '__type') {

tests/dynamic-tests.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import Version from '../src/util/version';
1313
import VersionFilter from '../src/convert/version-filter';
1414
import glob from 'glob';
1515
import mkdir from 'make-dir';
16+
import Indentor from '../src/render/indentor';
1617

1718
const writeOutput = process.env['DEBUG_MODE'] !== 'none';
1819

@@ -55,8 +56,12 @@ describe('Dynamic test suite', () => {
5556
const basename = testFile.replace(/(input|exact)(\.d)?\.ts$/i, '');
5657
const expectedFile = /exact\.d\.ts$/i.test(testFile) ? testFile : `${basename}expected.d.ts`;
5758
const expectedOutput = fs.readFileSync(path.join(__dirname, expectedFile), 'utf8');
59+
const optionsFile = path.join(__dirname, `${basename}options.json`);
60+
const options = fs.existsSync(optionsFile) ? JSON.parse(fs.readFileSync(optionsFile, 'utf8')) : null;
61+
62+
ReflectionFormatter.sortOption = options?.sort ?? ReflectionSortFlags.tag;
63+
Indentor.indentString = options?.indentString ?? ' ';
5864

59-
ReflectionFormatter.sortOption = ReflectionSortFlags.tag;
6065
const formatter = ReflectionFormatter.instance();
6166

6267
if (project) {
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
declare namespace IndentHandlers {
2+
type MyUncommentedHandler = (foo: any) => any;
3+
4+
/**
5+
* My comment
6+
*/
7+
type MyCommentedHandler =
8+
/**
9+
* Handler comment
10+
*
11+
* @param foo can be anything
12+
*/
13+
(foo: any) => any;
14+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"indentString": " "
3+
}

0 commit comments

Comments
 (0)