Skip to content

Commit 0b5e67f

Browse files
committed
fix: Fix formatting of private methods.
1 parent ecd9f12 commit 0b5e67f

File tree

5 files changed

+43
-2
lines changed

5 files changed

+43
-2
lines changed

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
name = "dprint-plugin-typescript"
33
description = "TypeScript code formatting plugin for dprint."
44
keywords = ["formatting", "formatter", "typescript"]
5-
version = "0.28.0"
5+
version = "0.28.1"
66
authors = ["David Sherret <[email protected]>"]
77
edition = "2018"
88
license = "MIT"

src/parsing/parser.rs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@ fn parse_node_with_inner_parse<'a>(node: Node<'a>, context: &mut Context<'a>, in
122122
Node::Constructor(node) => parse_constructor(node, context),
123123
Node::Decorator(node) => parse_decorator(node, context),
124124
Node::TsParamProp(node) => parse_parameter_prop(node, context),
125+
Node::PrivateMethod(node) => parse_private_method(node, context),
125126
Node::PrivateName(node) => parse_private_name(node, context),
126127
Node::PrivateProp(node) => parse_private_prop(node, context),
127128
/* clauses */
@@ -383,6 +384,26 @@ fn parse_node_with_inner_parse<'a>(node: Node<'a>, context: &mut Context<'a>, in
383384
/* class */
384385

385386
fn parse_class_method<'a>(node: &'a ClassMethod, context: &mut Context<'a>) -> PrintItems {
387+
// todo: consolidate with private method
388+
return parse_class_or_object_method(ClassOrObjectMethod {
389+
parameters_span_data: node.get_parameters_span_data(context),
390+
decorators: Some(&node.function.decorators),
391+
accessibility: node.accessibility,
392+
is_static: node.is_static,
393+
is_async: node.function.is_async,
394+
is_abstract: node.is_abstract,
395+
kind: node.kind.into(),
396+
is_generator: node.function.is_generator,
397+
is_optional: node.is_optional,
398+
key: (&node.key).into(),
399+
type_params: node.function.type_params.as_ref().map(|x| x.into()),
400+
params: node.function.params.iter().map(|x| x.into()).collect(),
401+
return_type: node.function.return_type.as_ref().map(|x| x.into()),
402+
body: node.function.body.as_ref().map(|x| x.into()),
403+
}, context);
404+
}
405+
406+
fn parse_private_method<'a>(node: &'a PrivateMethod, context: &mut Context<'a>) -> PrintItems {
386407
return parse_class_or_object_method(ClassOrObjectMethod {
387408
parameters_span_data: node.get_parameters_span_data(context),
388409
decorators: Some(&node.function.decorators),

src/parsing/parser_types.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -711,6 +711,12 @@ impl ParametersSpanned for Function {
711711
}
712712
}
713713

714+
impl ParametersSpanned for PrivateMethod {
715+
fn get_parameters_span_data(&self, context: &mut Context) -> Option<Span> {
716+
self.function.get_parameters_span_data(context)
717+
}
718+
}
719+
714720
impl ParametersSpanned for ClassMethod {
715721
fn get_parameters_span_data(&self, context: &mut Context) -> Option<Span> {
716722
self.function.get_parameters_span_data(context)
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
~~ lineWidth: 50 ~~
2+
== should format private methods ==
3+
abstract class Test {
4+
#method1( arg : string ) : test {
5+
return 5 ;
6+
}
7+
}
8+
9+
[expect]
10+
abstract class Test {
11+
#method1(arg: string): test {
12+
return 5;
13+
}
14+
}

0 commit comments

Comments
 (0)