|
1 | 1 | use crate::ClippyConfiguration;
|
2 | 2 | use crate::msrvs::Msrv;
|
3 |
| -use crate::types::{DisallowedPath, MacroMatcher, MatchLintBehaviour, PubUnderscoreFieldsBehaviour, Rename}; |
| 3 | +use crate::types::{ |
| 4 | + DisallowedPath, MacroMatcher, MatchLintBehaviour, PubUnderscoreFieldsBehaviour, Rename, SourceItemOrderingCategory, |
| 5 | + SourceItemOrderingEnableFor, SourceItemOrderingModuleItemGroupings, SourceItemOrderingModuleItemKind, |
| 6 | + SourceItemOrderingTraitAssocItemKind, SourceItemOrderingTraitAssocItemKinds, |
| 7 | +}; |
4 | 8 | use rustc_errors::Applicability;
|
5 | 9 | use rustc_session::Session;
|
6 | 10 | use rustc_span::edit_distance::edit_distance;
|
@@ -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)]
|
@@ -459,6 +489,9 @@ define_Conf! {
|
459 | 489 | /// Whether to apply the raw pointer heuristic to determine if a type is `Send`.
|
460 | 490 | #[lints(non_send_fields_in_send_ty)]
|
461 | 491 | enable_raw_pointer_heuristic_for_send: bool = true,
|
| 492 | + /// Which kind of elements should be ordered internally, possible values being `enum`, `impl`, `module`, `struct`, `trait`. |
| 493 | + #[lints(arbitrary_source_item_ordering)] |
| 494 | + enable_source_item_ordering_for: SourceItemOrderingEnableFor = DEFAULT_ENABLE_SOURCE_ITEM_ORDERING_FOR.into(), |
462 | 495 | /// Whether to recommend using implicit into iter for reborrowed values.
|
463 | 496 | ///
|
464 | 497 | /// #### Example
|
@@ -530,6 +563,9 @@ define_Conf! {
|
530 | 563 | /// crate. For example, `pub(crate)` items.
|
531 | 564 | #[lints(missing_docs_in_private_items)]
|
532 | 565 | missing_docs_in_crate_items: bool = false,
|
| 566 | + /// The named groupings of different source item kinds within modules. |
| 567 | + #[lints(arbitrary_source_item_ordering)] |
| 568 | + module_item_order_groupings: SourceItemOrderingModuleItemGroupings = DEFAULT_MODULE_ITEM_ORDERING_GROUPS.into(), |
533 | 569 | /// The minimum rust version that the project supports. Defaults to the `rust-version` field in `Cargo.toml`
|
534 | 570 | #[default_text = "current version"]
|
535 | 571 | #[lints(
|
@@ -637,6 +673,9 @@ define_Conf! {
|
637 | 673 | /// The maximum number of lines a function or method can have
|
638 | 674 | #[lints(too_many_lines)]
|
639 | 675 | too_many_lines_threshold: u64 = 100,
|
| 676 | + /// The order of associated items in traits. |
| 677 | + #[lints(arbitrary_source_item_ordering)] |
| 678 | + trait_assoc_item_kinds_order: SourceItemOrderingTraitAssocItemKinds = DEFAULT_TRAIT_ASSOC_ITEM_KINDS_ORDER.into(), |
640 | 679 | /// The maximum size (in bytes) to consider a `Copy` type for passing by value instead of by
|
641 | 680 | /// reference. By default there is no limit
|
642 | 681 | #[default_text = "target_pointer_width * 2"]
|
|
0 commit comments