|
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, SourceItemOrdering, |
| 5 | + SourceItemOrderingCategory, 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;
|
@@ -47,6 +51,29 @@ const DEFAULT_ALLOWED_IDENTS_BELOW_MIN_CHARS: &[&str] = &["i", "j", "x", "y", "z
|
47 | 51 | const DEFAULT_ALLOWED_PREFIXES: &[&str] = &["to", "as", "into", "from", "try_into", "try_from"];
|
48 | 52 | const DEFAULT_ALLOWED_TRAITS_WITH_RENAMED_PARAMS: &[&str] =
|
49 | 53 | &["core::convert::From", "core::convert::TryFrom", "core::str::FromStr"];
|
| 54 | +const DEFAULT_MODULE_ITEM_ORDERING_GROUPS: &[(&str, &[SourceItemOrderingModuleItemKind])] = { |
| 55 | + #[allow(clippy::enum_glob_use)] // Very local glob use for legibility. |
| 56 | + use SourceItemOrderingModuleItemKind::*; |
| 57 | + &[ |
| 58 | + ("modules", &[ExternCrate, Mod, ForeignMod]), |
| 59 | + ("use", &[Use]), |
| 60 | + ("macros", &[Macro]), |
| 61 | + ("global_asm", &[GlobalAsm]), |
| 62 | + ("UPPER_SNAKE_CASE", &[Static, Const]), |
| 63 | + ("PascalCase", &[TyAlias, Enum, Struct, Union, Trait, TraitAlias, Impl]), |
| 64 | + ("lower_snake_case", &[Fn]), |
| 65 | + ] |
| 66 | +}; |
| 67 | +const DEFAULT_TRAIT_ASSOC_ITEM_KINDS_ORDER: &[SourceItemOrderingTraitAssocItemKind] = { |
| 68 | + #[allow(clippy::enum_glob_use)] // Very local glob use for legibility. |
| 69 | + use SourceItemOrderingTraitAssocItemKind::*; |
| 70 | + &[Const, Type, Fn] |
| 71 | +}; |
| 72 | +const DEFAULT_SOURCE_ITEM_ORDERING: &[SourceItemOrderingCategory] = { |
| 73 | + #[allow(clippy::enum_glob_use)] // Very local glob use for legibility. |
| 74 | + use SourceItemOrderingCategory::*; |
| 75 | + &[Enum, Impl, Module, Struct, Trait] |
| 76 | +}; |
50 | 77 |
|
51 | 78 | /// Conf with parse errors
|
52 | 79 | #[derive(Default)]
|
@@ -533,6 +560,9 @@ define_Conf! {
|
533 | 560 | /// crate. For example, `pub(crate)` items.
|
534 | 561 | #[lints(missing_docs_in_private_items)]
|
535 | 562 | missing_docs_in_crate_items: bool = false,
|
| 563 | + /// The named groupings of different source item kinds within modules. |
| 564 | + #[lints(arbitrary_source_item_ordering)] |
| 565 | + module_item_order_groupings: SourceItemOrderingModuleItemGroupings = DEFAULT_MODULE_ITEM_ORDERING_GROUPS.into(), |
536 | 566 | /// The minimum rust version that the project supports. Defaults to the `rust-version` field in `Cargo.toml`
|
537 | 567 | #[default_text = "current version"]
|
538 | 568 | #[lints(
|
@@ -612,6 +642,9 @@ define_Conf! {
|
612 | 642 | /// The maximum number of single char bindings a scope may have
|
613 | 643 | #[lints(many_single_char_names)]
|
614 | 644 | single_char_binding_names_threshold: u64 = 4,
|
| 645 | + /// Which kind of elements should be ordered internally, possible values being `enum`, `impl`, `module`, `struct`, `trait`. |
| 646 | + #[lints(arbitrary_source_item_ordering)] |
| 647 | + source_item_ordering: SourceItemOrdering = DEFAULT_SOURCE_ITEM_ORDERING.into(), |
615 | 648 | /// The maximum allowed stack size for functions in bytes
|
616 | 649 | #[lints(large_stack_frames)]
|
617 | 650 | stack_size_threshold: u64 = 512_000,
|
@@ -641,6 +674,9 @@ define_Conf! {
|
641 | 674 | /// The maximum number of lines a function or method can have
|
642 | 675 | #[lints(too_many_lines)]
|
643 | 676 | too_many_lines_threshold: u64 = 100,
|
| 677 | + /// The order of associated items in traits. |
| 678 | + #[lints(arbitrary_source_item_ordering)] |
| 679 | + trait_assoc_item_kinds_order: SourceItemOrderingTraitAssocItemKinds = DEFAULT_TRAIT_ASSOC_ITEM_KINDS_ORDER.into(), |
644 | 680 | /// The maximum size (in bytes) to consider a `Copy` type for passing by value instead of by
|
645 | 681 | /// reference. By default there is no limit
|
646 | 682 | #[default_text = "target_pointer_width * 2"]
|
|
0 commit comments