mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-08-28 09:16:10 +02:00
lint: Check for missing trailing newline
This commit is contained in:
@@ -1 +1 @@
|
|||||||
See [doc/build-\*.md](/doc)
|
See [doc/build-\*.md](/doc)
|
||||||
|
@@ -1,3 +1,3 @@
|
|||||||
RPC and Startup Option
|
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)
|
||||||
|
@@ -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
|
// Distributed under the MIT software license, see the accompanying
|
||||||
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
||||||
|
|
||||||
@@ -66,4 +66,4 @@ FUZZ_TARGET(bech32_roundtrip)
|
|||||||
assert(decoded.data == converted_input);
|
assert(decoded.data == converted_input);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -3,8 +3,8 @@
|
|||||||
// file COPYING or https://opensource.org/license/mit/.
|
// file COPYING or https://opensource.org/license/mit/.
|
||||||
|
|
||||||
use std::env;
|
use std::env;
|
||||||
use std::fs;
|
use std::fs::{self, File};
|
||||||
use std::io::ErrorKind;
|
use std::io::{ErrorKind, Read, Seek, SeekFrom};
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
use std::process::{Command, ExitCode, Stdio};
|
use std::process::{Command, ExitCode, Stdio};
|
||||||
|
|
||||||
@@ -88,6 +88,11 @@ fn get_linter_list() -> Vec<&'static Linter> {
|
|||||||
name: "trailing_whitespace",
|
name: "trailing_whitespace",
|
||||||
lint_fn: lint_trailing_whitespace
|
lint_fn: lint_trailing_whitespace
|
||||||
},
|
},
|
||||||
|
&Linter {
|
||||||
|
description: "Check for trailing newline",
|
||||||
|
name: "trailing_newline",
|
||||||
|
lint_fn: lint_trailing_newline
|
||||||
|
},
|
||||||
&Linter {
|
&Linter {
|
||||||
description: "Run all linters of the form: test/lint/lint-*.py",
|
description: "Run all linters of the form: test/lint/lint-*.py",
|
||||||
name: "all_python_linters",
|
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 {
|
fn lint_tabs_whitespace() -> LintResult {
|
||||||
let tabs = git()
|
let tabs = git()
|
||||||
.args(["grep", "-I", "--line-number", "--perl-regexp", "^\\t", "--"])
|
.args(["grep", "-I", "--line-number", "--perl-regexp", "^\\t", "--"])
|
||||||
|
Reference in New Issue
Block a user