All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] checkpatch: Warn on embedded function names
@ 2017-01-04  3:21 Joe Perches
  2017-01-04  6:56 ` [Acked] " Andy Whitcroft
  0 siblings, 1 reply; 3+ messages in thread
From: Joe Perches @ 2017-01-04  3:21 UTC (permalink / raw)
  To: Andrew Morton, Andy Whitcroft; +Cc: linux-kernel

Embedded function names are less appropriate to use when
refactoring can cause function renaming.  Prefer the use
of "%s", __func__ to embedded function names.

Signed-off-by: Joe Perches <joe@perches.com>
---
 scripts/checkpatch.pl | 22 ++++++++++++++++++++--
 1 file changed, 20 insertions(+), 2 deletions(-)

diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
index 982c52ca6473..4f53093a1b0b 100755
--- a/scripts/checkpatch.pl
+++ b/scripts/checkpatch.pl
@@ -2134,7 +2134,7 @@ sub process {
 	my $in_header_lines = $file ? 0 : 1;
 	my $in_commit_log = 0;		#Scanning lines before patch
 	my $has_commit_log = 0;		#Encountered lines before patch
-       my $commit_log_possible_stack_dump = 0;
+	my $commit_log_possible_stack_dump = 0;
 	my $commit_log_long_line = 0;
 	my $commit_log_has_diff = 0;
 	my $reported_maintainer_file = 0;
@@ -2154,6 +2154,7 @@ sub process {
 	my $realline = 0;
 	my $realcnt = 0;
 	my $here = '';
+	my $context_function;		#undef'd unless there's a known function
 	my $in_comment = 0;
 	my $comment_edge = 0;
 	my $first_line = 0;
@@ -2192,7 +2193,8 @@ sub process {
 			}
 			#next;
 		}
-		if ($rawline=~/^\@\@ -\d+(?:,\d+)? \+(\d+)(,(\d+))? \@\@/) {
+		if ($rawline=~/^\@\@ -\d+(?:,\d+)? \+(\d+)(,(\d+))? \@\@(.*)/) {
+			my $context = $4;
 			$realline=$1-1;
 			if (defined $2) {
 				$realcnt=$3+1;
@@ -2201,6 +2203,12 @@ sub process {
 			}
 			$in_comment = 0;
 
+			if ($context =~ /\b(\w+)\s*\(/) {
+				$context_function = $1;
+			} else {
+				undef $context_function;
+			}
+
 			# Guestimate if this is a continuing comment.  Run
 			# the context looking for a comment "edge".  If this
 			# edge is a close comment then we must be in a comment
@@ -5157,6 +5165,16 @@ sub process {
 			     "break quoted strings at a space character\n" . $hereprev);
 		}
 
+#check for an embedded function name in a string when the function is known
+# as part of a diff.  This does not work for -f --file checking as it
+#depends on patch context providing the function name
+		if ($line =~ /^\+.*$String/ &&
+		    defined($context_function) &&
+		    get_quoted_string($line, $rawline) =~ /\b$context_function\b/) {
+			WARN("EMBEDDED_FUNCTION_NAME",
+			     "Prefer using \"%s\", __func__ to embedded function names\n" . $herecurr);
+		}
+
 # check for spaces before a quoted newline
 		if ($rawline =~ /^.*\".*\s\\n/) {
 			if (WARN("QUOTED_WHITESPACE_BEFORE_NEWLINE",
-- 
2.10.0.rc2.1.g053435c

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* [Acked] [PATCH] checkpatch: Warn on embedded function names
  2017-01-04  3:21 [PATCH] checkpatch: Warn on embedded function names Joe Perches
@ 2017-01-04  6:56 ` Andy Whitcroft
  0 siblings, 0 replies; 3+ messages in thread
From: Andy Whitcroft @ 2017-01-04  6:56 UTC (permalink / raw)
  To: Joe Perches; +Cc: Andrew Morton, linux-kernel

