Skip to content

Commit fa57294

Browse files
author
MarcoFalke
committed
lint: Fix lint-whitespace issues
1 parent d14c728 commit fa57294

File tree

2 files changed

+81
-136
lines changed

2 files changed

+81
-136
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: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,85 @@ fs:: namespace, which has unsafe filesystem functions marked as deleted.
9595
}
9696
}
9797

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

0 commit comments

Comments
 (0)