Re: [PATCH] checkpatch: error if file terminates without a new-line

From: Prasad Pandit
Date: Tue Apr 16 2024 - 03:19:08 EST


[+linux-kernel]

On Saturday, 30 March, 2024 at 09:09:12 am IST, Prasad Pandit <ppandit@xxxxxxxxxx> wrote: 
From: Prasad Pandit <pjp@xxxxxxxxxxxxxxxxx>

Add check to flag an error if a patch terminates a file
without a new line (\n) character.

Suggested-by: Dan Carpenter <dan.carpenter@xxxxxxxxxx>
Signed-off-by: Prasad Pandit <pjp@xxxxxxxxxxxxxxxxx>
---
scripts/checkpatch.pl | 7 +++++++
1 file changed, 7 insertions(+)

-> https://lore.kernel.org/all/CAE8KmOxG=3sWKpeB5fdWTK-SCipS=JyDE-_DNgY--DtoSQZ0Qw@xxxxxxxxxxxxxx/T/#t

diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
index 9c4c4a61bc83..df34c0709410 100755
--- a/scripts/checkpatch.pl
+++ b/scripts/checkpatch.pl
@@ -2795,6 +2795,13 @@ sub process {
            $is_patch = 1;
        }

+# check if patch terminates file without a new line (\n)
+        if ($line =~ /^\\ No newline at end of file$/
+            and $rawlines[$linenr - 2] =~ /^\+.*$/) {
+            ERROR("NOEOL_FILE",
+                  "patch terminates file without a new line (\\n).");
+        }
+
#extract the line range in the file after the patch is applied
        if (!$in_commit_log &&
            $line =~ /^\@\@ -\d+(?:,\d+)? \+(\d+)(,(\d+))? \@\@(.*)/) {
--
2.44.0