Skip to content

Commit

Permalink
Merge bitcoin#29487: lint: Fix lint-whitespace issues
Browse files Browse the repository at this point in the history
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#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
  • Loading branch information
fanquake committed Mar 15, 2024
2 parents 178b4d4 + 5555395 commit 015ac13
Show file tree
Hide file tree
Showing 2 changed files with 84 additions and 137 deletions.
136 changes: 0 additions & 136 deletions test/lint/lint-whitespace.py

This file was deleted.

85 changes: 84 additions & 1 deletion test/lint/test_runner/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ type LintFn = fn() -> LintResult;

/// Return the git command
fn git() -> Command {
Command::new("git")
let mut git = Command::new("git");
git.arg("--no-pager");
git
}

/// Return stdout
Expand Down Expand Up @@ -95,6 +97,85 @@ fs:: namespace, which has unsafe filesystem functions marked as deleted.
}
}

/// Return the pathspecs for whitespace related excludes
fn get_pathspecs_exclude_whitespace() -> Vec<String> {
let mut list = get_pathspecs_exclude_subtrees();
list.extend(
[
// Permanent excludes
"*.patch",
"src/qt/locale",
"contrib/windeploy/win-codesign.cert",
"doc/README_windows.txt",
// Temporary excludes, or existing violations
"doc/release-notes/release-notes-0.*",
"contrib/init/bitcoind.openrc",
"contrib/macdeploy/macdeployqtplus",
"src/crypto/sha256_sse4.cpp",
"src/qt/res/src/*.svg",
"test/functional/test_framework/crypto/ellswift_decode_test_vectors.csv",
"test/functional/test_framework/crypto/xswiftec_inv_test_vectors.csv",
"contrib/qos/tc.sh",
"contrib/verify-commits/gpg.sh",
"src/univalue/include/univalue_escapes.h",
"src/univalue/test/object.cpp",
"test/lint/git-subtree-check.sh",
]
.iter()
.map(|s| format!(":(exclude){}", s)),
);
list
}

fn lint_trailing_whitespace() -> LintResult {
let trailing_space = git()
.args(["grep", "-I", "--line-number", "\\s$", "--"])
.args(get_pathspecs_exclude_whitespace())
.status()
.expect("command error")
.success();
if trailing_space {
Err(r#"
^^^
Trailing whitespace is problematic, because git may warn about it, or editors may remove it by
default, forcing developers in the future to either undo the changes manually or spend time on
review.
Thus, it is best to remove the trailing space now.
Please add any false positives, such as subtrees, Windows-related files, patch files, or externally
sourced files to the exclude list.
"#
.to_string())
} else {
Ok(())
}
}

fn lint_tabs_whitespace() -> LintResult {
let tabs = git()
.args(["grep", "-I", "--line-number", "--perl-regexp", "^\\t", "--"])
.args(["*.cpp", "*.h", "*.md", "*.py", "*.sh"])
.args(get_pathspecs_exclude_whitespace())
.status()
.expect("command error")
.success();
if tabs {
Err(r#"
^^^
Use of tabs in this codebase is problematic, because existing code uses spaces and tabs will cause
display issues and conflict with editor settings.
Please remove the tabs.
Please add any false positives, such as subtrees, or externally sourced files to the exclude list.
"#
.to_string())
} else {
Ok(())
}
}

fn lint_includes_build_config() -> LintResult {
let config_path = "./src/config/bitcoin-config.h.in";
let include_directive = "#include <config/bitcoin-config.h>";
Expand Down Expand Up @@ -232,6 +313,8 @@ fn main() -> ExitCode {
let test_list: Vec<(&str, LintFn)> = vec![
("subtree check", lint_subtree),
("std::filesystem check", lint_std_filesystem),
("trailing whitespace check", lint_trailing_whitespace),
("no-tabs check", lint_tabs_whitespace),
("build config includes check", lint_includes_build_config),
("-help=1 documentation check", lint_doc),
("lint-*.py scripts", lint_all),
Expand Down

0 comments on commit 015ac13

Please sign in to comment.