Skip to content

Commit 015ac13

Browse files
committed
Merge bitcoin/bitcoin#29487: lint: Fix lint-whitespace issues
5555395 lint: Use git --no-pager to print any output in one go (MarcoFalke) fa57294 lint: Fix lint-whitespace issues (MarcoFalke) Pull request description: The lint check has many issues: * It uses `COMMIT_RANGE`, which is brittle code, apparently making it harder to run the CI locally, or self-hosted. See bitcoin/bitcoin#29274 (comment) * The result depends on `COMMIT_RANGE`, or the number of commits passed to the script, which can cause false negatives or false positives. * It is based on the diff output, parsing it, and printing it again, which is brittle as well. * The output does not include line number, making it harder to act on a lint error. Fix all issues by removing the script and replacing it with a simple call to `git grep -I --line-number ...`. ACKs for top commit: TheCharlatan: Re-ACK 5555395 Tree-SHA512: 71ea8b6382af064beb72fb17f21a0ae9e9238c97e7fa43c2ec353fd1dd73a7bbd696ba0f0a9f65d1eff7c86cbf6cc104a992cb5450a3d50f122955e835270065
2 parents 178b4d4 + 5555395 commit 015ac13

File tree

2 files changed

+84
-137
lines changed

2 files changed

+84
-137
lines changed

test/lint/lint-whitespace.py

Lines changed: 0 additions & 136 deletions
This file was deleted.

test/lint/test_runner/src/main.rs

Lines changed: 84 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@ type LintFn = fn() -> LintResult;
1414

1515
/// Return the git command
1616
fn git() -> Command {
17-
Command::new("git")
17+
let mut git = Command::new("git");
18+
git.arg("--no-pager");
19+
git
1820
}
1921

2022
/// Return stdout
@@ -95,6 +97,85 @@ fs:: namespace, which has unsafe filesystem functions marked as deleted.
9597
}
9698
}
9799

100+
/// Return the pathspecs for whitespace related excludes
101+
fn get_pathspecs_exclude_whitespace() -> Vec<String> {
102+
let mut list = get_pathspecs_exclude_subtrees();
103+
list.extend(
104+
[
105+
// Permanent excludes
106+
"*.patch",
107+
"src/qt/locale",
108+
"contrib/windeploy/win-codesign.cert",
109+
"doc/README_windows.txt",
110+
// Temporary excludes, or existing violations
111+
"doc/release-notes/release-notes-0.*",
112+
"contrib/init/bitcoind.openrc",
113+
"contrib/macdeploy/macdeployqtplus",
114+
"src/crypto/sha256_sse4.cpp",
115+
"src/qt/res/src/*.svg",
116+
"test/functional/test_framework/crypto/ellswift_decode_test_vectors.csv",
117+
"test/functional/test_framework/crypto/xswiftec_inv_test_vectors.csv",
118+
"contrib/qos/tc.sh",
119+
"contrib/verify-commits/gpg.sh",
120+
"src/univalue/include/univalue_escapes.h",
121+
"src/univalue/test/object.cpp",
122+
"test/lint/git-subtree-check.sh",
123+
]
124+
.iter()
125+
.map(|s| format!(":(exclude){}", s)),
126+
);
127+
list
128+
}
129+
130+
fn lint_trailing_whitespace() -> LintResult {
131+
let trailing_space = git()
132+
.args(["grep", "-I", "--line-number", "\\s$", "--"])
133+
.args(get_pathspecs_exclude_whitespace())
134+
.status()
135+
.expect("command error")
136+
.success();
137+
if trailing_space {
138+
Err(r#"
139+
^^^
140+
Trailing whitespace is problematic, because git may warn about it, or editors may remove it by
141+
default, forcing developers in the future to either undo the changes manually or spend time on
142+
review.
143+
144+
Thus, it is best to remove the trailing space now.
145+
146+
Please add any false positives, such as subtrees, Windows-related files, patch files, or externally
147+
sourced files to the exclude list.
148+
"#
149+
.to_string())
150+
} else {
151+
Ok(())
152+
}
153+
}
154+
155+
fn lint_tabs_whitespace() -> LintResult {
156+
let tabs = git()
157+
.args(["grep", "-I", "--line-number", "--perl-regexp", "^\\t", "--"])
158+
.args(["*.cpp", "*.h", "*.md", "*.py", "*.sh"])
159+
.args(get_pathspecs_exclude_whitespace())
160+
.status()
161+
.expect("command error")
162+
.success();
163+
if tabs {
164+
Err(r#"
165+
^^^
166+
Use of tabs in this codebase is problematic, because existing code uses spaces and tabs will cause
167+
display issues and conflict with editor settings.
168+
169+
Please remove the tabs.
170+
171+
Please add any false positives, such as subtrees, or externally sourced files to the exclude list.
172+
"#
173+
.to_string())
174+
} else {
175+
Ok(())
176+
}
177+
}
178+
98179
fn lint_includes_build_config() -> LintResult {
99180
let config_path = "./src/config/bitcoin-config.h.in";
100181
let include_directive = "#include <config/bitcoin-config.h>";
@@ -232,6 +313,8 @@ fn main() -> ExitCode {
232313
let test_list: Vec<(&str, LintFn)> = vec![
233314
("subtree check", lint_subtree),
234315
("std::filesystem check", lint_std_filesystem),
316+
("trailing whitespace check", lint_trailing_whitespace),
317+
("no-tabs check", lint_tabs_whitespace),
235318
("build config includes check", lint_includes_build_config),
236319
("-help=1 documentation check", lint_doc),
237320
("lint-*.py scripts", lint_all),

0 commit comments

Comments
 (0)