Skip to content

Commit

Permalink
# This is a combination of 2 commits.
Browse files Browse the repository at this point in the history
# This is the 1st commit message:

Add tests for redirected rules

# The commit message #2 will be skipped:

# Add test rules for redirection
  • Loading branch information
zanieb committed Feb 1, 2024
1 parent 7c51476 commit c53a810
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 5 deletions.
22 changes: 17 additions & 5 deletions crates/ruff/tests/integration_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -826,6 +826,7 @@ fn nursery_prefix() {
-:1:1: RUF903 Hey this is a stable test rule with a display only fix.
-:1:1: RUF920 Hey this is a deprecated test rule.
-:1:1: RUF921 Hey this is another deprecated test rule.
-:1:1: RUF950 Hey this is a test rule that was redirected from another.
Found 6 errors.
[*] 1 fixable with the `--fix` option (1 hidden fix can be enabled with the `--unsafe-fixes` option).
Expand All @@ -850,6 +851,7 @@ fn nursery_all() {
-:1:1: RUF903 Hey this is a stable test rule with a display only fix.
-:1:1: RUF920 Hey this is a deprecated test rule.
-:1:1: RUF921 Hey this is another deprecated test rule.
-:1:1: RUF950 Hey this is a test rule that was redirected from another.
Found 7 errors.
[*] 1 fixable with the `--fix` option (1 hidden fix can be enabled with the `--unsafe-fixes` option).
Expand Down Expand Up @@ -929,7 +931,8 @@ fn preview_enabled_prefix() {
-:1:1: RUF903 Hey this is a stable test rule with a display only fix.
-:1:1: RUF911 Hey this is a preview test rule.
-:1:1: RUF912 Hey this is a nursery test rule.
Found 6 errors.
-:1:1: RUF950 Hey this is a test rule that was redirected from another.
Found 7 errors.
[*] 1 fixable with the `--fix` option (1 hidden fix can be enabled with the `--unsafe-fixes` option).
----- stderr -----
Expand All @@ -953,7 +956,8 @@ fn preview_enabled_all() {
-:1:1: RUF903 Hey this is a stable test rule with a display only fix.
-:1:1: RUF911 Hey this is a preview test rule.
-:1:1: RUF912 Hey this is a nursery test rule.
Found 8 errors.
-:1:1: RUF950 Hey this is a test rule that was redirected from another.
Found 9 errors.
[*] 1 fixable with the `--fix` option (1 hidden fix can be enabled with the `--unsafe-fixes` option).
----- stderr -----
Expand Down Expand Up @@ -1088,7 +1092,8 @@ fn preview_enabled_group_ignore() {
-:1:1: RUF903 Hey this is a stable test rule with a display only fix.
-:1:1: RUF911 Hey this is a preview test rule.
-:1:1: RUF912 Hey this is a nursery test rule.
Found 6 errors.
-:1:1: RUF950 Hey this is a test rule that was redirected from another.
Found 7 errors.
[*] 1 fixable with the `--fix` option (1 hidden fix can be enabled with the `--unsafe-fixes` option).
----- stderr -----
Expand Down Expand Up @@ -1150,9 +1155,11 @@ fn redirect_direct() {
// Selection of a redirected rule directly should use the new rule and warn
let mut cmd = RuffCheck::default().args(["--select", "RUF940"]).build();
assert_cmd_snapshot!(cmd, @r###"
success: true
exit_code: 0
success: false
exit_code: 1
----- stdout -----
-:1:1: RUF950 Hey this is a test rule that was redirected from another.
Found 1 error.
----- stderr -----
"###);
Expand Down Expand Up @@ -1795,9 +1802,14 @@ extend-safe-fixes = ["RUF9"]
-:1:1: RUF901 Hey this is a stable test rule with a safe fix.
-:1:1: RUF902 [*] Hey this is a stable test rule with an unsafe fix.
-:1:1: RUF903 Hey this is a stable test rule with a display only fix.
<<<<<<< HEAD
-:1:1: RUF920 Hey this is a deprecated test rule.
-:1:1: RUF921 Hey this is another deprecated test rule.
Found 6 errors.
=======
-:1:1: RUF950 Hey this is a test rule that was redirected from another.
Found 5 errors.
>>>>>>> d1091abbf (Add test rules for redirection)
[*] 1 fixable with the `--fix` option (1 hidden fix can be enabled with the `--unsafe-fixes` option).
----- stderr -----
Expand Down
6 changes: 6 additions & 0 deletions crates/ruff_linter/src/linter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,12 @@ pub fn check_path(
Rule::AnotherRemovedTestRule => {
test_rules::AnotherRemovedTestRule::diagnostic(locator, indexer)
}
Rule::RedirectedToTestRule => {
test_rules::RedirectedToTestRule::diagnostic(locator, indexer)
}
Rule::RedirectedFromTestRule => {
test_rules::RedirectedFromTestRule::diagnostic(locator, indexer)
}
_ => unreachable!("All test rules must have an implementation"),
};
if let Some(diagnostic) = diagnostic {
Expand Down
2 changes: 2 additions & 0 deletions crates/ruff_linter/src/rules/ruff/rules/test_rules.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ pub(crate) const TEST_RULES: &[Rule] = &[
Rule::AnotherDeprecatedTestRule,
Rule::RemovedTestRule,
Rule::AnotherRemovedTestRule,
Rule::RedirectedFromTestRule,
Rule::RedirectedToTestRule,
];

pub(crate) trait TestRule {
Expand Down

0 comments on commit c53a810

Please sign in to comment.