* [PATCH 1/1] checkpatch: fix some whitespace issues caused by --fix
@ 2013-08-05 11:08 Phil Carmody
2013-08-06 1:00 ` Joe Perches
0 siblings, 1 reply; 4+ messages in thread
From: Phil Carmody @ 2013-08-05 11:08 UTC (permalink / raw)
To: apw, joe; +Cc: linux-kernel, Phil Carmody
Lines with incorrect spacing around an operator, such as:
bystander, correct,incorrect
would get "fixed" to
bystander,correct, incorrect
as the correct argument as well as the incorrectly-spaced operator
were both being trimmed. The correct argument only needs to be
right trimmed.
Signed-off-by: Phil Carmody <phil.carmody@partner.samsung.com>
---
scripts/checkpatch.pl | 19 +++++++++++++------
1 file changed, 13 insertions(+), 6 deletions(-)
diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
index 2ee9eb7..b5f4157 100755
--- a/scripts/checkpatch.pl
+++ b/scripts/checkpatch.pl
@@ -1432,6 +1432,13 @@ sub check_absolute_file {
}
}
+sub rtrim {
+ my ($string) = @_;
+
+ $string =~ s/\s+$//;
+
+ return $string;
+}
sub trim {
my ($string) = @_;
@@ -2852,7 +2859,7 @@ sub process {
if ($ctx !~ /.x[WEC]/ && $cc !~ /^}/) {
if (ERROR("SPACING",
"space required after that '$op' $at\n" . $hereptr)) {
- $good = trim($fix_elements[$n]) . trim($fix_elements[$n + 1]) . " ";
+ $good = rtrim($fix_elements[$n]) . trim($fix_elements[$n + 1]) . " ";
$line_fixed = 1;
}
}
@@ -2881,7 +2888,7 @@ sub process {
if (ERROR("SPACING",
"space prohibited after that '$op' $at\n" . $hereptr)) {
$fixed_line =~ s/\s+$//;
- $good = trim($fix_elements[$n]) . trim($fix_elements[$n + 1]);
+ $good = rtrim($fix_elements[$n]) . trim($fix_elements[$n + 1]);
$line_fixed = 1;
if (defined $fix_elements[$n + 2]) {
$fix_elements[$n + 2] =~ s/^\s+//;
@@ -2904,7 +2911,7 @@ sub process {
if (ERROR("SPACING",
"space prohibited before that '$op' $at\n" . $hereptr)) {
$fixed_line =~ s/\s+$//;
- $good = trim($fix_elements[$n]) . trim($fix_elements[$n + 1]);
+ $good = rtrim($fix_elements[$n]) . trim($fix_elements[$n + 1]);
$line_fixed = 1;
}
}
@@ -2912,7 +2919,7 @@ sub process {
if (ERROR("SPACING",
"space prohibited after that '$op' $at\n" . $hereptr)) {
$fixed_line =~ s/\s+$//;
- $good = trim($fix_elements[$n]) . trim($fix_elements[$n + 1]);
+ $good = rtrim($fix_elements[$n]) . trim($fix_elements[$n + 1]);
$line_fixed = 1;
if (defined $fix_elements[$n + 2]) {
$fix_elements[$n + 2] =~ s/^\s+//;
@@ -2931,7 +2938,7 @@ sub process {
if (ERROR("SPACING",
"need consistent spacing around '$op' $at\n" . $hereptr)) {
$fixed_line =~ s/\s+$//;
- $good = trim($fix_elements[$n]) . " " . trim($fix_elements[$n + 1]) . " ";
+ $good = rtrim($fix_elements[$n]) . " " . trim($fix_elements[$n + 1]) . " ";
$line_fixed = 1;
}
}
@@ -2942,7 +2949,7 @@ sub process {
if ($ctx =~ /Wx./) {
if (ERROR("SPACING",
"space prohibited before that '$op' $at\n" . $hereptr)) {
- $good = trim($fix_elements[$n]) . trim($fix_elements[$n + 1]);
+ $good = rtrim($fix_elements[$n]) . trim($fix_elements[$n + 1]);
$line_fixed = 1;
}
}
--
1.7.9.5
^ permalink raw reply [flat|nested] 4+ messages in thread* Re: [PATCH 1/1] checkpatch: fix some whitespace issues caused by --fix
2013-08-05 11:08 [PATCH 1/1] checkpatch: fix some whitespace issues caused by --fix Phil Carmody
@ 2013-08-06 1:00 ` Joe Perches
2013-08-06 8:05 ` Phil Carmody
0 siblings, 1 reply; 4+ messages in thread
From: Joe Perches @ 2013-08-06 1:00 UTC (permalink / raw)
To: Phil Carmody; +Cc: apw, linux-kernel
On Mon, 2013-08-05 at 14:08 +0300, Phil Carmody wrote:
> Lines with incorrect spacing around an operator, such as:
> bystander, correct,incorrect
> would get "fixed" to
> bystander,correct, incorrect
> as the correct argument as well as the incorrectly-spaced operator
> were both being trimmed. The correct argument only needs to be
> right trimmed.
Thanks for the patch, but I think it needs a different fix.
Even after your patch the --fix option still makes a mess
of several code spacing issues.
I'll work on it and propose something soonish.
^ permalink raw reply [flat|nested] 4+ messages in thread
* RE: [PATCH 1/1] checkpatch: fix some whitespace issues caused by --fix
2013-08-06 1:00 ` Joe Perches
@ 2013-08-06 8:05 ` Phil Carmody
2013-08-06 14:09 ` Joe Perches
0 siblings, 1 reply; 4+ messages in thread
From: Phil Carmody @ 2013-08-06 8:05 UTC (permalink / raw)
To: 'Joe Perches'; +Cc: apw, linux-kernel
> On Mon, 2013-08-05 at 14:08 +0300, Phil Carmody wrote:
> > Lines with incorrect spacing around an operator, such as:
> > bystander, correct,incorrect
> > would get "fixed" to
> > bystander,correct, incorrect
> > as the correct argument as well as the incorrectly-spaced operator
> > were both being trimmed. The correct argument only needs to be right
> > trimmed.
>
> Thanks for the patch, but I think it needs a different fix.
I think it's the right approach, but you're right, it doesn't
fix all the problems. However, in part that's because many
copies of the string, or bits of it, are created, and when
one copy is modified, the others don't replicate that change.
> Even after your patch the --fix option still makes a mess of several
> code spacing issues.
Indeed. Just seen - func(foo,&bar); becoming func(foo, &bar);,
as --fix wants to put a space both after the ',' and before the '&'.
> I'll work on it and propose something soonish.
It's very much a WIP - I'll send my bride-of-checkpatch to you
as soon as I've written some blurb. It might be that the
complexities inside checkpatch can't be overcome, and it's
easier to address the changes entirely in a separate script?
Phil
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH 1/1] checkpatch: fix some whitespace issues caused by --fix
2013-08-06 8:05 ` Phil Carmody
@ 2013-08-06 14:09 ` Joe Perches
0 siblings, 0 replies; 4+ messages in thread
From: Joe Perches @ 2013-08-06 14:09 UTC (permalink / raw)
To: Phil Carmody; +Cc: apw, linux-kernel
On Tue, 2013-08-06 at 11:05 +0300, Phil Carmody wrote:
> > On Mon, 2013-08-05 at 14:08 +0300, Phil Carmody wrote:
> > > Lines with incorrect spacing around an operator, such as:
> > > bystander, correct,incorrect
> > > would get "fixed" to
> > > bystander,correct, incorrect
> > > as the correct argument as well as the incorrectly-spaced operator
> > > were both being trimmed. The correct argument only needs to be right
> > > trimmed.
> >
> > Thanks for the patch, but I think it needs a different fix.
>
> I think it's the right approach, but you're right,
> fix all the problems. However, in part that's because many
> copies of the string, or bits of it, are created, and when
> one copy is modified, the others don't replicate that change.
>
> > Even after your patch the --fix option still makes a mess of several
> > code spacing issues.
>
> Indeed. Just seen - func(foo,&bar); becoming func(foo, &bar);,
> as --fix wants to put a space both after the ',' and before the '&'.
Hi Phil.
Basically, checkpatch needs to left trim the
"$fix_elements[$n + 2])" if it exists.
> > I'll work on it and propose something soonish.
>
> It's very much a WIP - I'll send my bride-of-checkpatch to you
> as soon as I've written some blurb. It might be that the
> complexities inside checkpatch can't be overcome, and it's
> easier to address the changes entirely in a separate script?
Maybe, but humans are lazy.
Maybe the "bride-of" approach will work better,
It's hard to know right now. No worries, you try
yours too and one or the other or both might be
the "right" approach.
btw:
The biggest complexity might be handling patches
that need lines added or removed by rewriting
the patch contexts.
Maybe creating an interdiff would be better than
rewriting the patch or file.
I was too lazy to do that to checkpatch for a
first pass.
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2013-08-06 14:09 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-08-05 11:08 [PATCH 1/1] checkpatch: fix some whitespace issues caused by --fix Phil Carmody
2013-08-06 1:00 ` Joe Perches
2013-08-06 8:05 ` Phil Carmody
2013-08-06 14:09 ` Joe Perches
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®