On Tue, Jan 03, 2017 at 07:21:54PM -0800, Joe Perches wrote:
> Embedded function names are less appropriate to use when
> refactoring can cause function renaming.  Prefer the use
> of "%s", __func__ to embedded function names.
> 
> Signed-off-by: Joe Perches <joe@perches.com>
> ---
>  scripts/checkpatch.pl | 22 ++++++++++++++++++++--
>  1 file changed, 20 insertions(+), 2 deletions(-)
> 
> diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
> index 982c52ca6473..4f53093a1b0b 100755
> --- a/scripts/checkpatch.pl
> +++ b/scripts/checkpatch.pl
> @@ -2134,7 +2134,7 @@ sub process {
>  	my $in_header_lines = $file ? 0 : 1;
>  	my $in_commit_log = 0;		#Scanning lines before patch
>  	my $has_commit_log = 0;		#Encountered lines before patch
> -       my $commit_log_possible_stack_dump = 0;
> +	my $commit_log_possible_stack_dump = 0;
>  	my $commit_log_long_line = 0;
>  	my $commit_log_has_diff = 0;
>  	my $reported_maintainer_file = 0;
> @@ -2154,6 +2154,7 @@ sub process {
>  	my $realline = 0;
>  	my $realcnt = 0;
>  	my $here = '';
> +	my $context_function;		#undef'd unless there's a known function
>  	my $in_comment = 0;
>  	my $comment_edge = 0;
>  	my $first_line = 0;
> @@ -2192,7 +2193,8 @@ sub process {
>  			}
>  			#next;
>  		}
> -		if ($rawline=~/^\@\@ -\d+(?:,\d+)? \+(\d+)(,(\d+))? \@\@/) {
> +		if ($rawline=~/^\@\@ -\d+(?:,\d+)? \+(\d+)(,(\d+))? \@\@(.*)/) {
> +			my $context = $4;
>  			$realline=$1-1;
>  			if (defined $2) {
>  				$realcnt=$3+1;
> @@ -2201,6 +2203,12 @@ sub process {
>  			}
>  			$in_comment = 0;
>  
> +			if ($context =~ /\b(\w+)\s*\(/) {
> +				$context_function = $1;
> +			} else {
> +				undef $context_function;
> +			}
> +
>  			# Guestimate if this is a continuing comment.  Run
>  			# the context looking for a comment "edge".  If this
>  			# edge is a close comment then we must be in a comment
> @@ -5157,6 +5165,16 @@ sub process {
>  			     "break quoted strings at a space character\n" . $hereprev);
>  		}
>  
> +#check for an embedded function name in a string when the function is known
> +# as part of a diff.  This does not work for -f --file checking as it
> +#depends on patch context providing the function name
> +		if ($line =~ /^\+.*$String/ &&
> +		    defined($context_function) &&
> +		    get_quoted_string($line, $rawline) =~ /\b$context_function\b/) {
> +			WARN("EMBEDDED_FUNCTION_NAME",
> +			     "Prefer using \"%s\", __func__ to embedded function names\n" . $herecurr);
> +		}
> +
>  # check for spaces before a quoted newline
>  		if ($rawline =~ /^.*\".*\s\\n/) {
>  			if (WARN("QUOTED_WHITESPACE_BEFORE_NEWLINE",
> -- 
> 2.10.0.rc2.1.g053435c
> 

Looks sane enough to me.

Acked-by: Andy Whitcroft <apw@canonical.com>

-apw

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [PATCH] checkpatch: Warn on embedded function names
@ 2017-01-04  6:16 Joe Perches
  0 siblings, 0 replies; 3+ messages in thread
From: Joe Perches @ 2017-01-04  6:16 UTC (permalink / raw)
  To: Andrew Morton, Andy Whitcroft; +Cc: linux-kernel

Embedded function names are less appropriate to use when
refactoring can cause function renaming.  Prefer the use
of "%s", __func__ to embedded function names.

Signed-off-by: Joe Perches <joe@perches.com>
---
 scripts/checkpatch.pl | 22 ++++++++++++++++++++--
 1 file changed, 20 insertions(+), 2 deletions(-)

diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
index 982c52ca6473..4f53093a1b0b 100755
--- a/scripts/checkpatch.pl
+++ b/scripts/checkpatch.pl
@@ -2134,7 +2134,7 @@ sub process {
 	my $in_header_lines = $file ? 0 : 1;
 	my $in_commit_log = 0;		#Scanning lines before patch
 	my $has_commit_log = 0;		#Encountered lines before patch
-       my $commit_log_possible_stack_dump = 0;
+	my $commit_log_possible_stack_dump = 0;
 	my $commit_log_long_line = 0;
 	my $commit_log_has_diff = 0;
 	my $reported_maintainer_file = 0;
@@ -2154,6 +2154,7 @@ sub process {
 	my $realline = 0;
 	my $realcnt = 0;
 	my $here = '';
+	my $context_function;		#undef'd unless there's a known function
 	my $in_comment = 0;
 	my $comment_edge = 0;
 	my $first_line = 0;
@@ -2192,7 +2193,8 @@ sub process {
 			}
 			#next;
 		}
-		if ($rawline=~/^\@\@ -\d+(?:,\d+)? \+(\d+)(,(\d+))? \@\@/) {
+		if ($rawline=~/^\@\@ -\d+(?:,\d+)? \+(\d+)(,(\d+))? \@\@(.*)/) {
+			my $context = $4;
 			$realline=$1-1;
 			if (defined $2) {
 				$realcnt=$3+1;
@@ -2201,6 +2203,12 @@ sub process {
 			}
 			$in_comment = 0;
 
+			if ($context =~ /\b(\w+)\s*\(/) {
+				$context_function = $1;
+			} else {
+				undef $context_function;
+			}
+
 			# Guestimate if this is a continuing comment.  Run
 			# the context looking for a comment "edge".  If this
 			# edge is a close comment then we must be in a comment
@@ -5157,6 +5165,16 @@ sub process {
 			     "break quoted strings at a space character\n" . $hereprev);
 		}
 
+#check for an embedded function name in a string when the function is known
+# as part of a diff.  This does not work for -f --file checking as it
+#depends on patch context providing the function name
+		if ($line =~ /^\+.*$String/ &&
+		    defined($context_function) &&
+		    get_quoted_string($line, $rawline) =~ /\b$context_function\b/) {
+			WARN("EMBEDDED_FUNCTION_NAME",
+			     "Prefer using \"%s\", __func__ to embedded function names\n" . $herecurr);
+		}
+
 # check for spaces before a quoted newline
 		if ($rawline =~ /^.*\".*\s\\n/) {
 			if (WARN("QUOTED_WHITESPACE_BEFORE_NEWLINE",
-- 
2.10.0.rc2.1.g053435c

^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2017-01-04  6:56 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-01-04  3:21 [PATCH] checkpatch: Warn on embedded function names Joe Perches
2017-01-04  6:56 ` [Acked] " Andy Whitcroft
2017-01-04  6:16 Joe Perches

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.