#!/usr/bin/env python3 import argparse import fnmatch import sys import os import re import shutil import subprocess # ---------- actual list of lints to apply (or disapply) ---------- # NOTE: We should NEVER have a `deny` for a built-in rustc lint. # It's okay to deny clippy lints, but if we deny rustc lints, # a future version of the compiler might refuse to build our code # entirely. WANT_LINTS = """ #![cfg_attr(not(ci_arti_stable), allow(renamed_and_removed_lints))] #![cfg_attr(not(ci_arti_nightly), allow(unknown_lints))] #![warn(missing_docs)] #![warn(noop_method_call)] #![warn(unreachable_pub)] #![warn(clippy::all)] #![deny(clippy::await_holding_lock)] #![deny(clippy::cargo_common_metadata)] #![deny(clippy::cast_lossless)] #![deny(clippy::checked_conversions)] #![warn(clippy::cognitive_complexity)] #![deny(clippy::debug_assert_with_mut_call)] #![deny(clippy::exhaustive_enums)] #![deny(clippy::exhaustive_structs)] #![deny(clippy::expl_impl_clone_on_copy)] #![deny(clippy::fallible_impl_from)] #![deny(clippy::implicit_clone)] #![deny(clippy::large_stack_arrays)] #![warn(clippy::manual_ok_or)] #![deny(clippy::missing_docs_in_private_items)] #![warn(clippy::needless_borrow)] #![warn(clippy::needless_pass_by_value)] #![warn(clippy::option_option)] #![deny(clippy::print_stderr)] #![deny(clippy::print_stdout)] #![warn(clippy::rc_buffer)] #![deny(clippy::ref_option_ref)] #![warn(clippy::semicolon_if_nothing_returned)] #![warn(clippy::trait_duplication_in_bounds)] #![deny(clippy::unnecessary_wraps)] #![warn(clippy::unseparated_literal_suffix)] #![deny(clippy::unwrap_used)] #![allow(clippy::let_unit_value)] // This can reasonably be done for explicitness #![allow(clippy::uninlined_format_args)] #![allow(clippy::significant_drop_in_scrutinee)] // arti/-/merge_requests/588/#note_2812945 #![allow(clippy::result_large_err)] // temporary workaround for arti#587 #![allow(clippy::needless_raw_string_hashes)] // complained-about code is fine, often best """ # ---------- list of lints to apply or disapply *in tests* ---------- TEST_LINTS = """ #![allow(clippy::bool_assert_comparison)] #![allow(clippy::clone_on_copy)] #![allow(clippy::dbg_macro)] #![allow(clippy::print_stderr)] #![allow(clippy::print_stdout)] #![allow(clippy::single_char_pattern)] #![allow(clippy::unwrap_used)] #![allow(clippy::unchecked_duration_subtraction)] #![allow(clippy::useless_vec)] #![allow(clippy::needless_pass_by_value)] """ # ---------- some notes about lints we might use - NOT USED by any code here ---------- SOON = """ """ WISH_WE_COULD = """ #![warn(unused_crate_dependencies)] """ DECIDED_NOT = """ #![deny(clippy::redundant_pub_crate)] #![deny(clippy::future_not_send)] #![deny(clippy::redundant_closure_for_method_calls)] #![deny(clippy::panic)] #![deny(clippy::if_then_some_else_none)] #![deny(clippy::expect_used)] #![deny(clippy::option_if_let_else)] #![deny(missing_debug_implementations)] #![deny(clippy::pub_enum_variant_names)] """ # ---------- code for autoprocessing Rust source files ---------- PAT = re.compile(r'^ *#!\[(?:cfg_attr\(.*)?(allow|deny|warn)') opts = None deferred_errors = [] class ImproperFile(Exception): def __init__(self, lno, message): self.lno = lno self.message = message def filter_file(lints, inp, outp, insist): in_lint_list = None found_lint_list = False lno = 0 for line in inp.readlines(): lno += 1 line_starts = None line_ends = None line_stripped = line.lstrip(' ') if line_stripped.startswith("// @@ begin lint list"): line_starts = 'main' elif line_stripped.startswith("// @@ begin test lint list"): line_starts = 'test' elif line_stripped.startswith("//!