Skip to content

Commit 7c87a0e

Browse files
committed
Merge bitcoin/bitcoin#32477: lint: Check for missing trailing newline
fa9198a lint: Check for missing trailing newline (MarcoFalke) fa2b2aa lint: Add archived notes to default excludes (MarcoFalke) Pull request description: A missing trailing newline is harmless, but a bit problematic: * `git` shows a warning by default * After another line is appended, the diff will be verbose and `git blame` will be wrong for the "untouched" line. Fix the problems by just requiring what is already the default, see also https://github.com/bitcoin/bitcoin/blob/663a9cabf811e2fc53102bc6da00d09fc99d1d81/.editorconfig#L9 and https://github.com/bitcoin/bitcoin/blob/663a9cabf811e2fc53102bc6da00d09fc99d1d81/test/lint/test_runner/src/main.rs#L327 ACKs for top commit: l0rinc: utACK fa9198a fanquake: ACK fa9198a Tree-SHA512: d144eebdeee68fc3404aa4a66ecd5c130f907ed4b869bd300f6e9ed74d125561d1f4cdd6dd20d9e969471a7d007399f928f072d1c1f626275ca31f32bc23fdbc
2 parents 33f8f8a + fa9198a commit 7c87a0e

File tree

4 files changed

+57
-12
lines changed

4 files changed

+57
-12
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: 53 additions & 8 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",
@@ -209,10 +214,13 @@ fn get_subtrees() -> Vec<&'static str> {
209214
]
210215
}
211216

212-
/// Return the pathspecs to exclude all subtrees
213-
fn get_pathspecs_exclude_subtrees() -> Vec<String> {
217+
/// Return the pathspecs to exclude by default
218+
fn get_pathspecs_default_excludes() -> Vec<String> {
214219
get_subtrees()
215220
.iter()
221+
.chain(&[
222+
"doc/release-notes/release-notes-*", // archived notes
223+
])
216224
.map(|s| format!(":(exclude){}", s))
217225
.collect()
218226
}
@@ -333,7 +341,7 @@ fn lint_py_lint() -> LintResult {
333341
let files = check_output(
334342
git()
335343
.args(["ls-files", "--", "*.py"])
336-
.args(get_pathspecs_exclude_subtrees()),
344+
.args(get_pathspecs_default_excludes()),
337345
)?;
338346

339347
let mut cmd = Command::new(bin_name);
@@ -459,7 +467,7 @@ expected to follow the naming "/doc/release-notes-<PR number>.md".
459467

460468
/// Return the pathspecs for whitespace related excludes
461469
fn get_pathspecs_exclude_whitespace() -> Vec<String> {
462-
let mut list = get_pathspecs_exclude_subtrees();
470+
let mut list = get_pathspecs_default_excludes();
463471
list.extend(
464472
[
465473
// Permanent excludes
@@ -468,7 +476,6 @@ fn get_pathspecs_exclude_whitespace() -> Vec<String> {
468476
"contrib/windeploy/win-codesign.cert",
469477
"doc/README_windows.txt",
470478
// Temporary excludes, or existing violations
471-
"doc/release-notes/release-notes-0.*",
472479
"contrib/init/bitcoind.openrc",
473480
"contrib/macdeploy/macdeployqtplus",
474481
"src/crypto/sha256_sse4.cpp",
@@ -512,6 +519,44 @@ sourced files to the exclude list.
512519
}
513520
}
514521

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+
515560
fn lint_tabs_whitespace() -> LintResult {
516561
let tabs = git()
517562
.args(["grep", "-I", "--line-number", "--perl-regexp", "^\\t", "--"])
@@ -569,7 +614,7 @@ fn lint_includes_build_config() -> LintResult {
569614
"*.cpp",
570615
"*.h",
571616
])
572-
.args(get_pathspecs_exclude_subtrees())
617+
.args(get_pathspecs_default_excludes())
573618
.args([
574619
// These are exceptions which don't use bitcoin-build-config.h, rather CMakeLists.txt adds
575620
// these cppflags manually.

0 commit comments

Comments
 (0)