perl_diagnostics/codes/
category.rs1use std::fmt;
2
3use super::DiagnosticCode;
4
5#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
7#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
8pub enum DiagnosticCategory {
9 Parser,
11 StrictWarnings,
13 PackageModule,
15 Subroutine,
17 BestPractices,
19 Deprecated,
21 Security,
23 Import,
25 Heredoc,
27 PerlCritic,
29}
30
31impl fmt::Display for DiagnosticCategory {
32 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
33 match self {
34 Self::Parser => write!(f, "Parser"),
35 Self::StrictWarnings => write!(f, "Strict/Warnings"),
36 Self::PackageModule => write!(f, "Package/Module"),
37 Self::Subroutine => write!(f, "Subroutine"),
38 Self::BestPractices => write!(f, "Best Practices"),
39 Self::Deprecated => write!(f, "Deprecated"),
40 Self::Security => write!(f, "Security"),
41 Self::Import => write!(f, "Import"),
42 Self::Heredoc => write!(f, "Heredoc"),
43 Self::PerlCritic => write!(f, "Perl::Critic"),
44 }
45 }
46}
47
48impl DiagnosticCode {
49 pub fn category(&self) -> DiagnosticCategory {
51 match self {
52 Self::ParseError | Self::SyntaxError | Self::UnexpectedEof => {
53 DiagnosticCategory::Parser
54 }
55
56 Self::MissingStrict
57 | Self::MissingWarnings
58 | Self::UnusedVariable
59 | Self::UndefinedVariable
60 | Self::VariableShadowing
61 | Self::VariableRedeclaration
62 | Self::DuplicateParameter
63 | Self::ParameterShadowsGlobal
64 | Self::UnusedParameter
65 | Self::UnquotedBareword
66 | Self::UninitializedVariable
67 | Self::MisspelledPragma
68 | Self::CaptureVarWithoutRegexMatch
69 | Self::PhaseScopedStrictPragma
70 | Self::PhaseScopedWarningsPragma => DiagnosticCategory::StrictWarnings,
71
72 Self::MissingPackageDeclaration | Self::DuplicatePackage => {
73 DiagnosticCategory::PackageModule
74 }
75
76 Self::DuplicateSubroutine
77 | Self::MissingReturn
78 | Self::InvalidPrototype
79 | Self::RoleConflict
80 | Self::MissingPodCoverage => DiagnosticCategory::Subroutine,
81
82 Self::BarewordFilehandle
83 | Self::TwoArgOpen
84 | Self::ImplicitReturn
85 | Self::AssignmentInCondition
86 | Self::NumericComparisonWithUndef
87 | Self::PrintfFormatMismatch
88 | Self::UnreachableCode
89 | Self::EvalErrorFlow
90 | Self::DuplicateHashKey
91 | Self::GotoUndefinedLabel
92 | Self::LoopControlUndefinedLabel
93 | Self::VersionIncompatFeature => DiagnosticCategory::BestPractices,
94
95 Self::DeprecatedDefined | Self::DeprecatedArrayBase => DiagnosticCategory::Deprecated,
96
97 Self::SecurityStringEval
98 | Self::SecurityBacktickExec
99 | Self::SecuritySignalHandler
100 | Self::SecuritySystemCall
101 | Self::SecurityExecCall
102 | Self::SecurityPipeOpen
103 | Self::SecurityReadpipe => DiagnosticCategory::Security,
104
105 Self::UnusedImport | Self::ModuleNotFound => DiagnosticCategory::Import,
106
107 Self::HeredocInFormat
108 | Self::HeredocInBegin
109 | Self::HeredocDynamicDelimiter
110 | Self::HeredocInSourceFilter
111 | Self::HeredocInRegexCode
112 | Self::HeredocInEval
113 | Self::HeredocTiedHandle => DiagnosticCategory::Heredoc,
114
115 Self::CriticSeverity1
116 | Self::CriticSeverity2
117 | Self::CriticSeverity3
118 | Self::CriticSeverity4
119 | Self::CriticSeverity5 => DiagnosticCategory::PerlCritic,
120 }
121 }
122}