#!/usr/bin/env python3 import argparse import fnmatch import sys import os import re import shutil from pathlib import Path from difflib import unified_diff # ---------- 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 = """ #![allow(renamed_and_removed_lints)] // @@REMOVE_WHEN(ci_arti_stable) #![allow(unknown_lints)] // @@REMOVE_WHEN(ci_arti_nightly) #![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)] #![allow(clippy::cognitive_complexity)] // See arti#2556 #![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::unchecked_time_subtraction)] #![deny(clippy::unnecessary_wraps)] #![warn(clippy::unseparated_literal_suffix)] #![deny(clippy::unwrap_used)] #![deny(clippy::mod_module_files)] #![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 #![allow(clippy::needless_lifetimes)] // See arti#1765 #![allow(mismatched_lifetime_syntaxes)] // temporary workaround for arti#2060 #![allow(clippy::collapsible_if)] // See arti#2342 #![deny(clippy::unused_async)] #![deny(clippy::string_slice)] // See arti#2571 """ # ---------- 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::mixed_attributes_style)] #![allow(clippy::print_stderr)] #![allow(clippy::print_stdout)] #![allow(clippy::single_char_pattern)] #![allow(clippy::unwrap_used)] #![allow(clippy::unchecked_time_subtraction)] #![allow(clippy::useless_vec)] #![allow(clippy::needless_pass_by_value)] #![allow(clippy::string_slice)] // See arti#2571 """ # ---------- list of lints to apply or disapply *in examples* ---------- EXAMPLE_LINTS = """ #![allow(unknown_lints)] // @@REMOVE_WHEN(ci_arti_nightly) """ + TEST_LINTS.strip() # ---------- 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)") LINT_LISTS = { "lint": WANT_LINTS, "test lint": TEST_LINTS, "example lint": EXAMPLE_LINTS, } # The start delimiter is a regular comment. START_LINE = re.compile(r"^(\s*)// @@ begin (.*) list") # End delimiter is Rustdoc containing an HTML comment, because rustfmt # *really really* hates comments that come after things. # Finishing the automaintained block with just a blank line is too much of a hazard. # It does end up in the output HTML from Rustdoc, but it is harmless there. END_LINE = re.compile(r"^\s*//!