Skip to contentSkip to conversation

scripts: checkpatch: Check spaces in Makefiles.

PATCH New Tóth János 1 participant 1 message Sep 19, 2024 Checkpatch

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 scripts: checkpatch: Check spaces in Makefiles.

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.

---
 scripts/checkpatch.pl | 21 +++++++++++++++++++++
 1 file changed, 21 insertions(+)
scripts/checkpatch.pl +21 -0
index 4427572b2477..25b6f5b024c0 100755
@@ -6,6 +6,7 @@
 # (c) 2007,2008, Andy Whitcroft <[email protected]> (new conditions, test suite)
 # (c) 2008-2010 Andy Whitcroft <[email protected]>
 # (c) 2010-2018 Joe Perches <[email protected]>
+# (c) 2024 Tóth János <[email protected]>
 
 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,

Signature · 1 line
Tóth János <[email protected]>