Skip Menu |

This queue is for tickets about the Perl-Tidy CPAN distribution.

Report information
The Basics
Id: 128280
Status: resolved
Priority: 0/
Queue: Perl-Tidy

People
Owner: Nobody in particular
Requestors: jidanni [...] jidanni.org
Cc:
AdminCc:

Bug Information
Severity: Unimportant
Broken in: 20180220
Fixed in: (no value)



Subject: --add-semicolons vs. one-line blocks
We read, -asc, --add-semicolons Setting -asc allows perltidy to add any missing optional semicolon at the end of a line which is followed by a closing curly brace on the next line. This is the default, and may be deactivated with -nasc or --noadd-semicolons. ^^^^^^^^^^^^^^^^^^^^^^ OK, but no consideration is given for: One-line blocks If an existing one-line block is longer than the maximum line length, however, it will be broken into multiple lines. When this happens, perltidy checks for and adds any optional terminating semicolon (unless the -nasc option is used) if the block is a code block. In other words the only way a one line blocks will never have their semicolons added! I propose "brace on the next line" behavior be changed to "brace on the same or next line".
Show quoted text
> In other words the only way a one line blocks will never have their > semicolons added
currently is doing it with ones keyboard!
So the problem is, how can we get perltidy to add semicolons into a one-line block when they are missing, without breaking the one-line block. The suggested modification would change how perltidy behaves on all existing scripts, so it cannot be made. The default behavior approximately follows the ‘perlstyle’ doc, which says “Semicolon omitted in "short" one-line BLOCK” where “short” is left undefined. A new flag which defines “short” would solve the problem. This seems simple but it isn’t completely straightforward, because "short" is probably best defined as number of tokens, or something similar, rather than as a line length. A simpler alternative would be to make it a binary all-or-none switch. I’m not sure if this is worth the programming effort, but I will consider it if there is enough interest. Meanwhile, a crude workaround for adding semicolons to one-line blocks, without breaking them, is cat infile > perltidy -l=10 -npro | perltidy –noadd-newlines –npro | perltidy >outfile where the 10 defines “short” as a total line length. This breaks the one-line blocks, adds the semicolons, and then reforms them and finally reformats. The -npro prevents reading any .perltidyrc file, and the –noadd-newlines reconstructs one-line blocks. This might have undesirable side-effects on a complete file, such as making more one-line blocks than desired, but it could be done as a macro within an editor and applied to selected sections of code.
Maybe just add an (yes, ugly) new flag: --add-semicolons-for-one-line-blocks .
Subject: Re: [rt.cpan.org #128280] --add-semicolons vs. one-line blocks
Date: Sun, 20 Jan 2019 09:21:47 +0800
To: "Steve Hancock via RT" <bug-Perl-Tidy [...] rt.cpan.org>
From: 積丹尼 Dan Jacobson <jidanni [...] jidanni.org>
Maybe just add an (yes, ugly) new flag: --add-semicolons-for-one-line-blocks .
version 20190601 added flag --one-line-block-semicolons=n (-olbs=n) to control semicolons in one-line blocks. The values of n are: n=0 means no semicolons termininating simple one-line blocks n=1 means stable; do not change from input file [DEFAULT and current] n=2 means always add semicolons in one-line blocks The current behavior corresponds to the default n=1.