diff mbox

checkpatch: Fix whitespace checks for documentation code blocks

Message ID 147315784999.7992.18445290612470259572.stgit@fimbulvetr.bsc.es (mailing list archive)
State New, archived
Headers show

Commit Message

Lluís Vilanova Sept. 6, 2016, 10:30 a.m. UTC
Prevent blank lines in documentation code blocks to be signalled as
incorrect trailing whitespace.

Code blocks in documentation are 4-column aligned, and blank lines in
them should have exactly 4 columns of trailing whitespace to prevent
QEMU's wiki to render them as separate code blocks.

Signed-off-by: Lluís Vilanova <vilanova@ac.upc.edu>
---
 scripts/checkpatch.pl |   10 ++++++++++
 1 file changed, 10 insertions(+)

Comments

Paolo Bonzini Sept. 6, 2016, 6:58 p.m. UTC | #1
On 06/09/2016 12:30, Lluís Vilanova wrote:
> Prevent blank lines in documentation code blocks to be signalled as
> incorrect trailing whitespace.
> 
> Code blocks in documentation are 4-column aligned, and blank lines in
> them should have exactly 4 columns of trailing whitespace to prevent
> QEMU's wiki to render them as separate code blocks.
> 
> Signed-off-by: Lluís Vilanova <vilanova@ac.upc.edu>
> ---
>  scripts/checkpatch.pl |   10 ++++++++++
>  1 file changed, 10 insertions(+)
> 
> diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
> index b0096a4..4bdfe2e 100755
> --- a/scripts/checkpatch.pl
> +++ b/scripts/checkpatch.pl
> @@ -1320,6 +1320,16 @@ sub process {
>  			my $herevet = "$here\n" . cat_vet($rawline) . "\n";
>  			ERROR("DOS line endings\n" . $herevet);
>  
> +		} elsif ($realfile =~ /^docs\/.+\.txt/ ||
> +			 $realfile =~ /^docs\/.+\.md/) {
> +		    if ($rawline =~ /^\+\s+$/ && $rawline !~ /^\+\s{4}$/) {

\s includes tabs, doesn't it?  So the second condition should be just

    $rawline ne '+    '

I think.

Paolo


> +			# TODO: properly check we're in a code block
> +			#       (surrounding text is 4-column aligned)
> +			my $herevet = "$here\n" . cat_vet($rawline) . "\n";
> +			ERROR("code blocks in documentation should have " .
> +			      "exactly 4 columns of trailing whitespace\n" .
> +			      $herevet);
> +		    }
>  		} elsif ($rawline =~ /^\+.*\S\s+$/ || $rawline =~ /^\+\s+$/) {
>  			my $herevet = "$here\n" . cat_vet($rawline) . "\n";
>  			ERROR("trailing whitespace\n" . $herevet);
>
Lluís Vilanova Sept. 7, 2016, 12:40 p.m. UTC | #2
Paolo Bonzini writes:

> On 06/09/2016 12:30, Lluís Vilanova wrote:
>> Prevent blank lines in documentation code blocks to be signalled as
>> incorrect trailing whitespace.
>> 
>> Code blocks in documentation are 4-column aligned, and blank lines in
>> them should have exactly 4 columns of trailing whitespace to prevent
>> QEMU's wiki to render them as separate code blocks.
>> 
>> Signed-off-by: Lluís Vilanova <vilanova@ac.upc.edu>
>> ---
>> scripts/checkpatch.pl |   10 ++++++++++
>> 1 file changed, 10 insertions(+)
>> 
>> diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
>> index b0096a4..4bdfe2e 100755
>> --- a/scripts/checkpatch.pl
>> +++ b/scripts/checkpatch.pl
>> @@ -1320,6 +1320,16 @@ sub process {
>> my $herevet = "$here\n" . cat_vet($rawline) . "\n";
>> ERROR("DOS line endings\n" . $herevet);
>> 
>> +		} elsif ($realfile =~ /^docs\/.+\.txt/ ||
>> +			 $realfile =~ /^docs\/.+\.md/) {
>> +		    if ($rawline =~ /^\+\s+$/ && $rawline !~ /^\+\s{4}$/) {

> \s includes tabs, doesn't it?  So the second condition should be just

>     $rawline ne '+    '

> I think.

> Paolo

So true; I'll resend a v2.

Thanks,
  Lluis
diff mbox

Patch

diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
index b0096a4..4bdfe2e 100755
--- a/scripts/checkpatch.pl
+++ b/scripts/checkpatch.pl
@@ -1320,6 +1320,16 @@  sub process {
 			my $herevet = "$here\n" . cat_vet($rawline) . "\n";
 			ERROR("DOS line endings\n" . $herevet);
 
+		} elsif ($realfile =~ /^docs\/.+\.txt/ ||
+			 $realfile =~ /^docs\/.+\.md/) {
+		    if ($rawline =~ /^\+\s+$/ && $rawline !~ /^\+\s{4}$/) {
+			# TODO: properly check we're in a code block
+			#       (surrounding text is 4-column aligned)
+			my $herevet = "$here\n" . cat_vet($rawline) . "\n";
+			ERROR("code blocks in documentation should have " .
+			      "exactly 4 columns of trailing whitespace\n" .
+			      $herevet);
+		    }
 		} elsif ($rawline =~ /^\+.*\S\s+$/ || $rawline =~ /^\+\s+$/) {
 			my $herevet = "$here\n" . cat_vet($rawline) . "\n";
 			ERROR("trailing whitespace\n" . $herevet);