Skip to contentSkip to conversation

checkpatch: allow URL >80 chars

PATCH Superseded Andreas Brauchli 2 participants 4 messages Nov 17, 2017 – Nov 18, 2017 Checkpatch

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 checkpatch: allow URL >80 chars

Allow URL to exceed the 80 char limit for improved interaction in adaption to ongoing but undocumented practice.

$ git grep -E '://\S{77}.*' -- '*.[ch]'

The patch checks that the URL is indeed on its own line in that it allows a maximal prefix of 4 characters to account for a URL after a comment (e.g. ' // https://...')

The URL format allows for up to 5 protocol characters before the separator :// (e.g. https, git, ...). Additionally, an URL starting with a "domain.tld" or "subdomain.domain" pattern (e.g. 'www.kernel.org') is also accepted.

$rawline is used in the check as comments are removed from $line.

---
 scripts/checkpatch.pl | 5 +++++
 1 file changed, 5 insertions(+)
scripts/checkpatch.pl +5 -0
index 8b80bac055e4..aed447923354 100755
@@ -2904,6 +2904,11 @@ sub process {
 			} elsif ($line =~ /^\+.*\bEFI_GUID\s*\(/) {
 				$msg_type = "";
 
+			# URL (w/ minimal padding e.g. "+ // ")
+			} elsif ($rawline =~ /^\+.*?\b((?:\w{1,5}:\/\/|\w+\.\w+)\S+).*$/ &&
+				 length($rawline) - length($1) <= 5) {
+				$msg_type = "";
+
 			# Otherwise set the alternate message types
 
 			# a comment starts before $max_line_length
Signature · 1 line
2.14.1
maintainer NAK
#1 lore raw
Quoted 26 lines · Andreas Brauchli

Allow URL to exceed the 80 char limit for improved interaction in adaption to ongoing but undocumented practice.

$ git grep -E '://\S{77}.*' -- '*.[ch]'

The patch checks that the URL is indeed on its own line in that it allows a maximal prefix of 4 characters to account for a URL after a comment (e.g. ' // https://...')

The URL format allows for up to 5 protocol characters before the separator :// (e.g. https, git, ...). Additionally, an URL starting with a "domain.tld" or "subdomain.domain" pattern (e.g. 'www.kernel.org') is also accepted.

$rawline is used in the check as comments are removed from $line.

---
 scripts/checkpatch.pl | 5 +++++
 1 file changed, 5 insertions(+)
scripts/checkpatch.pl +0 -0
index 8b80bac055e4..aed447923354 100755

scripts/checkpatch.pl sub process { · line 2908

Quoted 5 lines
scripts/checkpatch.pl +2 -0
@@ -2904,6 +2904,11 @@ sub process {
 			} elsif ($line =~ /^\+.*\bEFI_GUID\s*\(/) {
 				$msg_type = "";
 
+			# URL (w/ minimal padding e.g. "+ // ")
+			} elsif ($rawline =~ /^\+.*?\b((?:\w{1,5}:\/\/|\w+\.\w+)\S+).*$/ &&

nack.

this matches member dereference lines like

	foo.bar = baz;

and include lines like

	#include <foo.h>
#2 lore raw
Quoted 35 lines · Joe Perches
Quoted 26 lines · Andreas Brauchli

Allow URL to exceed the 80 char limit for improved interaction in adaption to ongoing but undocumented practice.

$ git grep -E '://\S{77}.*' -- '*.[ch]'

The patch checks that the URL is indeed on its own line in that it allows a maximal prefix of 4 characters to account for a URL after a comment (e.g. ' // https://...')

The URL format allows for up to 5 protocol characters before the separator :// (e.g. https, git, ...). Additionally, an URL starting with a "domain.tld" or "subdomain.domain" pattern (e.g. 'www.kernel.org') is also accepted.

$rawline is used in the check as comments are removed from $line.

---
 scripts/checkpatch.pl | 5 +++++
 1 file changed, 5 insertions(+)
scripts/checkpatch.pl +0 -0
index 8b80bac055e4..aed447923354 100755

scripts/checkpatch.pl sub process { · line 2908

Quoted 5 lines
scripts/checkpatch.pl +2 -0
@@ -2904,6 +2904,11 @@ sub process {
 			} elsif ($line =~ /^\+.*\bEFI_GUID\s*\(/) {
 				$msg_type = "";
 
+			# URL (w/ minimal padding e.g. "+ // ")
+			} elsif ($rawline =~ /^\+.*?\b((?:\w{1,5}:\/\/|\w+\.\w+)\S+).*$/ &&

nack.

Quoted 7 lines

this matches member dereference lines like

	foo.bar = baz;

and include lines like

	#include <foo.h>

Agreed, there are even a few false positives (all member derefs). Apologies for failing to catch those.

Is the patch acceptable if it only catches URL with protocol specifiers foo:// ? That would catch most cases and doesn't show false positives:

$ git grep -E '://\S{75}.*' -- '*.[ch]'

Cheers,
Andreas

maintainer
#3 lore raw
Quoted 3 lines · Andreas Brauchli

Is the patch acceptable if it only catches URL with protocol specifiers foo:// ? That would catch most cases and doesn't show false positives:

$ git grep -E '://\S{75}.*' -- '*.[ch]'

Of course. but I suggest using a prefix like

\b[\w\.\+\-]+://

so the URL scheme is properly described.

It might be best if there was some generic mechanism to identify possible URIs and not just URLs instead.

https://en.wikipedia.org/wiki/Uniform_Resource_Identifier