Skip to content

Commit fa9198a

Browse files
author
MarcoFalke
committed
lint: Check for missing trailing newline
1 parent fa2b2aa commit fa9198a

File tree

4 files changed

+49
-6
lines changed

4 files changed

+49
-6
lines changed

INSTALL.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
See [doc/build-\*.md](/doc)
1+
See [doc/build-\*.md](/doc)

doc/release-notes-31278.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
RPC and Startup Option
22
---
3-
The `-paytxfee` startup option and the `settxfee` RPC are now deprecated and will be removed in Bitcoin Core 31.0. They allowed the user to set a static fee rate for wallet transactions, which could potentially lead to overpaying or underpaying. Users should instead rely on fee estimation or specify a fee rate per transaction using the `fee_rate` argument in RPCs such as `fundrawtransaction`, `sendtoaddress`, `send`, `sendall`, and `sendmany`. (#31278)
3+
The `-paytxfee` startup option and the `settxfee` RPC are now deprecated and will be removed in Bitcoin Core 31.0. They allowed the user to set a static fee rate for wallet transactions, which could potentially lead to overpaying or underpaying. Users should instead rely on fee estimation or specify a fee rate per transaction using the `fee_rate` argument in RPCs such as `fundrawtransaction`, `sendtoaddress`, `send`, `sendall`, and `sendmany`. (#31278)

src/test/fuzz/bech32.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) 2019-2021 The Bitcoin Core developers
1+
// Copyright (c) 2019-present The Bitcoin Core developers
22
// Distributed under the MIT software license, see the accompanying
33
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
44

@@ -66,4 +66,4 @@ FUZZ_TARGET(bech32_roundtrip)
6666
assert(decoded.data == converted_input);
6767
}
6868
}
69-
}
69+
}

test/lint/test_runner/src/main.rs

Lines changed: 45 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
// file COPYING or https://opensource.org/license/mit/.
44

55
use std::env;
6-
use std::fs;
7-
use std::io::ErrorKind;
6+
use std::fs::{self, File};
7+
use std::io::{ErrorKind, Read, Seek, SeekFrom};
88
use std::path::PathBuf;
99
use std::process::{Command, ExitCode, Stdio};
1010

@@ -88,6 +88,11 @@ fn get_linter_list() -> Vec<&'static Linter> {
8888
name: "trailing_whitespace",
8989
lint_fn: lint_trailing_whitespace
9090
},
91+
&Linter {
92+
description: "Check for trailing newline",
93+
name: "trailing_newline",
94+
lint_fn: lint_trailing_newline
95+
},
9196
&Linter {
9297
description: "Run all linters of the form: test/lint/lint-*.py",
9398
name: "all_python_linters",
@@ -514,6 +519,44 @@ sourced files to the exclude list.
514519
}
515520
}
516521

522+
fn lint_trailing_newline() -> LintResult {
523+
let files = check_output(
524+
git()
525+
.args([
526+
"ls-files", "--", "*.py", "*.cpp", "*.h", "*.md", "*.rs", "*.sh", "*.cmake",
527+
])
528+
.args(get_pathspecs_default_excludes()),
529+
)?;
530+
let mut missing_newline = false;
531+
for path in files.lines() {
532+
let mut file = File::open(path).expect("must be able to open file");
533+
if file.seek(SeekFrom::End(-1)).is_err() {
534+
continue; // Allow fully empty files
535+
}
536+
let mut buffer = [0u8; 1];
537+
file.read_exact(&mut buffer)
538+
.expect("must be able to read the last byte");
539+
if buffer[0] != b'\n' {
540+
missing_newline = true;
541+
println!("{path}");
542+
}
543+
}
544+
if missing_newline {
545+
Err(r#"
546+
A trailing newline is required, because git may warn about it missing. Also, it can make diffs
547+
verbose and can break git blame after appending lines.
548+
549+
Thus, it is best to add the trailing newline now.
550+
551+
Please add any false positives to the exclude list.
552+
"#
553+
.trim()
554+
.to_string())
555+
} else {
556+
Ok(())
557+
}
558+
}
559+
517560
fn lint_tabs_whitespace() -> LintResult {
518561
let tabs = git()
519562
.args(["grep", "-I", "--line-number", "--perl-regexp", "^\\t", "--"])

0 commit comments

Comments
 (0)