lint(clippy): warn on manual printing to stdout or stderr (#3767)

Most logging should use `tracing::trace!()` or `tracing::debug!()` instead.
This commit is contained in:
teor 2022-03-08 19:14:15 +10:00 committed by GitHub
parent cee770fe2c
commit cef146edbd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
14 changed files with 22 additions and 12 deletions

View File

@ -38,6 +38,12 @@ rustflags = [
"-Wclippy::dbg_macro",
"-Wclippy::todo",
# Manual debugging output.
# Use tracing::trace!() or tracing::debug!() instead.
"-Wclippy::print_stdout",
"-Wclippy::print_stderr",
"-Wclippy::dbg_macro",
# Code styles we want to accept
"-Aclippy::try_err",
@ -59,10 +65,6 @@ rustflags = [
#"-Wclippy::cast_precision_loss", # 25 non-test warnings, 10 test warnings
#"-Wclippy::cast_sign_loss", # 6 non-test warnings, 15 test warnings
# disable these lints using a zebra-test config.toml, but warn for other crates
#"-Wclippy::print_stdout",
#"-Wclippy::print_stderr",
# fix hidden lifetime parameters
#"-Wrust_2018_idioms",
]

View File

@ -14,11 +14,6 @@ use NetworkUpgrade::*;
fn activation_bijective() {
zebra_test::init();
if std::env::var_os("TEST_FAKE_ACTIVATION_HEIGHTS").is_some() {
eprintln!("Skipping activation_bijective() since $TEST_FAKE_ACTIVATION_HEIGHTS is set");
return;
}
let mainnet_activations = NetworkUpgrade::activation_list(Mainnet);
let mainnet_heights: HashSet<&block::Height> = mainnet_activations.keys().collect();
assert_eq!(MAINNET_ACTIVATION_HEIGHTS.len(), mainnet_heights.len());

View File

@ -3,6 +3,7 @@
// Modified from:
// https://github.com/zcash/librustzcash/blob/c48bb4def2e122289843ddb3cb2984c325c03ca0/zcash_proofs/examples/get-params-path.rs
#[allow(clippy::print_stdout)]
fn main() {
let path = zebra_consensus::groth16::Groth16Parameters::directory();
if let Some(path) = path.to_str() {

View File

@ -23,7 +23,7 @@ use zebra_chain::{
use crate::primitives::halo2::*;
#[allow(dead_code)]
#[allow(dead_code, clippy::print_stdout)]
fn generate_test_vectors() {
let proving_key = ProvingKey::build();

View File

@ -48,6 +48,7 @@ fn blocks_with_v5_transactions() -> Result<()> {
///
/// This test requires setting the TEST_FAKE_ACTIVATION_HEIGHTS.
#[test]
#[allow(clippy::print_stderr)]
fn all_upgrades_and_wrong_commitments_with_fake_activation_heights() -> Result<()> {
zebra_test::init();

View File

@ -276,6 +276,7 @@ impl<T> TestChild<T> {
/// Note: the timeout is only checked after each full line is received from
/// the child.
#[instrument(skip(self, lines))]
#[allow(clippy::print_stdout)]
pub fn expect_line_matching<L>(
&mut self,
lines: &mut L,

View File

@ -18,6 +18,7 @@ const ZEBRA_SKIP_IPV6_TESTS: &str = "ZEBRA_SKIP_IPV6_TESTS";
/// Should we skip Zebra tests which need reliable, fast network connectivity?
//
// TODO: separate "good and reliable" from "any network"?
#[allow(clippy::print_stderr)]
pub fn zebra_skip_network_tests() -> bool {
if env::var_os(ZEBRA_SKIP_NETWORK_TESTS).is_some() {
// This message is captured by the test runner, use
@ -34,6 +35,7 @@ pub fn zebra_skip_network_tests() -> bool {
///
/// Since `zebra_skip_network_tests` only disables tests which need reliable network connectivity,
/// we allow IPv6 tests even when `ZEBRA_SKIP_NETWORK_TESTS` is set.
#[allow(clippy::print_stderr)]
pub fn zebra_skip_ipv6_tests() -> bool {
if env::var_os(ZEBRA_SKIP_IPV6_TESTS).is_some() {
eprintln!("Skipping IPv6 network test because '$ZEBRA_SKIP_IPV6_TESTS' is set.");

View File

@ -11,6 +11,7 @@ use zebra_test::{command::TestDirExt, prelude::Stdio};
/// (This message is captured by the test runner, use `cargo test -- --nocapture` to see it.)
///
/// The command's stdout and stderr are ignored.
#[allow(clippy::print_stderr)]
fn is_command_available(cmd: &str, args: &[&str]) -> bool {
let status = Command::new(cmd)
.args(args)

View File

@ -65,6 +65,7 @@ fn cmd_output(cmd: &mut std::process::Command) -> Result<String> {
Ok(s)
}
#[allow(clippy::print_stdout)]
fn main() -> Result<()> {
init_tracing();

View File

@ -28,6 +28,7 @@ fn disable_non_reproducible(_config: &mut Config) {
*/
}
#[allow(clippy::print_stderr)]
fn main() {
let mut config = Config::default();
disable_non_reproducible(&mut config);
@ -48,7 +49,7 @@ fn main() {
Err(e) => {
eprintln!(
"git error in vergen build script: skipping git env vars: {:?}",
e
e,
);
*config.git_mut().enabled_mut() = false;
vergen(config).expect("non-git vergen should succeed");

View File

@ -192,6 +192,7 @@ impl Application for ZebradApp {
/// If you would like to add additional components to your application
/// beyond the default ones provided by the framework, this is the place
/// to do so.
#[allow(clippy::print_stderr)]
fn register_components(&mut self, command: &Self::Cmd) -> Result<(), FrameworkError> {
use crate::components::{
metrics::MetricsEndpoint, tokio::TokioComponent, tracing::TracingEndpoint,

View File

@ -13,6 +13,7 @@ pub struct GenerateCmd {
impl Runnable for GenerateCmd {
/// Start the application.
#[allow(clippy::print_stdout)]
fn run(&self) {
let default_config = ZebradConfig::default();
let mut output = r"# Default configuration for zebrad.

View File

@ -11,6 +11,7 @@ pub struct VersionCmd {}
impl Runnable for VersionCmd {
/// Print version message
#[allow(clippy::print_stdout)]
fn run(&self) {
println!("{} {}", ZebradCmd::name(), ZebradCmd::version());
}

View File

@ -1261,6 +1261,7 @@ fn cached_mandatory_checkpoint_test_config() -> Result<ZebradConfig> {
///
/// Returns an error if the child exits or the fixed timeout elapses
/// before `STOP_AT_HEIGHT_REGEX` is found.
#[allow(clippy::print_stderr)]
fn create_cached_database_height(
network: Network,
height: Height,
@ -1268,7 +1269,8 @@ fn create_cached_database_height(
checkpoint_sync: bool,
stop_regex: &str,
) -> Result<()> {
println!("Creating cached database");
eprintln!("creating cached database");
// 16 hours
let timeout = Duration::from_secs(60 * 60 * 16);