Skip to content

Commit

Permalink
Fixed spacing for anon subs
Browse files Browse the repository at this point in the history
Fixes #1686
  • Loading branch information
hurricup committed Dec 28, 2017
1 parent 043cad3 commit e6ac565
Show file tree
Hide file tree
Showing 11 changed files with 57 additions and 104 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public interface PerlFormattingTokenSets extends PerlElementTypes {
TokenSet SUB_DEFINITIONS_TOKENSET = TokenSet.create(
METHOD_DEFINITION,
FUNC_DEFINITION,

SUB_EXPR,
SUB_DEFINITION,
SUB_DECLARATION
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,15 +54,13 @@ static SpacingBuilder createSpacingBuilder(CommonCodeStyleSettings settings, Per
.between(PACKAGE, VERSION_ELEMENT).spaces(1)
.between(RESERVED_FORMAT, SUB_NAME).spaces(1)

.betweenInside(SUB_NAME, LEFT_PAREN, SUB_DEFINITION).spaceIf(settings.SPACE_BEFORE_METHOD_PARENTHESES)
.betweenInside(SUB_NAME, LEFT_PAREN, SUB_DECLARATION).spaceIf(settings.SPACE_BEFORE_METHOD_PARENTHESES)
.betweenInside(SUB_NAME, LEFT_PAREN, METHOD_DEFINITION).spaceIf(settings.SPACE_BEFORE_METHOD_PARENTHESES)
.betweenInside(SUB_NAME, LEFT_PAREN, FUNC_DEFINITION).spaceIf(settings.SPACE_BEFORE_METHOD_PARENTHESES)
.beforeInside(LEFT_PAREN, SUB_DEFINITIONS_TOKENSET).spaceIf(settings.SPACE_BEFORE_METHOD_PARENTHESES)

.betweenInside(LEFT_PAREN, RIGHT_PAREN, SUB_DEFINITION).spaceIf(settings.SPACE_WITHIN_EMPTY_METHOD_PARENTHESES)
.betweenInside(LEFT_PAREN, RIGHT_PAREN, SUB_DECLARATION).spaceIf(settings.SPACE_WITHIN_EMPTY_METHOD_PARENTHESES)
.betweenInside(LEFT_PAREN, RIGHT_PAREN, METHOD_DEFINITION).spaceIf(settings.SPACE_WITHIN_EMPTY_METHOD_PARENTHESES)
.betweenInside(LEFT_PAREN, RIGHT_PAREN, FUNC_DEFINITION).spaceIf(settings.SPACE_WITHIN_EMPTY_METHOD_PARENTHESES)
.betweenInside(LEFT_PAREN, RIGHT_PAREN, SUB_EXPR).spaceIf(settings.SPACE_WITHIN_EMPTY_METHOD_PARENTHESES)

.afterInside(LEFT_PAREN, SUB_DEFINITIONS_TOKENSET).spaceIf(settings.SPACE_WITHIN_METHOD_PARENTHESES)
.beforeInside(RIGHT_PAREN, SUB_DEFINITIONS_TOKENSET).spaceIf(settings.SPACE_WITHIN_METHOD_PARENTHESES)
Expand Down
17 changes: 6 additions & 11 deletions testData/formatter/perl/spacing/declarations.code
Original file line number Diff line number Diff line change
Expand Up @@ -15,25 +15,20 @@ sub subname ( $a
method subname ( $a , $b , $c ) {}
func subname ( $a , $b , $c ) {}
sub something ( ) : method : other : something { }

sub something ( ) : method : other : something;

method something ( ) : method : other : something { }

func something ( ) : method : other : something { }

my $var : method : other : something;

my ( $var1, $var2, $var3) : method : other : something;

sub so ( ) : me : ot : so { }

sub so ( ) : me : ot : so ;

method so ( ) : me : ot : so { }

func so ( ) : me : ot : so { }

my $var : me : ot : so ;

my ( $v1, $v2, $v3 ) : me : ot : so ;
sub { };
sub ( ) { };
sub ( $var ) { };
sub : method { };
sub ( ) : method { };
sub ( $var ) : method { };
Original file line number Diff line number Diff line change
Expand Up @@ -15,25 +15,20 @@ sub subname($a, $b, $c) {}
method subname($a, $b, $c) {}
func subname($a, $b, $c) {}
sub something():method:other:something {}

sub something():method:other:something;

method something():method:other:something {}

func something():method:other:something {}

my $var:method:other:something;

my ($var1, $var2, $var3):method:other:something;

sub so():me:ot:so {}

sub so():me:ot:so;

method so():me:ot:so {}

func so():me:ot:so {}

my $var:me:ot:so;

my ($v1, $v2, $v3):me:ot:so;
sub {};
sub() {};
sub($var) {};
sub:method {};
sub():method {};
sub($var):method {};
Original file line number Diff line number Diff line change
Expand Up @@ -15,25 +15,20 @@ sub subname($a, $b, $c) {}
method subname($a, $b, $c) {}
func subname($a, $b, $c) {}
sub something() :method :other :something {}

sub something() :method :other :something;

method something() :method :other :something {}

func something() :method :other :something {}

my $var :method :other :something;

my ($var1, $var2, $var3) :method :other :something;

sub so() :me :ot :so {}

sub so() :me :ot :so;

method so() :me :ot :so {}

func so() :me :ot :so {}

my $var :me :ot :so;

my ($v1, $v2, $v3) :me :ot :so;
sub {};
sub() {};
sub($var) {};
sub :method {};
sub() :method {};
sub($var) :method {};
Original file line number Diff line number Diff line change
Expand Up @@ -15,25 +15,20 @@ sub subname($a, $b, $c) {}
method subname($a, $b, $c) {}
func subname($a, $b, $c) {}
sub something() :method :other :something {}

sub something() :method :other :something;

method something() :method :other :something {}

func something() :method :other :something {}

my $var :method :other :something;

my ($var1, $var2, $var3) :method :other :something;

sub so() :me :ot :so {}

sub so() :me :ot :so;

method so() :me :ot :so {}

func so() :me :ot :so {}

my $var :me :ot :so;

my ($v1, $v2, $v3) :me :ot :so;
sub {};
sub() {};
sub($var) {};
sub :method {};
sub() :method {};
sub($var) :method {};
Original file line number Diff line number Diff line change
Expand Up @@ -15,25 +15,20 @@ sub subname ($a, $b, $c) {}
method subname ($a, $b, $c) {}
func subname ($a, $b, $c) {}
sub something () :method :other :something {}

sub something () :method :other :something;

method something () :method :other :something {}

func something () :method :other :something {}

my $var :method :other :something;

my ($var1, $var2, $var3) :method :other :something;

sub so () :me :ot :so {}

sub so () :me :ot :so;

method so () :me :ot :so {}

func so () :me :ot :so {}

my $var :me :ot :so;

my ($v1, $v2, $v3) :me :ot :so;
sub {};
sub () {};
sub ($var) {};
sub :method {};
sub () :method {};
sub ($var) :method {};
Original file line number Diff line number Diff line change
Expand Up @@ -15,25 +15,20 @@ sub subname($a, $b, $c) {}
method subname($a, $b, $c) {}
func subname($a, $b, $c) {}
sub something() :method :other :something {}

sub something() :method :other :something;

method something() :method :other :something {}

func something() :method :other :something {}

my $var :method :other :something;

my ($var1, $var2, $var3) :method :other :something;

sub so() :me :ot :so {}

sub so() :me :ot :so;

method so() :me :ot :so {}

func so() :me :ot :so {}

my $var :me :ot :so;

my ($v1, $v2, $v3) :me :ot :so;
sub {};
sub() {};
sub($var) {};
sub :method {};
sub() :method {};
sub($var) :method {};
Original file line number Diff line number Diff line change
Expand Up @@ -15,25 +15,20 @@ sub subname($a, $b, $c) {}
method subname($a, $b, $c) {}
func subname($a, $b, $c) {}
sub something( ) :method :other :something {}

sub something( ) :method :other :something;

method something( ) :method :other :something {}

func something( ) :method :other :something {}

my $var :method :other :something;

my ($var1, $var2, $var3) :method :other :something;

sub so( ) :me :ot :so {}

sub so( ) :me :ot :so;

method so( ) :me :ot :so {}

func so( ) :me :ot :so {}

my $var :me :ot :so;

my ($v1, $v2, $v3) :me :ot :so;
sub {};
sub( ) {};
sub($var) {};
sub :method {};
sub( ) :method {};
sub($var) :method {};
Original file line number Diff line number Diff line change
Expand Up @@ -15,25 +15,20 @@ sub subname($a, $b, $c) {}
method subname($a, $b, $c) {}
func subname($a, $b, $c) {}
sub something() :method :other :something {}

sub something() :method :other :something;

method something() :method :other :something {}

func something() :method :other :something {}

my $var :method :other :something;

my ($var1, $var2, $var3) :method :other :something;

sub so() :me :ot :so {}

sub so() :me :ot :so;

method so() :me :ot :so {}

func so() :me :ot :so {}

my $var :me :ot :so;

my ($v1, $v2, $v3) :me :ot :so;
sub {};
sub() {};
sub($var) {};
sub :method {};
sub() :method {};
sub($var) :method {};
Original file line number Diff line number Diff line change
Expand Up @@ -15,25 +15,20 @@ sub subname( $a, $b, $c ) {}
method subname( $a, $b, $c ) {}
func subname( $a, $b, $c ) {}
sub something() :method :other :something {}

sub something() :method :other :something;

method something() :method :other :something {}

func something() :method :other :something {}

my $var :method :other :something;

my ($var1, $var2, $var3) :method :other :something;

sub so() :me :ot :so {}

sub so() :me :ot :so;

method so() :me :ot :so {}

func so() :me :ot :so {}

my $var :me :ot :so;

my ($v1, $v2, $v3) :me :ot :so;
sub {};
sub() {};
sub( $var ) {};
sub :method {};
sub() :method {};
sub( $var ) :method {};

0 comments on commit e6ac565

Please sign in to comment.