Skip to content

Commit 26496b0

Browse files
committed
feat(analyzer): add property and generator issue categories
This commit continues the work on issue categorization by introducing two new categories, giving users more fine-grained control over the analysis. The new categories are: - **`property_issues`**: Groups all diagnostics related to class properties, including access, assignment, visibility, and type compatibility. - **`generator_issues`**: Groups all diagnostics related to PHP generators, such as `yield`, `yield from`, and generator return types. These categories can be disabled in `mago.toml` to help tailor the analysis for specific projects. Additionally, existing categories like `argument`, `redundancy`, and `impossibility` have been expanded to be more comprehensive. Signed-off-by: azjezz <[email protected]>
1 parent b6b9539 commit 26496b0

File tree

4 files changed

+102
-2
lines changed

4 files changed

+102
-2
lines changed

crates/analyzer/src/code.rs

Lines changed: 74 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -779,7 +779,7 @@ impl IssueCode {
779779
]
780780
}
781781

782-
pub const fn get_argument_issue_codes() -> [Self; 14] {
782+
pub const fn get_argument_issue_codes() -> [Self; 16] {
783783
[
784784
Self::DuplicateNamedArgument,
785785
Self::FalseArgument,
@@ -795,10 +795,12 @@ impl IssueCode {
795795
Self::PossiblyFalseArgument,
796796
Self::PossiblyInvalidArgument,
797797
Self::PossiblyNullArgument,
798+
Self::TooFewArguments,
799+
Self::TooManyArguments,
798800
]
799801
}
800802

801-
pub const fn get_argument_issue_code_values() -> [&'static str; 14] {
803+
pub const fn get_argument_issue_code_values() -> [&'static str; 16] {
802804
[
803805
"duplicate-named-argument",
804806
"false-argument",
@@ -814,6 +816,8 @@ impl IssueCode {
814816
"possibly-false-argument",
815817
"possibly-invalid-argument",
816818
"possibly-null-argument",
819+
"too-few-arguments",
820+
"too-many-arguments",
817821
]
818822
}
819823

@@ -840,6 +844,74 @@ impl IssueCode {
840844
"possibly-null-operand",
841845
]
842846
}
847+
848+
pub const fn get_property_issue_codes() -> [Self; 14] {
849+
[
850+
Self::AmbiguousObjectPropertyAccess,
851+
Self::IncompatiblePropertyType,
852+
Self::InvalidPropertyAccess,
853+
Self::InvalidPropertyAssignmentValue,
854+
Self::InvalidPropertyRead,
855+
Self::InvalidPropertyWrite,
856+
Self::InvalidStaticPropertyAccess,
857+
Self::MixedPropertyAccess,
858+
Self::MixedPropertyTypeCoercion,
859+
Self::NonExistentProperty,
860+
Self::NullPropertyAccess,
861+
Self::OverriddenPropertyAccess,
862+
Self::PossiblyNullPropertyAccess,
863+
Self::PropertyTypeCoercion,
864+
]
865+
}
866+
867+
pub const fn get_property_issue_code_values() -> [&'static str; 14] {
868+
[
869+
"ambiguous-object-property-access",
870+
"incompatible-property-type",
871+
"invalid-property-access",
872+
"invalid-property-assignment-value",
873+
"invalid-property-read",
874+
"invalid-property-write",
875+
"invalid-static-property-access",
876+
"mixed-property-access",
877+
"mixed-property-type-coercion",
878+
"non-existent-property",
879+
"null-property-access",
880+
"overridden-property-access",
881+
"possibly-null-property-access",
882+
"property-type-coercion",
883+
]
884+
}
885+
886+
pub const fn get_generator_issue_codes() -> [Self; 10] {
887+
[
888+
Self::HiddenGeneratorReturn,
889+
Self::InvalidGeneratorReturnType,
890+
Self::InvalidYieldKeyType,
891+
Self::InvalidYieldValueType,
892+
Self::UnknownYieldFromIteratorType,
893+
Self::YieldFromInvalidKeyType,
894+
Self::YieldFromInvalidSendType,
895+
Self::YieldFromInvalidValueType,
896+
Self::YieldFromNonIterable,
897+
Self::YieldOutsideFunction,
898+
]
899+
}
900+
901+
pub const fn get_generator_issue_code_values() -> [&'static str; 10] {
902+
[
903+
"hidden-generator-return",
904+
"invalid-generator-return-type",
905+
"invalid-yield-key-type",
906+
"invalid-yield-value-type",
907+
"unknown-yield-from-iterator-type",
908+
"yield-from-invalid-key-type",
909+
"yield-from-invalid-send-type",
910+
"yield-from-invalid-value-type",
911+
"yield-from-non-iterable",
912+
"yield-outside-function",
913+
]
914+
}
843915
}
844916

845917
impl std::str::FromStr for IssueCode {

crates/analyzer/src/lib.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,14 @@ impl<'a> Analyzer<'a> {
123123
collector.add_disabled_codes(IssueCode::get_operand_issue_code_values());
124124
}
125125

126+
if !self.settings.property_issues {
127+
collector.add_disabled_codes(IssueCode::get_property_issue_code_values());
128+
}
129+
130+
if !self.settings.generator_issues {
131+
collector.add_disabled_codes(IssueCode::get_generator_issue_code_values());
132+
}
133+
126134
let mut context = {
127135
Context::new(
128136
self.interner,

crates/analyzer/src/settings.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,12 @@ pub struct Settings {
4848
/// Report all issues related to operands in expressions. Defaults to `true`.
4949
pub operand_issues: bool,
5050

51+
/// Report all issues related to properties and their usage. Defaults to `true`.
52+
pub property_issues: bool,
53+
54+
/// Report all issues related to the use of generators. Defaults to `true`.
55+
pub generator_issues: bool,
56+
5157
/// Find and report expressions whose results are not used (e.g., `$a + $b;`). Defaults to `false`.
5258
pub find_unused_expressions: bool,
5359

@@ -111,6 +117,8 @@ impl Settings {
111117
argument_issues: true,
112118
operand_issues: true,
113119
ambiguity_issues: true,
120+
property_issues: true,
121+
generator_issues: true,
114122
find_unused_expressions: false,
115123
find_unused_definitions: false,
116124
analyze_dead_code: false,

src/config/analyzer.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,12 @@ pub struct AnalyzeConfiguration {
5656
/// Report all issues related to operands in expressions.
5757
pub operand_issues: bool,
5858

59+
/// Report all issues related to properties and their usage.
60+
pub property_issues: bool,
61+
62+
/// Report all issues related to the use of generators.
63+
pub generator_issues: bool,
64+
5965
/// Whether to find unused expressions.
6066
pub find_unused_expressions: bool,
6167

@@ -101,6 +107,8 @@ impl AnalyzeConfiguration {
101107
template_issues: self.template_issues,
102108
argument_issues: self.argument_issues,
103109
operand_issues: self.operand_issues,
110+
property_issues: self.property_issues,
111+
generator_issues: self.generator_issues,
104112
analyze_dead_code: self.analyze_dead_code,
105113
find_unused_definitions: self.find_unused_definitions,
106114
find_unused_expressions: self.find_unused_expressions,
@@ -137,6 +145,8 @@ impl ConfigurationEntry for AnalyzeConfiguration {
137145
.set_default("analyze.template_issues", defaults.template_issues)?
138146
.set_default("analyze.argument_issues", defaults.argument_issues)?
139147
.set_default("analyze.operand_issues", defaults.operand_issues)?
148+
.set_default("analyze.property_issues", defaults.property_issues)?
149+
.set_default("analyze.generator_issues", defaults.generator_issues)?
140150
.set_default("analyze.find_unused_definitions", defaults.find_unused_definitions)?
141151
.set_default("analyze.find_unused_expressions", defaults.find_unused_expressions)?
142152
.set_default("analyze.analyze_dead_code", defaults.analyze_dead_code)?
@@ -169,6 +179,8 @@ impl Default for AnalyzeConfiguration {
169179
template_issues: defaults.template_issues,
170180
argument_issues: defaults.argument_issues,
171181
operand_issues: defaults.operand_issues,
182+
property_issues: defaults.property_issues,
183+
generator_issues: defaults.generator_issues,
172184
find_unused_expressions: defaults.find_unused_expressions,
173185
find_unused_definitions: defaults.find_unused_definitions,
174186
analyze_dead_code: defaults.analyze_dead_code,

0 commit comments

Comments
 (0)