mirror of
https://github.com/rust-lang/rust-clippy
synced 2024-11-10 07:04:18 +00:00
Mark the lints for each config via an attribute instead of a doc comment..
This commit is contained in:
parent
7422202ca5
commit
1d06ad5599
4 changed files with 173 additions and 272 deletions
|
@ -123,6 +123,7 @@ macro_rules! define_Conf {
|
|||
$(#[doc = $doc:literal])+
|
||||
$(#[conf_deprecated($dep:literal, $new_conf:ident)])?
|
||||
$(#[default_text = $default_text:expr])?
|
||||
$(#[lints($($for_lints:ident),* $(,)?)])?
|
||||
$name:ident: $ty:ty = $default:expr,
|
||||
)*) => {
|
||||
/// Clippy lint configuration
|
||||
|
@ -201,90 +202,57 @@ macro_rules! define_Conf {
|
|||
}
|
||||
|
||||
pub fn get_configuration_metadata() -> Vec<ClippyConfiguration> {
|
||||
let mut sorted = vec![
|
||||
$(
|
||||
{
|
||||
let deprecation_reason = wrap_option!($($dep)?);
|
||||
|
||||
ClippyConfiguration::new(
|
||||
stringify!($name),
|
||||
default_text!(defaults::$name() $(, $default_text)?),
|
||||
concat!($($doc, '\n',)*),
|
||||
deprecation_reason,
|
||||
)
|
||||
},
|
||||
)+
|
||||
];
|
||||
sorted.sort_by(|a, b| a.name.cmp(&b.name));
|
||||
sorted
|
||||
}
|
||||
|
||||
#[test]
|
||||
pub fn is_conf_ordered() {
|
||||
use itertools::Itertools;
|
||||
|
||||
let misordered: Vec<_> = [$(stringify!($name),)*].array_windows::<2>().filter(|[x, y]| x > y).collect();
|
||||
assert!(
|
||||
misordered.is_empty(),
|
||||
"the following config fields are misordered:\n {}",
|
||||
misordered.iter().format_with("\n ", |[x, y], f| f(&format_args!("{x}, {y}"))),
|
||||
);
|
||||
vec![$(
|
||||
ClippyConfiguration {
|
||||
name: stringify!($name).replace('_', "-"),
|
||||
default: default_text!(defaults::$name() $(, $default_text)?),
|
||||
lints: &[$($(stringify!($for_lints)),*)?],
|
||||
doc: concat!($($doc, '\n',)*),
|
||||
deprecation_reason: wrap_option!($($dep)?)
|
||||
},
|
||||
)*]
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
define_Conf! {
|
||||
/// Lint: ABSOLUTE_PATHS.
|
||||
///
|
||||
/// Which crates to allow absolute paths from
|
||||
#[lints(absolute_paths)]
|
||||
absolute_paths_allowed_crates: FxHashSet<String> = FxHashSet::default(),
|
||||
/// Lint: ABSOLUTE_PATHS.
|
||||
///
|
||||
/// The maximum number of segments a path can have before being linted, anything above this will
|
||||
/// be linted.
|
||||
#[lints(absolute_paths)]
|
||||
absolute_paths_max_segments: u64 = 2,
|
||||
/// Lint: UNDOCUMENTED_UNSAFE_BLOCKS.
|
||||
///
|
||||
/// Whether to accept a safety comment to be placed above the attributes for the `unsafe` block
|
||||
#[lints(undocumented_unsafe_blocks)]
|
||||
accept_comment_above_attributes: bool = true,
|
||||
/// Lint: UNDOCUMENTED_UNSAFE_BLOCKS.
|
||||
///
|
||||
/// Whether to accept a safety comment to be placed above the statement containing the `unsafe` block
|
||||
#[lints(undocumented_unsafe_blocks)]
|
||||
accept_comment_above_statement: bool = true,
|
||||
/// Lint: MODULO_ARITHMETIC.
|
||||
///
|
||||
/// Don't lint when comparing the result of a modulo operation to zero.
|
||||
#[lints(modulo_arithmetic)]
|
||||
allow_comparison_to_zero: bool = true,
|
||||
/// Lint: DBG_MACRO.
|
||||
///
|
||||
/// Whether `dbg!` should be allowed in test functions or `#[cfg(test)]`
|
||||
#[lints(dbg_macro)]
|
||||
allow_dbg_in_tests: bool = false,
|
||||
/// Lint: EXPECT_USED.
|
||||
///
|
||||
/// Whether `expect` should be allowed in test functions or `#[cfg(test)]`
|
||||
#[lints(expect_used)]
|
||||
allow_expect_in_tests: bool = false,
|
||||
/// Lint: UNINLINED_FORMAT_ARGS.
|
||||
///
|
||||
/// Whether to allow mixed uninlined format args, e.g. `format!("{} {}", a, foo.bar)`
|
||||
#[lints(uninlined_format_args)]
|
||||
allow_mixed_uninlined_format_args: bool = true,
|
||||
/// Lint: UNNECESSARY_RAW_STRING_HASHES.
|
||||
///
|
||||
/// Whether to allow `r#""#` when `r""` can be used
|
||||
#[lints(unnecessary_raw_string_hashes)]
|
||||
allow_one_hash_in_raw_strings: bool = false,
|
||||
/// Lint: PANIC.
|
||||
///
|
||||
/// Whether `panic` should be allowed in test functions or `#[cfg(test)]`
|
||||
#[lints(panic)]
|
||||
allow_panic_in_tests: bool = false,
|
||||
/// Lint: PRINT_STDOUT, PRINT_STDERR.
|
||||
///
|
||||
/// Whether print macros (ex. `println!`) should be allowed in test functions or `#[cfg(test)]`
|
||||
#[lints(print_stderr, print_stdout)]
|
||||
allow_print_in_tests: bool = false,
|
||||
/// Lint: MODULE_INCEPTION.
|
||||
///
|
||||
/// Whether to allow module inception if it's not public.
|
||||
#[lints(module_inception)]
|
||||
allow_private_module_inception: bool = false,
|
||||
/// Lint: RENAMED_FUNCTION_PARAMS.
|
||||
///
|
||||
/// List of trait paths to ignore when checking renamed function parameters.
|
||||
///
|
||||
/// #### Example
|
||||
|
@ -298,33 +266,27 @@ define_Conf! {
|
|||
/// - By default, the following traits are ignored: `From`, `TryFrom`, `FromStr`
|
||||
/// - `".."` can be used as part of the list to indicate that the configured values should be appended to the
|
||||
/// default configuration of Clippy. By default, any configuration will replace the default value.
|
||||
#[lints(renamed_function_params)]
|
||||
allow_renamed_params_for: Vec<String> =
|
||||
DEFAULT_ALLOWED_TRAITS_WITH_RENAMED_PARAMS.iter().map(ToString::to_string).collect(),
|
||||
/// Lint: UNWRAP_USED.
|
||||
///
|
||||
/// Whether `unwrap` should be allowed in test functions or `#[cfg(test)]`
|
||||
#[lints(unwrap_used)]
|
||||
allow_unwrap_in_tests: bool = false,
|
||||
/// Lint: USELESS_VEC.
|
||||
///
|
||||
/// Whether `useless_vec` should ignore test functions or `#[cfg(test)]`
|
||||
#[lints(useless_vec)]
|
||||
allow_useless_vec_in_tests: bool = false,
|
||||
/// Lint: PATH_ENDS_WITH_EXT.
|
||||
///
|
||||
/// Additional dotfiles (files or directories starting with a dot) to allow
|
||||
#[lints(path_ends_with_ext)]
|
||||
allowed_dotfiles: Vec<String> = Vec::default(),
|
||||
/// Lint: MULTIPLE_CRATE_VERSIONS.
|
||||
///
|
||||
/// A list of crate names to allow duplicates of
|
||||
#[lints(multiple_crate_versions)]
|
||||
allowed_duplicate_crates: FxHashSet<String> = FxHashSet::default(),
|
||||
/// Lint: MIN_IDENT_CHARS.
|
||||
///
|
||||
/// Allowed names below the minimum allowed characters. The value `".."` can be used as part of
|
||||
/// the list to indicate, that the configured values should be appended to the default
|
||||
/// configuration of Clippy. By default, any configuration will replace the default value.
|
||||
#[lints(min_ident_chars)]
|
||||
allowed_idents_below_min_chars: FxHashSet<String> =
|
||||
DEFAULT_ALLOWED_IDENTS_BELOW_MIN_CHARS.iter().map(ToString::to_string).collect(),
|
||||
/// Lint: MODULE_NAME_REPETITIONS.
|
||||
///
|
||||
/// List of prefixes to allow when determining whether an item's name ends with the module's name.
|
||||
/// If the rest of an item's name is an allowed prefix (e.g. item `ToFoo` or `to_foo` in module `foo`),
|
||||
/// then don't emit a warning.
|
||||
|
@ -342,13 +304,11 @@ define_Conf! {
|
|||
/// `TryInto` will also be included)
|
||||
/// - Use `".."` as part of the list to indicate that the configured values should be appended to the
|
||||
/// default configuration of Clippy. By default, any configuration will replace the default value
|
||||
#[lints(module_name_repetitions)]
|
||||
allowed_prefixes: Vec<String> = DEFAULT_ALLOWED_PREFIXES.iter().map(ToString::to_string).collect(),
|
||||
/// Lint: DISALLOWED_SCRIPT_IDENTS.
|
||||
///
|
||||
/// The list of unicode scripts allowed to be used in the scope.
|
||||
#[lints(disallowed_script_idents)]
|
||||
allowed_scripts: Vec<String> = vec!["Latin".to_string()],
|
||||
/// Lint: WILDCARD_IMPORTS.
|
||||
///
|
||||
/// List of path segments allowed to have wildcard imports.
|
||||
///
|
||||
/// #### Example
|
||||
|
@ -362,9 +322,8 @@ define_Conf! {
|
|||
/// 1. This configuration has no effects if used with `warn_on_all_wildcard_imports = true`.
|
||||
/// 2. Paths with any segment that containing the word 'prelude'
|
||||
/// are already allowed by default.
|
||||
#[lints(wildcard_imports)]
|
||||
allowed_wildcard_imports: FxHashSet<String> = FxHashSet::default(),
|
||||
/// Lint: ARITHMETIC_SIDE_EFFECTS.
|
||||
///
|
||||
/// Suppress checking of the passed type names in all types of operations.
|
||||
///
|
||||
/// If a specific operation is desired, consider using `arithmetic_side_effects_allowed_binary` or `arithmetic_side_effects_allowed_unary` instead.
|
||||
|
@ -379,9 +338,8 @@ define_Conf! {
|
|||
///
|
||||
/// A type, say `SomeType`, listed in this configuration has the same behavior of
|
||||
/// `["SomeType" , "*"], ["*", "SomeType"]` in `arithmetic_side_effects_allowed_binary`.
|
||||
#[lints(arithmetic_side_effects)]
|
||||
arithmetic_side_effects_allowed: Vec<String> = <_>::default(),
|
||||
/// Lint: ARITHMETIC_SIDE_EFFECTS.
|
||||
///
|
||||
/// Suppress checking of the passed type pair names in binary operations like addition or
|
||||
/// multiplication.
|
||||
///
|
||||
|
@ -396,9 +354,8 @@ define_Conf! {
|
|||
/// ```toml
|
||||
/// arithmetic-side-effects-allowed-binary = [["SomeType" , "f32"], ["AnotherType", "*"]]
|
||||
/// ```
|
||||
#[lints(arithmetic_side_effects)]
|
||||
arithmetic_side_effects_allowed_binary: Vec<[String; 2]> = <_>::default(),
|
||||
/// Lint: ARITHMETIC_SIDE_EFFECTS.
|
||||
///
|
||||
/// Suppress checking of the passed type names in unary operations like "negation" (`-`).
|
||||
///
|
||||
/// #### Example
|
||||
|
@ -406,73 +363,78 @@ define_Conf! {
|
|||
/// ```toml
|
||||
/// arithmetic-side-effects-allowed-unary = ["SomeType", "AnotherType"]
|
||||
/// ```
|
||||
#[lints(arithmetic_side_effects)]
|
||||
arithmetic_side_effects_allowed_unary: Vec<String> = <_>::default(),
|
||||
/// Lint: LARGE_STACK_ARRAYS, LARGE_CONST_ARRAYS.
|
||||
///
|
||||
/// The maximum allowed size for arrays on the stack
|
||||
#[lints(large_const_arrays, large_stack_arrays)]
|
||||
array_size_threshold: u64 = 512_000,
|
||||
/// Lint: ENUM_VARIANT_NAMES, LARGE_TYPES_PASSED_BY_VALUE, TRIVIALLY_COPY_PASS_BY_REF, UNNECESSARY_WRAPS, UNUSED_SELF, UPPER_CASE_ACRONYMS, WRONG_SELF_CONVENTION, BOX_COLLECTION, REDUNDANT_ALLOCATION, RC_BUFFER, VEC_BOX, OPTION_OPTION, LINKEDLIST, RC_MUTEX, UNNECESSARY_BOX_RETURNS, SINGLE_CALL_FN, NEEDLESS_PASS_BY_REF_MUT.
|
||||
///
|
||||
/// Suppress lints whenever the suggested change would cause breakage for other crates.
|
||||
#[lints(
|
||||
box_collection,
|
||||
enum_variant_names,
|
||||
large_types_passed_by_value,
|
||||
linkedlist,
|
||||
needless_pass_by_ref_mut,
|
||||
option_option,
|
||||
rc_buffer,
|
||||
rc_mutex,
|
||||
redundant_allocation,
|
||||
single_call_fn,
|
||||
trivially_copy_pass_by_ref,
|
||||
unnecessary_box_returns,
|
||||
unnecessary_wraps,
|
||||
unused_self,
|
||||
upper_case_acronyms,
|
||||
vec_box,
|
||||
wrong_self_convention,
|
||||
)]
|
||||
avoid_breaking_exported_api: bool = true,
|
||||
/// Lint: AWAIT_HOLDING_INVALID_TYPE.
|
||||
///
|
||||
/// The list of types which may not be held across an await point.
|
||||
#[lints(await_holding_invalid_type)]
|
||||
await_holding_invalid_types: Vec<DisallowedPath> = Vec::new(),
|
||||
/// DEPRECATED LINT: BLACKLISTED_NAME.
|
||||
///
|
||||
/// Use the Disallowed Names lint instead
|
||||
#[conf_deprecated("Please use `disallowed-names` instead", disallowed_names)]
|
||||
blacklisted_names: Vec<String> = Vec::new(),
|
||||
/// Lint: CARGO_COMMON_METADATA.
|
||||
///
|
||||
/// For internal testing only, ignores the current `publish` settings in the Cargo manifest.
|
||||
#[lints(cargo_common_metadata)]
|
||||
cargo_ignore_publish: bool = false,
|
||||
/// Lint: MISSING_SAFETY_DOC, UNNECESSARY_SAFETY_DOC, MISSING_PANICS_DOC, MISSING_ERRORS_DOC.
|
||||
///
|
||||
/// Whether to also run the listed lints on private items.
|
||||
#[lints(missing_errors_doc, missing_panics_doc, missing_safety_doc, unnecessary_safety_doc)]
|
||||
check_private_items: bool = false,
|
||||
/// Lint: COGNITIVE_COMPLEXITY.
|
||||
///
|
||||
/// The maximum cognitive complexity a function can have
|
||||
#[lints(cognitive_complexity)]
|
||||
cognitive_complexity_threshold: u64 = 25,
|
||||
/// DEPRECATED LINT: CYCLOMATIC_COMPLEXITY.
|
||||
///
|
||||
/// Use the Cognitive Complexity lint instead.
|
||||
#[conf_deprecated("Please use `cognitive-complexity-threshold` instead", cognitive_complexity_threshold)]
|
||||
cyclomatic_complexity_threshold: u64 = 25,
|
||||
/// Lint: DISALLOWED_MACROS.
|
||||
///
|
||||
/// The list of disallowed macros, written as fully qualified paths.
|
||||
#[lints(disallowed_macros)]
|
||||
disallowed_macros: Vec<DisallowedPath> = Vec::new(),
|
||||
/// Lint: DISALLOWED_METHODS.
|
||||
///
|
||||
/// The list of disallowed methods, written as fully qualified paths.
|
||||
#[lints(disallowed_methods)]
|
||||
disallowed_methods: Vec<DisallowedPath> = Vec::new(),
|
||||
/// Lint: DISALLOWED_NAMES.
|
||||
///
|
||||
/// The list of disallowed names to lint about. NB: `bar` is not here since it has legitimate uses. The value
|
||||
/// `".."` can be used as part of the list to indicate that the configured values should be appended to the
|
||||
/// default configuration of Clippy. By default, any configuration will replace the default value.
|
||||
#[lints(disallowed_names)]
|
||||
disallowed_names: Vec<String> = DEFAULT_DISALLOWED_NAMES.iter().map(ToString::to_string).collect(),
|
||||
/// Lint: DISALLOWED_TYPES.
|
||||
///
|
||||
/// The list of disallowed types, written as fully qualified paths.
|
||||
#[lints(disallowed_types)]
|
||||
disallowed_types: Vec<DisallowedPath> = Vec::new(),
|
||||
/// Lint: DOC_MARKDOWN.
|
||||
///
|
||||
/// The list of words this lint should not consider as identifiers needing ticks. The value
|
||||
/// `".."` can be used as part of the list to indicate, that the configured values should be appended to the
|
||||
/// default configuration of Clippy. By default, any configuration will replace the default value. For example:
|
||||
/// * `doc-valid-idents = ["ClipPy"]` would replace the default list with `["ClipPy"]`.
|
||||
/// * `doc-valid-idents = ["ClipPy", ".."]` would append `ClipPy` to the default list.
|
||||
#[lints(doc_markdown)]
|
||||
doc_valid_idents: FxHashSet<String> = DEFAULT_DOC_VALID_IDENTS.iter().map(ToString::to_string).collect(),
|
||||
/// Lint: NON_SEND_FIELDS_IN_SEND_TY.
|
||||
///
|
||||
/// Whether to apply the raw pointer heuristic to determine if a type is `Send`.
|
||||
#[lints(non_send_fields_in_send_ty)]
|
||||
enable_raw_pointer_heuristic_for_send: bool = true,
|
||||
/// Lint: EXPLICIT_ITER_LOOP.
|
||||
///
|
||||
/// Whether to recommend using implicit into iter for reborrowed values.
|
||||
///
|
||||
/// #### Example
|
||||
|
@ -490,174 +452,194 @@ define_Conf! {
|
|||
/// for _ in &*rmvec {}
|
||||
/// for _ in &mut *rmvec {}
|
||||
/// ```
|
||||
#[lints(explicit_iter_loop)]
|
||||
enforce_iter_loop_reborrow: bool = false,
|
||||
/// Lint: MISSING_ENFORCED_IMPORT_RENAMES.
|
||||
///
|
||||
/// The list of imports to always rename, a fully qualified path followed by the rename.
|
||||
#[lints(missing_enforced_import_renames)]
|
||||
enforced_import_renames: Vec<Rename> = Vec::new(),
|
||||
/// Lint: ENUM_VARIANT_NAMES.
|
||||
///
|
||||
/// The minimum number of enum variants for the lints about variant names to trigger
|
||||
#[lints(enum_variant_names)]
|
||||
enum_variant_name_threshold: u64 = 3,
|
||||
/// Lint: LARGE_ENUM_VARIANT.
|
||||
///
|
||||
/// The maximum size of an enum's variant to avoid box suggestion
|
||||
#[lints(large_enum_variant)]
|
||||
enum_variant_size_threshold: u64 = 200,
|
||||
/// Lint: EXCESSIVE_NESTING.
|
||||
///
|
||||
/// The maximum amount of nesting a block can reside in
|
||||
#[lints(excessive_nesting)]
|
||||
excessive_nesting_threshold: u64 = 0,
|
||||
/// Lint: LARGE_FUTURES.
|
||||
///
|
||||
/// The maximum byte size a `Future` can have, before it triggers the `clippy::large_futures` lint
|
||||
#[lints(large_futures)]
|
||||
future_size_threshold: u64 = 16 * 1024,
|
||||
/// Lint: MUTABLE_KEY_TYPE, IFS_SAME_COND, BORROW_INTERIOR_MUTABLE_CONST, DECLARE_INTERIOR_MUTABLE_CONST.
|
||||
///
|
||||
/// A list of paths to types that should be treated as if they do not contain interior mutability
|
||||
#[lints(borrow_interior_mutable_const, declare_interior_mutable_const, ifs_same_cond, mutable_key_type)]
|
||||
ignore_interior_mutability: Vec<String> = Vec::from(["bytes::Bytes".into()]),
|
||||
/// Lint: RESULT_LARGE_ERR.
|
||||
///
|
||||
/// The maximum size of the `Err`-variant in a `Result` returned from a function
|
||||
#[lints(result_large_err)]
|
||||
large_error_threshold: u64 = 128,
|
||||
/// Lint: DECIMAL_LITERAL_REPRESENTATION.
|
||||
///
|
||||
/// The lower bound for linting decimal literals
|
||||
#[lints(decimal_literal_representation)]
|
||||
literal_representation_threshold: u64 = 16384,
|
||||
/// Lint: MANUAL_LET_ELSE.
|
||||
///
|
||||
/// Whether the matches should be considered by the lint, and whether there should
|
||||
/// be filtering for common types.
|
||||
#[lints(manual_let_else)]
|
||||
matches_for_let_else: MatchLintBehaviour = MatchLintBehaviour::WellKnownTypes,
|
||||
/// Lint: FN_PARAMS_EXCESSIVE_BOOLS.
|
||||
///
|
||||
/// The maximum number of bool parameters a function can have
|
||||
#[lints(fn_params_excessive_bools)]
|
||||
max_fn_params_bools: u64 = 3,
|
||||
/// Lint: LARGE_INCLUDE_FILE.
|
||||
///
|
||||
/// The maximum size of a file included via `include_bytes!()` or `include_str!()`, in bytes
|
||||
#[lints(large_include_file)]
|
||||
max_include_file_size: u64 = 1_000_000,
|
||||
/// Lint: STRUCT_EXCESSIVE_BOOLS.
|
||||
///
|
||||
/// The maximum number of bool fields a struct can have
|
||||
#[lints(struct_excessive_bools)]
|
||||
max_struct_bools: u64 = 3,
|
||||
/// Lint: INDEX_REFUTABLE_SLICE.
|
||||
///
|
||||
/// When Clippy suggests using a slice pattern, this is the maximum number of elements allowed in
|
||||
/// the slice pattern that is suggested. If more elements are necessary, the lint is suppressed.
|
||||
/// For example, `[_, _, _, e, ..]` is a slice pattern with 4 elements.
|
||||
#[lints(index_refutable_slice)]
|
||||
max_suggested_slice_pattern_length: u64 = 3,
|
||||
/// Lint: TYPE_REPETITION_IN_BOUNDS.
|
||||
///
|
||||
/// The maximum number of bounds a trait can have to be linted
|
||||
#[lints(type_repetition_in_bounds)]
|
||||
max_trait_bounds: u64 = 3,
|
||||
/// Lint: MIN_IDENT_CHARS.
|
||||
///
|
||||
/// Minimum chars an ident can have, anything below or equal to this will be linted.
|
||||
#[lints(min_ident_chars)]
|
||||
min_ident_chars_threshold: u64 = 1,
|
||||
/// Lint: MISSING_DOCS_IN_PRIVATE_ITEMS.
|
||||
///
|
||||
/// Whether to **only** check for missing documentation in items visible within the current
|
||||
/// crate. For example, `pub(crate)` items.
|
||||
#[lints(missing_docs_in_private_items)]
|
||||
missing_docs_in_crate_items: bool = false,
|
||||
/// Lint: MANUAL_SPLIT_ONCE, MANUAL_STR_REPEAT, CLONED_INSTEAD_OF_COPIED, REDUNDANT_FIELD_NAMES, OPTION_MAP_UNWRAP_OR, REDUNDANT_STATIC_LIFETIMES, FILTER_MAP_NEXT, CHECKED_CONVERSIONS, MANUAL_RANGE_CONTAINS, USE_SELF, MEM_REPLACE_WITH_DEFAULT, MANUAL_NON_EXHAUSTIVE, OPTION_AS_REF_DEREF, MAP_UNWRAP_OR, MATCH_LIKE_MATCHES_MACRO, MANUAL_STRIP, MISSING_CONST_FOR_FN, UNNESTED_OR_PATTERNS, FROM_OVER_INTO, PTR_AS_PTR, IF_THEN_SOME_ELSE_NONE, APPROX_CONSTANT, DEPRECATED_CFG_ATTR, INDEX_REFUTABLE_SLICE, MAP_CLONE, BORROW_AS_PTR, MANUAL_BITS, ERR_EXPECT, CAST_ABS_TO_UNSIGNED, UNINLINED_FORMAT_ARGS, MANUAL_CLAMP, MANUAL_LET_ELSE, UNCHECKED_DURATION_SUBTRACTION, COLLAPSIBLE_STR_REPLACE, SEEK_FROM_CURRENT, SEEK_REWIND, UNNECESSARY_LAZY_EVALUATIONS, TRANSMUTE_PTR_TO_REF, ALMOST_COMPLETE_RANGE, NEEDLESS_BORROW, DERIVABLE_IMPLS, MANUAL_IS_ASCII_CHECK, MANUAL_REM_EUCLID, MANUAL_RETAIN, TYPE_REPETITION_IN_BOUNDS, TUPLE_ARRAY_CONVERSIONS, MANUAL_TRY_FOLD, MANUAL_HASH_ONE, ITER_KV_MAP, MANUAL_C_STR_LITERALS, ASSIGNING_CLONES, LEGACY_NUMERIC_CONSTANTS, MANUAL_PATTERN_CHAR_COMPARISON, ALLOW_ATTRIBUTES, ALLOW_ATTRIBUTES_WITHOUT_REASON, COLLAPSIBLE_MATCH.
|
||||
///
|
||||
/// The minimum rust version that the project supports. Defaults to the `rust-version` field in `Cargo.toml`
|
||||
#[default_text = "current version"]
|
||||
#[lints(
|
||||
allow_attributes,
|
||||
allow_attributes_without_reason,
|
||||
almost_complete_range,
|
||||
approx_constant,
|
||||
assigning_clones,
|
||||
borrow_as_ptr,
|
||||
cast_abs_to_unsigned,
|
||||
checked_conversions,
|
||||
cloned_instead_of_copied,
|
||||
collapsible_match,
|
||||
collapsible_str_replace,
|
||||
deprecated_cfg_attr,
|
||||
derivable_impls,
|
||||
err_expect,
|
||||
filter_map_next,
|
||||
from_over_into,
|
||||
if_then_some_else_none,
|
||||
index_refutable_slice,
|
||||
iter_kv_map,
|
||||
legacy_numeric_constants,
|
||||
manual_bits,
|
||||
manual_c_str_literals,
|
||||
manual_clamp,
|
||||
manual_hash_one,
|
||||
manual_is_ascii_check,
|
||||
manual_let_else,
|
||||
manual_non_exhaustive,
|
||||
manual_pattern_char_comparison,
|
||||
manual_range_contains,
|
||||
manual_rem_euclid,
|
||||
manual_retain,
|
||||
manual_split_once,
|
||||
manual_str_repeat,
|
||||
manual_strip,
|
||||
manual_try_fold,
|
||||
map_clone,
|
||||
map_unwrap_or,
|
||||
match_like_matches_macro,
|
||||
mem_replace_with_default,
|
||||
missing_const_for_fn,
|
||||
needless_borrow,
|
||||
option_as_ref_deref,
|
||||
option_map_unwrap_or,
|
||||
ptr_as_ptr,
|
||||
redundant_field_names,
|
||||
redundant_static_lifetimes,
|
||||
seek_from_current,
|
||||
seek_rewind,
|
||||
transmute_ptr_to_ref,
|
||||
tuple_array_conversions,
|
||||
type_repetition_in_bounds,
|
||||
unchecked_duration_subtraction,
|
||||
uninlined_format_args,
|
||||
unnecessary_lazy_evaluations,
|
||||
unnested_or_patterns,
|
||||
use_self,
|
||||
)]
|
||||
msrv: Msrv = Msrv::empty(),
|
||||
/// Lint: LARGE_TYPES_PASSED_BY_VALUE.
|
||||
///
|
||||
/// The minimum size (in bytes) to consider a type for passing by reference instead of by value.
|
||||
#[lints(large_types_passed_by_value)]
|
||||
pass_by_value_size_limit: u64 = 256,
|
||||
/// Lint: PUB_UNDERSCORE_FIELDS.
|
||||
///
|
||||
/// Lint "public" fields in a struct that are prefixed with an underscore based on their
|
||||
/// exported visibility, or whether they are marked as "pub".
|
||||
#[lints(pub_underscore_fields)]
|
||||
pub_underscore_fields_behavior: PubUnderscoreFieldsBehaviour = PubUnderscoreFieldsBehaviour::PubliclyExported,
|
||||
/// Lint: SEMICOLON_INSIDE_BLOCK.
|
||||
///
|
||||
/// Whether to lint only if it's multiline.
|
||||
#[lints(semicolon_inside_block)]
|
||||
semicolon_inside_block_ignore_singleline: bool = false,
|
||||
/// Lint: SEMICOLON_OUTSIDE_BLOCK.
|
||||
///
|
||||
/// Whether to lint only if it's singleline.
|
||||
#[lints(semicolon_outside_block)]
|
||||
semicolon_outside_block_ignore_multiline: bool = false,
|
||||
/// Lint: MANY_SINGLE_CHAR_NAMES.
|
||||
///
|
||||
/// The maximum number of single char bindings a scope may have
|
||||
#[lints(many_single_char_names)]
|
||||
single_char_binding_names_threshold: u64 = 4,
|
||||
/// Lint: LARGE_STACK_FRAMES.
|
||||
///
|
||||
/// The maximum allowed stack size for functions in bytes
|
||||
#[lints(large_stack_frames)]
|
||||
stack_size_threshold: u64 = 512_000,
|
||||
/// Lint: NONSTANDARD_MACRO_BRACES.
|
||||
///
|
||||
/// Enforce the named macros always use the braces specified.
|
||||
///
|
||||
/// A `MacroMatcher` can be added like so `{ name = "macro_name", brace = "(" }`. If the macro
|
||||
/// could be used with a full path two `MacroMatcher`s have to be added one with the full path
|
||||
/// `crate_name::macro_name` and one with just the macro name.
|
||||
#[lints(nonstandard_macro_braces)]
|
||||
standard_macro_braces: Vec<MacroMatcher> = Vec::new(),
|
||||
/// Lint: STRUCT_FIELD_NAMES.
|
||||
///
|
||||
/// The minimum number of struct fields for the lints about field names to trigger
|
||||
#[lints(struct_field_names)]
|
||||
struct_field_name_threshold: u64 = 3,
|
||||
/// Lint: INDEXING_SLICING.
|
||||
///
|
||||
/// Whether to suppress a restriction lint in constant code. In same
|
||||
/// cases the restructured operation might not be unavoidable, as the
|
||||
/// suggested counterparts are unavailable in constant code. This
|
||||
/// configuration will cause restriction lints to trigger even
|
||||
/// if no suggestion can be made.
|
||||
#[lints(indexing_slicing)]
|
||||
suppress_restriction_lint_in_const: bool = false,
|
||||
/// Lint: BOXED_LOCAL, USELESS_VEC.
|
||||
///
|
||||
/// The maximum size of objects (in bytes) that will be linted. Larger objects are ok on the heap
|
||||
#[lints(boxed_local, useless_vec)]
|
||||
too_large_for_stack: u64 = 200,
|
||||
/// Lint: TOO_MANY_ARGUMENTS.
|
||||
///
|
||||
/// The maximum number of argument a function or method can have
|
||||
#[lints(too_many_arguments)]
|
||||
too_many_arguments_threshold: u64 = 7,
|
||||
/// Lint: TOO_MANY_LINES.
|
||||
///
|
||||
/// The maximum number of lines a function or method can have
|
||||
#[lints(too_many_lines)]
|
||||
too_many_lines_threshold: u64 = 100,
|
||||
/// Lint: TRIVIALLY_COPY_PASS_BY_REF.
|
||||
///
|
||||
/// The maximum size (in bytes) to consider a `Copy` type for passing by value instead of by
|
||||
/// reference. By default there is no limit
|
||||
#[default_text = "target_pointer_width * 2"]
|
||||
#[lints(trivially_copy_pass_by_ref)]
|
||||
trivial_copy_size_limit: Option<u64> = None,
|
||||
/// Lint: TYPE_COMPLEXITY.
|
||||
///
|
||||
/// The maximum complexity a type can have
|
||||
#[lints(type_complexity)]
|
||||
type_complexity_threshold: u64 = 250,
|
||||
/// Lint: UNNECESSARY_BOX_RETURNS.
|
||||
///
|
||||
/// The byte size a `T` in `Box<T>` can have, below which it triggers the `clippy::unnecessary_box` lint
|
||||
#[lints(unnecessary_box_returns)]
|
||||
unnecessary_box_size: u64 = 128,
|
||||
/// Lint: UNREADABLE_LITERAL.
|
||||
///
|
||||
/// Should the fraction of a decimal be linted to include separators.
|
||||
#[lints(unreadable_literal)]
|
||||
unreadable_literal_lint_fractions: bool = true,
|
||||
/// Lint: UPPER_CASE_ACRONYMS.
|
||||
///
|
||||
/// Enables verbose mode. Triggers if there is more than one uppercase char next to each other
|
||||
#[lints(upper_case_acronyms)]
|
||||
upper_case_acronyms_aggressive: bool = false,
|
||||
/// Lint: VEC_BOX.
|
||||
///
|
||||
/// The size of the boxed type in bytes, where boxing in a `Vec` is allowed
|
||||
#[lints(vec_box)]
|
||||
vec_box_size_threshold: u64 = 4096,
|
||||
/// Lint: VERBOSE_BIT_MASK.
|
||||
///
|
||||
/// The maximum allowed size of a bit mask before suggesting to use 'trailing_zeros'
|
||||
#[lints(verbose_bit_mask)]
|
||||
verbose_bit_mask_threshold: u64 = 1,
|
||||
/// Lint: WILDCARD_IMPORTS.
|
||||
///
|
||||
/// Whether to allow certain wildcard imports (prelude, super in tests).
|
||||
#[lints(wildcard_imports)]
|
||||
warn_on_all_wildcard_imports: bool = false,
|
||||
/// Lint: MACRO_METAVARS_IN_UNSAFE.
|
||||
///
|
||||
/// Whether to also emit warnings for unsafe blocks with metavariable expansions in **private** macros.
|
||||
#[lints(macro_metavars_in_unsafe)]
|
||||
warn_unsafe_macro_metavars_in_private_macros: bool = false,
|
||||
}
|
||||
|
||||
|
|
|
@ -1,11 +1,12 @@
|
|||
use std::fmt::{self, Write};
|
||||
use itertools::Itertools;
|
||||
use std::fmt;
|
||||
|
||||
#[derive(Debug, Clone, Default)]
|
||||
pub struct ClippyConfiguration {
|
||||
pub name: String,
|
||||
pub default: String,
|
||||
pub lints: Vec<String>,
|
||||
pub doc: String,
|
||||
pub lints: &'static [&'static str],
|
||||
pub doc: &'static str,
|
||||
pub deprecation_reason: Option<&'static str>,
|
||||
}
|
||||
|
||||
|
@ -20,54 +21,16 @@ impl fmt::Display for ClippyConfiguration {
|
|||
}
|
||||
|
||||
impl ClippyConfiguration {
|
||||
pub fn new(
|
||||
name: &'static str,
|
||||
default: String,
|
||||
doc_comment: &'static str,
|
||||
deprecation_reason: Option<&'static str>,
|
||||
) -> Self {
|
||||
let (mut lints, doc) = parse_config_field_doc(doc_comment)
|
||||
.unwrap_or_else(|| (vec![], "[ERROR] MALFORMED DOC COMMENT".to_string()));
|
||||
|
||||
lints.sort();
|
||||
|
||||
Self {
|
||||
name: to_kebab(name),
|
||||
lints,
|
||||
doc,
|
||||
default,
|
||||
deprecation_reason,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn to_markdown_paragraph(&self) -> String {
|
||||
let mut out = format!(
|
||||
"## `{}`\n{}\n\n",
|
||||
format!(
|
||||
"## `{}`\n{}\n\n**Default Value:** `{}`\n\n---\n**Affected lints:**\n{}\n\n",
|
||||
self.name,
|
||||
self.doc
|
||||
.lines()
|
||||
.map(|line| line.strip_prefix(" ").unwrap_or(line))
|
||||
.collect::<Vec<_>>()
|
||||
.join("\n"),
|
||||
);
|
||||
|
||||
if !self.default.is_empty() {
|
||||
write!(out, "**Default Value:** `{}`\n\n", self.default).unwrap();
|
||||
}
|
||||
|
||||
write!(
|
||||
out,
|
||||
"---\n**Affected lints:**\n{}\n\n",
|
||||
self.lints
|
||||
.iter()
|
||||
.map(|name| name.to_string().split_whitespace().next().unwrap().to_string())
|
||||
.map(|name| format!("* [`{name}`](https://rust-lang.github.io/rust-clippy/master/index.html#{name})"))
|
||||
.collect::<Vec<_>>()
|
||||
.join("\n"),
|
||||
self.doc.lines().map(|x| x.strip_prefix(' ').unwrap_or(x)).join("\n"),
|
||||
self.default,
|
||||
self.lints.iter().format_with("\n", |name, f| f(&format_args!(
|
||||
"* [`{name}`](https://rust-lang.github.io/rust-clippy/master/index.html#{name})"
|
||||
))),
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
out
|
||||
}
|
||||
|
||||
pub fn to_markdown_link(&self) -> String {
|
||||
|
@ -75,47 +38,3 @@ impl ClippyConfiguration {
|
|||
format!("[`{}`]: {BOOK_CONFIGS_PATH}#{}", self.name, self.name)
|
||||
}
|
||||
}
|
||||
|
||||
/// This parses the field documentation of the config struct.
|
||||
///
|
||||
/// ```rust, ignore
|
||||
/// parse_config_field_doc(cx, "Lint: LINT_NAME_1, LINT_NAME_2. Papa penguin, papa penguin")
|
||||
/// ```
|
||||
///
|
||||
/// Would yield:
|
||||
/// ```rust, ignore
|
||||
/// Some(["lint_name_1", "lint_name_2"], "Papa penguin, papa penguin")
|
||||
/// ```
|
||||
fn parse_config_field_doc(doc_comment: &str) -> Option<(Vec<String>, String)> {
|
||||
const DOC_START: &str = " Lint: ";
|
||||
if doc_comment.starts_with(DOC_START)
|
||||
&& let Some(split_pos) = doc_comment.find('.')
|
||||
{
|
||||
let mut doc_comment = doc_comment.to_string();
|
||||
let mut documentation = doc_comment.split_off(split_pos);
|
||||
|
||||
// Extract lints
|
||||
doc_comment.make_ascii_lowercase();
|
||||
let lints: Vec<String> = doc_comment
|
||||
.split_off(DOC_START.len())
|
||||
.lines()
|
||||
.next()
|
||||
.unwrap()
|
||||
.split(", ")
|
||||
.map(str::to_string)
|
||||
.collect();
|
||||
|
||||
// Format documentation correctly
|
||||
// split off leading `.` from lint name list and indent for correct formatting
|
||||
documentation = documentation.trim_start_matches('.').trim().replace("\n ", "\n ");
|
||||
|
||||
Some((lints, documentation))
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
|
||||
/// Transforms a given `snake_case_string` to a tasty `kebab-case-string`
|
||||
fn to_kebab(config_name: &str) -> String {
|
||||
config_name.replace('_', "-")
|
||||
}
|
||||
|
|
|
@ -496,7 +496,7 @@ pub fn explain(name: &str) -> i32 {
|
|||
// Check if the lint has configuration
|
||||
let mut mdconf = get_configuration_metadata();
|
||||
let name = name.to_ascii_lowercase();
|
||||
mdconf.retain(|cconf| cconf.lints.contains(&name));
|
||||
mdconf.retain(|cconf| cconf.lints.contains(&&*name));
|
||||
if !mdconf.is_empty() {
|
||||
println!("### Configuration for {}:\n", info.lint.name_lower());
|
||||
for conf in mdconf {
|
||||
|
|
|
@ -165,7 +165,7 @@ impl MetadataCollector {
|
|||
fn get_lint_configs(&self, lint_name: &str) -> Option<String> {
|
||||
self.config
|
||||
.iter()
|
||||
.filter(|config| config.lints.iter().any(|lint| lint == lint_name))
|
||||
.filter(|config| config.lints.iter().any(|&lint| lint == lint_name))
|
||||
.map(ToString::to_string)
|
||||
.reduce(|acc, x| acc + &x)
|
||||
.map(|configurations| {
|
||||
|
|
Loading…
Reference in a new issue