lint: Check for missing trailing newline

This commit is contained in:
MarcoFalke
2025-05-13 11:46:58 +02:00
parent fa2b2aa27c
commit fa9198af55
4 changed files with 49 additions and 6 deletions

View File

@ -1 +1 @@
See [doc/build-\*.md](/doc)
See [doc/build-\*.md](/doc)

View File

@ -1,3 +1,3 @@
RPC and Startup Option
---
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)
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)

View File

@ -1,4 +1,4 @@
// Copyright (c) 2019-2021 The Bitcoin Core developers
// Copyright (c) 2019-present The Bitcoin Core developers
// Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
@ -66,4 +66,4 @@ FUZZ_TARGET(bech32_roundtrip)
assert(decoded.data == converted_input);
}
}
}
}

View File

@ -3,8 +3,8 @@
// file COPYING or https://opensource.org/license/mit/.
use std::env;
use std::fs;
use std::io::ErrorKind;
use std::fs::{self, File};
use std::io::{ErrorKind, Read, Seek, SeekFrom};
use std::path::PathBuf;
use std::process::{Command, ExitCode, Stdio};
@ -88,6 +88,11 @@ fn get_linter_list() -> Vec<&'static Linter> {
name: "trailing_whitespace",
lint_fn: lint_trailing_whitespace
},
&Linter {
description: "Check for trailing newline",
name: "trailing_newline",
lint_fn: lint_trailing_newline
},
&Linter {
description: "Run all linters of the form: test/lint/lint-*.py",
name: "all_python_linters",
@ -514,6 +519,44 @@ sourced files to the exclude list.
}
}
fn lint_trailing_newline() -> LintResult {
let files = check_output(
git()
.args([
"ls-files", "--", "*.py", "*.cpp", "*.h", "*.md", "*.rs", "*.sh", "*.cmake",
])
.args(get_pathspecs_default_excludes()),
)?;
let mut missing_newline = false;
for path in files.lines() {
let mut file = File::open(path).expect("must be able to open file");
if file.seek(SeekFrom::End(-1)).is_err() {
continue; // Allow fully empty files
}
let mut buffer = [0u8; 1];
file.read_exact(&mut buffer)
.expect("must be able to read the last byte");
if buffer[0] != b'\n' {
missing_newline = true;
println!("{path}");
}
}
if missing_newline {
Err(r#"
A trailing newline is required, because git may warn about it missing. Also, it can make diffs
verbose and can break git blame after appending lines.
Thus, it is best to add the trailing newline now.
Please add any false positives to the exclude list.
"#
.trim()
.to_string())
} else {
Ok(())
}
}
fn lint_tabs_whitespace() -> LintResult {
let tabs = git()
.args(["grep", "-I", "--line-number", "--perl-regexp", "^\\t", "--"])