Skip to content

Commit 3d57959

Browse files
committed
Force new line after a line comment
1 parent 0a93b02 commit 3d57959

3 files changed

Lines changed: 40 additions & 3 deletions

File tree

Changes

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
Revision history for SQL-Beautify
22

3+
0.05 2022-03-09
4+
* Force new linr after a line comment
5+
36
0.04 2011-08-07
47
* Support for adding own keywords.
58
* Support for custom rules
@@ -15,7 +18,7 @@ Revision history for SQL-Beautify
1518
0.02 2009-03-29
1619
* Fix in documentation.
1720
* Line break before ORDER BY and GROUP BY.
18-
21+
1922

2023
0.01 2009-02-22
2124
First version, released on an unsuspecting world.

lib/SQL/Beautify.pm

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,11 @@ sub beautify {
115115
$self->_process_rule($rule, $token);
116116
}
117117

118+
elsif($token =~ /^--$/i) {
119+
$self->_add_token($token);
120+
$self->_new_line;
121+
}
122+
118123
elsif($token eq '(') {
119124
$self->_add_token($token);
120125
$self->_new_line;
@@ -233,8 +238,8 @@ sub _add_token {
233238
$token = uc $token
234239
if $self->_is_keyword($token) and $self->{uc_keywords};
235240

236-
# lowercase name
237-
$token = lc $token
241+
# lowercase name
242+
$token = lc $token
238243
if $self->{lc_names} and !$self->_is_keyword( $token ) and !$self->_is_constant( $token );
239244

240245
$self->{_output} .= $token;

t/line_comment.t

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#!/usr/bin/perl
2+
3+
use strict;
4+
use warnings;
5+
6+
use Test::More tests => 4;
7+
use SQL::Beautify;
8+
9+
my $sql = new SQL::Beautify(spaces => 2);
10+
my $query;
11+
my $beauty;
12+
13+
ok($sql, 'got instance');
14+
15+
# Test plain text formatting.
16+
$query = <DATA>;
17+
$beauty = <DATA>;
18+
19+
$beauty = eval $beauty;
20+
21+
ok($sql->query($query) eq $query, 'query set');
22+
ok($sql->query eq $query, 'query get');
23+
24+
ok($sql->beautify eq $beauty, 'beautified');
25+
26+
27+
__DATA__
28+
SELECT * FROM foo, bar, baz WHERE foo.id = bar.id -- AND bar.id = baz.id
29+
"SELECT\n *\nFROM\n foo,\n bar,\n baz\nWHERE\n foo.id = bar.id -- AND bar.id = baz.id\n"

0 commit comments

Comments
 (0)