mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-10-01 06:11:35 +00:00
Move incorrect case diagnostic things into their module
This commit is contained in:
parent
91def936bc
commit
69782f55de
4 changed files with 88 additions and 92 deletions
|
@ -4,92 +4,10 @@ mod match_check;
|
|||
mod unsafe_check;
|
||||
mod decl_check;
|
||||
|
||||
use std::fmt;
|
||||
|
||||
use base_db::CrateId;
|
||||
use hir_def::ModuleDefId;
|
||||
use hir_expand::HirFileId;
|
||||
use syntax::{ast, AstPtr};
|
||||
|
||||
use crate::db::HirDatabase;
|
||||
|
||||
pub use crate::diagnostics::{
|
||||
decl_check::{incorrect_case, IncorrectCase},
|
||||
expr::{
|
||||
record_literal_missing_fields, record_pattern_missing_fields, BodyValidationDiagnostic,
|
||||
},
|
||||
unsafe_check::missing_unsafe,
|
||||
};
|
||||
|
||||
pub fn validate_module_item(
|
||||
db: &dyn HirDatabase,
|
||||
krate: CrateId,
|
||||
owner: ModuleDefId,
|
||||
) -> Vec<IncorrectCase> {
|
||||
let _p = profile::span("validate_module_item");
|
||||
let mut validator = decl_check::DeclValidator::new(db, krate);
|
||||
validator.validate_item(owner);
|
||||
validator.sink
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub enum CaseType {
|
||||
// `some_var`
|
||||
LowerSnakeCase,
|
||||
// `SOME_CONST`
|
||||
UpperSnakeCase,
|
||||
// `SomeStruct`
|
||||
UpperCamelCase,
|
||||
}
|
||||
|
||||
impl fmt::Display for CaseType {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
let repr = match self {
|
||||
CaseType::LowerSnakeCase => "snake_case",
|
||||
CaseType::UpperSnakeCase => "UPPER_SNAKE_CASE",
|
||||
CaseType::UpperCamelCase => "CamelCase",
|
||||
};
|
||||
|
||||
write!(f, "{}", repr)
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub enum IdentType {
|
||||
Constant,
|
||||
Enum,
|
||||
Field,
|
||||
Function,
|
||||
Parameter,
|
||||
StaticVariable,
|
||||
Structure,
|
||||
Variable,
|
||||
Variant,
|
||||
}
|
||||
|
||||
impl fmt::Display for IdentType {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
let repr = match self {
|
||||
IdentType::Constant => "Constant",
|
||||
IdentType::Enum => "Enum",
|
||||
IdentType::Field => "Field",
|
||||
IdentType::Function => "Function",
|
||||
IdentType::Parameter => "Parameter",
|
||||
IdentType::StaticVariable => "Static variable",
|
||||
IdentType::Structure => "Structure",
|
||||
IdentType::Variable => "Variable",
|
||||
IdentType::Variant => "Variant",
|
||||
};
|
||||
|
||||
write!(f, "{}", repr)
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct IncorrectCase {
|
||||
pub file: HirFileId,
|
||||
pub ident: AstPtr<ast::Name>,
|
||||
pub expected_case: CaseType,
|
||||
pub ident_type: IdentType,
|
||||
pub ident_text: String,
|
||||
pub suggested_text: String,
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue