Skip to contentSkip to conversation

checkpatch: add a fixer for missing newline at eof

PATCH Superseded [email protected] 2 participants 2 messages Oct 14, 2020 – Oct 15, 2020 Checkpatch

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 checkpatch: add a fixer for missing newline at eof

From: Tom Rix <[email protected]>

Remove the trailing error message from the fixed lines

---
 scripts/checkpatch.pl | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)
scripts/checkpatch.pl +5 -2
index fab38b493cef..7d3db096bc44 100755
@@ -3393,8 +3393,11 @@ sub process {
 
 # check for adding lines without a newline.
 		if ($line =~ /^\+/ && defined $lines[$linenr] && $lines[$linenr] =~ /^\\ No newline at end of file/) {
-			WARN("MISSING_EOF_NEWLINE",
-			     "adding a line without newline at end of file\n" . $herecurr);
+			if (WARN("MISSING_EOF_NEWLINE",
+			         "adding a line without newline at end of file\n" . $herecurr) &&
+			    $fix) {
+			    fix_delete_line($fixlinenr+1, "No newline at end of file");
+			}
 		}
 
 # check we are in a valid source file C or perl if not then ignore this hunk
Signature · 1 line
2.18.1
maintainer
#1 lore raw
Quoted 3 lines · On Wed, 2020-10-14 at 14:15 -0700, [email protected] wrote:

From: Tom Rix <[email protected]>

Remove the trailing error message from the fixed lines

Hi Tom.

scripts/checkpatch.pl

Quoted 1 line
scripts/checkpatch.pl +0 -0

[]

scripts/checkpatch.pl sub process { · line 3399

Quoted 10 lines
scripts/checkpatch.pl +4 -2
@@ -3393,8 +3393,11 @@ sub process {
 
 # check for adding lines without a newline.
 		if ($line =~ /^\+/ && defined $lines[$linenr] && $lines[$linenr] =~ /^\\ No newline at end of file/) {
-			WARN("MISSING_EOF_NEWLINE",
-			     "adding a line without newline at end of file\n" . $herecurr);
+			if (WARN("MISSING_EOF_NEWLINE",
+			         "adding a line without newline at end of file\n" . $herecurr) &&
+			    $fix) {
+			    fix_delete_line($fixlinenr+1, "No newline at end of file");

This is misindented, the 4 spaces before fix_delete_line should be a tab, otherwise this looks fine, thanks.