[PATCH] scripts: checkpatch: Check spaces in Makefiles.

Tóth János via B4 Relay posted 1 patch 2 months, 1 week ago
scripts/checkpatch.pl | 21 +++++++++++++++++++++
1 file changed, 21 insertions(+)
[PATCH] scripts: checkpatch: Check spaces in Makefiles.
Posted by Tóth János via B4 Relay 2 months, 1 week ago
From: Tóth János <gomba007@gmail.com>

I've found a Makefile that looked like this:
    obj-$(X)<tab><tab>+=<space>X.o
    obj-$(Y)<space><space>+=<space>Y.o

This patch allows checkpatch to detect this type of style error
in Makefiles. The check is disabled for the comment-only lines.

Signed-off-by: Tóth János <gomba007@gmail.com>
---
 scripts/checkpatch.pl | 21 +++++++++++++++++++++
 1 file changed, 21 insertions(+)

diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
index 4427572b2477..25b6f5b024c0 100755
--- a/scripts/checkpatch.pl
+++ b/scripts/checkpatch.pl
@@ -6,6 +6,7 @@
 # (c) 2007,2008, Andy Whitcroft <apw@uk.ibm.com> (new conditions, test suite)
 # (c) 2008-2010 Andy Whitcroft <apw@canonical.com>
 # (c) 2010-2018 Joe Perches <joe@perches.com>
+# (c) 2024 Tóth János <gomba007@gmail.com>
 
 use strict;
 use warnings;
@@ -3718,6 +3719,26 @@ sub process {
 			     "Use of $flag is deprecated, please use \`$replacement->{$flag} instead.\n" . $herecurr) if ($replacement->{$flag});
 		}
 
+		if ($realfile =~ /Makefile.*/ && $rawline !~ /^\+\#/) {
+			if ($rawline =~ /  /) {
+				my $herevet = "$here\n" . cat_vet($rawline) . "\n";
+				WARN("MULTIPLE_SPACES",
+				     "please, use tabs\n" . $herevet)
+			}
+
+			if ($rawline =~ / \t/) {
+				my $herevet = "$here\n" . cat_vet($rawline) . "\n";
+				WARN("SPACE_BEFORE_TAB",
+				     "please, no space before tabs, use tabs\n" . $herevet)
+			}
+
+			if ($rawline =~ /\t /) {
+				my $herevet = "$here\n" . cat_vet($rawline) . "\n";
+				WARN("TAB_BEFORE_SPACE",
+				     "please, no tab before spaces, use tabs\n" . $herevet)
+			}
+		}
+
 # check for DT compatible documentation
 		if (defined $root &&
 			(($realfile =~ /\.dtsi?$/ && $line =~ /^\+\s*compatible\s*=\s*\"/) ||

---
base-commit: 98f7e32f20d28ec452afb208f9cffc08448a2652
change-id: 20240919-checkpatch-makefile-spaces-74c1bcd2829c

Best regards,
-- 
Tóth János <gomba007@gmail.com>