-
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Various: Add support for protected(set) and public(set), add rule to …
…check for redundant vis
- Loading branch information
1 parent
12bdea4
commit 940b457
Showing
10 changed files
with
129 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
55 changes: 55 additions & 0 deletions
55
crates/linter/src/plugin/redundancy/rules/redundant_write_visibility.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
use mago_ast::{Modifier, Property}; | ||
use mago_reporting::{Annotation, Issue, Level}; | ||
use mago_span::HasSpan; | ||
use mago_walker::Walker; | ||
|
||
use crate::{context::LintContext, rule::Rule}; | ||
|
||
#[derive(Clone, Debug)] | ||
pub struct RedundantWriteVisibility; | ||
|
||
impl Rule for RedundantWriteVisibility { | ||
fn get_name(&self) -> &'static str { | ||
"redundant-write-visibility" | ||
} | ||
|
||
fn get_default_level(&self) -> Option<mago_reporting::Level> { | ||
Some(Level::Help) | ||
} | ||
} | ||
|
||
impl<'a> Walker<LintContext<'a>> for RedundantWriteVisibility { | ||
fn walk_in_property(&self, property: &Property, context: &mut LintContext<'a>) { | ||
let modifiers = property.modifiers(); | ||
|
||
if modifiers.is_empty() { | ||
return; | ||
} | ||
|
||
let Some(write_visibility) = modifiers.get_first_write_visibility() else { | ||
return; | ||
}; | ||
|
||
let Some(read_visibility) = modifiers.get_first_read_visibility() else { | ||
return; | ||
}; | ||
|
||
match (read_visibility, write_visibility) { | ||
(Modifier::Public(_), Modifier::PublicSet(_)) | (Modifier::Protected(_), Modifier::ProtectedSet(_)) | (Modifier::Private(_), Modifier::PrivateSet(_)) => { | ||
let issue = Issue::new(context.level(), "identical write visibility has no effect") | ||
.with_help("remove the redundant write visibility modifier") | ||
.with_annotations(vec![ | ||
Annotation::secondary(read_visibility.span()), | ||
Annotation::secondary(write_visibility.span()), | ||
]); | ||
|
||
context.report_with_fix(issue, |plan| { | ||
let range = write_visibility.span().to_range(); | ||
|
||
plan.delete(range, mago_fixer::SafetyClassification::PotentiallyUnsafe) | ||
}); | ||
}, | ||
_ => {} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters