|
1 | 1 | use crate::msrvs::Msrv;
|
2 |
| -use crate::types::{DisallowedPath, MacroMatcher, MatchLintBehaviour, PubUnderscoreFieldsBehaviour, Rename}; |
| 2 | +use crate::types::{ |
| 3 | + DisallowedPath, MacroMatcher, MatchLintBehaviour, PubUnderscoreFieldsBehaviour, Rename, SourceItemOrderingCategory, |
| 4 | + SourceItemOrderingEnableFor, SourceItemOrderingModuleItemGroupings, SourceItemOrderingModuleItemKind, |
| 5 | + SourceItemOrderingTraitAssocItemKind, SourceItemOrderingTraitAssocItemKinds, |
| 6 | +}; |
3 | 7 | use crate::ClippyConfiguration;
|
4 | 8 | use rustc_errors::Applicability;
|
5 | 9 | use rustc_session::Session;
|
@@ -46,6 +50,32 @@ const DEFAULT_ALLOWED_IDENTS_BELOW_MIN_CHARS: &[&str] = &["i", "j", "x", "y", "z
|
46 | 50 | const DEFAULT_ALLOWED_PREFIXES: &[&str] = &["to", "as", "into", "from", "try_into", "try_from"];
|
47 | 51 | const DEFAULT_ALLOWED_TRAITS_WITH_RENAMED_PARAMS: &[&str] =
|
48 | 52 | &["core::convert::From", "core::convert::TryFrom", "core::str::FromStr"];
|
| 53 | +const DEFAULT_MODULE_ITEM_ORDERING_GROUPS: &[(&str, &[SourceItemOrderingModuleItemKind])] = { |
| 54 | + #[allow(clippy::enum_glob_use)] // Very local glob use for legibility. |
| 55 | + use SourceItemOrderingModuleItemKind::*; |
| 56 | + &[ |
| 57 | + ("modules", &[Mod, ForeignMod]), |
| 58 | + ("use", &[Use]), |
| 59 | + ("macros", &[Macro]), |
| 60 | + ("global_asm", &[GlobalAsm]), |
| 61 | + ("UPPER_SNAKE_CASE", &[Static, Const]), |
| 62 | + ( |
| 63 | + "PascalCase", |
| 64 | + &[TyAlias, OpaqueTy, Enum, Struct, Union, Trait, TraitAlias, Impl], |
| 65 | + ), |
| 66 | + ("lower_snake_case", &[Fn]), |
| 67 | + ] |
| 68 | +}; |
| 69 | +const DEFAULT_TRAIT_ASSOC_ITEM_KINDS_ORDER: &[SourceItemOrderingTraitAssocItemKind] = { |
| 70 | + #[allow(clippy::enum_glob_use)] // Very local glob use for legibility. |
| 71 | + use SourceItemOrderingTraitAssocItemKind::*; |
| 72 | + &[Const, Type, Fn] |
| 73 | +}; |
| 74 | +const DEFAULT_ENABLE_SOURCE_ITEM_ORDERING_FOR: &[SourceItemOrderingCategory] = { |
| 75 | + #[allow(clippy::enum_glob_use)] // Very local glob use for legibility. |
| 76 | + use SourceItemOrderingCategory::*; |
| 77 | + &[Enum, Impl, Module, Struct, Trait] |
| 78 | +}; |
49 | 79 |
|
50 | 80 | /// Conf with parse errors
|
51 | 81 | #[derive(Default)]
|
@@ -434,6 +464,9 @@ define_Conf! {
|
434 | 464 | /// Whether to apply the raw pointer heuristic to determine if a type is `Send`.
|
435 | 465 | #[lints(non_send_fields_in_send_ty)]
|
436 | 466 | enable_raw_pointer_heuristic_for_send: bool = true,
|
| 467 | + /// Which kind of elements should be ordered internally, possible values being `enum`, `impl`, `module`, `struct`, `trait`. |
| 468 | + #[lints(arbitrary_source_item_ordering)] |
| 469 | + enable_source_item_ordering_for: SourceItemOrderingEnableFor = DEFAULT_ENABLE_SOURCE_ITEM_ORDERING_FOR.into(), |
437 | 470 | /// Whether to recommend using implicit into iter for reborrowed values.
|
438 | 471 | ///
|
439 | 472 | /// #### Example
|
@@ -505,6 +538,9 @@ define_Conf! {
|
505 | 538 | /// crate. For example, `pub(crate)` items.
|
506 | 539 | #[lints(missing_docs_in_private_items)]
|
507 | 540 | missing_docs_in_crate_items: bool = false,
|
| 541 | + /// The named groupings of different source item kinds within modules. |
| 542 | + #[lints(arbitrary_source_item_ordering)] |
| 543 | + module_item_order_groupings: SourceItemOrderingModuleItemGroupings = DEFAULT_MODULE_ITEM_ORDERING_GROUPS.into(), |
508 | 544 | /// The minimum rust version that the project supports. Defaults to the `rust-version` field in `Cargo.toml`
|
509 | 545 | #[default_text = "current version"]
|
510 | 546 | #[lints(
|
@@ -611,6 +647,9 @@ define_Conf! {
|
611 | 647 | /// The maximum number of lines a function or method can have
|
612 | 648 | #[lints(too_many_lines)]
|
613 | 649 | too_many_lines_threshold: u64 = 100,
|
| 650 | + /// The order of associated items in traits. |
| 651 | + #[lints(arbitrary_source_item_ordering)] |
| 652 | + trait_assoc_item_kinds_order: SourceItemOrderingTraitAssocItemKinds = DEFAULT_TRAIT_ASSOC_ITEM_KINDS_ORDER.into(), |
614 | 653 | /// The maximum size (in bytes) to consider a `Copy` type for passing by value instead of by
|
615 | 654 | /// reference. By default there is no limit
|
616 | 655 | #[default_text = "target_pointer_width * 2"]
|
|
0 commit comments