mirror of https://github.com/astral-sh/ruff
Stabilize `os-symlink` (`PTH211`) (#20229)
Summary -- Rule and test/snapshot updated, the docs look good My one hesitation here is that we could hold off stabilizing the rule until its fix is also ready for stabilization, but this is also the only preview PTH rule, so I think it's okay to stabilize the rule and later (probably in the next minor release) stabilize the fixes together.
This commit is contained in:
parent
1de9dac9d5
commit
262f2767ca
|
|
@ -956,7 +956,7 @@ pub fn code_to_rule(linter: Linter, code: &str) -> Option<(RuleGroup, Rule)> {
|
||||||
(Flake8UsePathlib, "207") => (RuleGroup::Stable, rules::flake8_use_pathlib::rules::Glob),
|
(Flake8UsePathlib, "207") => (RuleGroup::Stable, rules::flake8_use_pathlib::rules::Glob),
|
||||||
(Flake8UsePathlib, "208") => (RuleGroup::Stable, rules::flake8_use_pathlib::violations::OsListdir),
|
(Flake8UsePathlib, "208") => (RuleGroup::Stable, rules::flake8_use_pathlib::violations::OsListdir),
|
||||||
(Flake8UsePathlib, "210") => (RuleGroup::Stable, rules::flake8_use_pathlib::rules::InvalidPathlibWithSuffix),
|
(Flake8UsePathlib, "210") => (RuleGroup::Stable, rules::flake8_use_pathlib::rules::InvalidPathlibWithSuffix),
|
||||||
(Flake8UsePathlib, "211") => (RuleGroup::Preview, rules::flake8_use_pathlib::rules::OsSymlink),
|
(Flake8UsePathlib, "211") => (RuleGroup::Stable, rules::flake8_use_pathlib::rules::OsSymlink),
|
||||||
|
|
||||||
// flake8-logging-format
|
// flake8-logging-format
|
||||||
(Flake8LoggingFormat, "001") => (RuleGroup::Stable, rules::flake8_logging_format::violations::LoggingStringFormat),
|
(Flake8LoggingFormat, "001") => (RuleGroup::Stable, rules::flake8_logging_format::violations::LoggingStringFormat),
|
||||||
|
|
|
||||||
|
|
@ -129,7 +129,6 @@ mod tests {
|
||||||
#[test_case(Rule::OsPathGetatime, Path::new("PTH203.py"))]
|
#[test_case(Rule::OsPathGetatime, Path::new("PTH203.py"))]
|
||||||
#[test_case(Rule::OsPathGetmtime, Path::new("PTH204.py"))]
|
#[test_case(Rule::OsPathGetmtime, Path::new("PTH204.py"))]
|
||||||
#[test_case(Rule::OsPathGetctime, Path::new("PTH205.py"))]
|
#[test_case(Rule::OsPathGetctime, Path::new("PTH205.py"))]
|
||||||
#[test_case(Rule::OsSymlink, Path::new("PTH211.py"))]
|
|
||||||
fn preview_flake8_use_pathlib(rule_code: Rule, path: &Path) -> Result<()> {
|
fn preview_flake8_use_pathlib(rule_code: Rule, path: &Path) -> Result<()> {
|
||||||
let snapshot = format!(
|
let snapshot = format!(
|
||||||
"preview__{}_{}",
|
"preview__{}_{}",
|
||||||
|
|
|
||||||
|
|
@ -1,152 +0,0 @@
|
||||||
---
|
|
||||||
source: crates/ruff_linter/src/rules/flake8_use_pathlib/mod.rs
|
|
||||||
---
|
|
||||||
PTH211 [*] `os.symlink` should be replaced by `Path.symlink_to`
|
|
||||||
--> PTH211.py:5:1
|
|
||||||
|
|
|
||||||
5 | os.symlink("usr/bin/python", "tmp/python")
|
|
||||||
| ^^^^^^^^^^
|
|
||||||
6 | os.symlink(b"usr/bin/python", b"tmp/python")
|
|
||||||
7 | Path("tmp/python").symlink_to("usr/bin/python") # Ok
|
|
||||||
|
|
|
||||||
help: Replace with `Path(...).symlink_to(...)`
|
|
||||||
2 | from pathlib import Path
|
|
||||||
3 |
|
|
||||||
4 |
|
|
||||||
- os.symlink("usr/bin/python", "tmp/python")
|
|
||||||
5 + Path("tmp/python").symlink_to("usr/bin/python")
|
|
||||||
6 | os.symlink(b"usr/bin/python", b"tmp/python")
|
|
||||||
7 | Path("tmp/python").symlink_to("usr/bin/python") # Ok
|
|
||||||
8 |
|
|
||||||
|
|
||||||
PTH211 [*] `os.symlink` should be replaced by `Path.symlink_to`
|
|
||||||
--> PTH211.py:6:1
|
|
||||||
|
|
|
||||||
5 | os.symlink("usr/bin/python", "tmp/python")
|
|
||||||
6 | os.symlink(b"usr/bin/python", b"tmp/python")
|
|
||||||
| ^^^^^^^^^^
|
|
||||||
7 | Path("tmp/python").symlink_to("usr/bin/python") # Ok
|
|
||||||
|
|
|
||||||
help: Replace with `Path(...).symlink_to(...)`
|
|
||||||
3 |
|
|
||||||
4 |
|
|
||||||
5 | os.symlink("usr/bin/python", "tmp/python")
|
|
||||||
- os.symlink(b"usr/bin/python", b"tmp/python")
|
|
||||||
6 + Path(b"tmp/python").symlink_to(b"usr/bin/python")
|
|
||||||
7 | Path("tmp/python").symlink_to("usr/bin/python") # Ok
|
|
||||||
8 |
|
|
||||||
9 | os.symlink("usr/bin/python", "tmp/python", target_is_directory=True)
|
|
||||||
|
|
||||||
PTH211 [*] `os.symlink` should be replaced by `Path.symlink_to`
|
|
||||||
--> PTH211.py:9:1
|
|
||||||
|
|
|
||||||
7 | Path("tmp/python").symlink_to("usr/bin/python") # Ok
|
|
||||||
8 |
|
|
||||||
9 | os.symlink("usr/bin/python", "tmp/python", target_is_directory=True)
|
|
||||||
| ^^^^^^^^^^
|
|
||||||
10 | os.symlink(b"usr/bin/python", b"tmp/python", target_is_directory=True)
|
|
||||||
11 | Path("tmp/python").symlink_to("usr/bin/python", target_is_directory=True) # Ok
|
|
||||||
|
|
|
||||||
help: Replace with `Path(...).symlink_to(...)`
|
|
||||||
6 | os.symlink(b"usr/bin/python", b"tmp/python")
|
|
||||||
7 | Path("tmp/python").symlink_to("usr/bin/python") # Ok
|
|
||||||
8 |
|
|
||||||
- os.symlink("usr/bin/python", "tmp/python", target_is_directory=True)
|
|
||||||
9 + Path("tmp/python").symlink_to("usr/bin/python", target_is_directory=True)
|
|
||||||
10 | os.symlink(b"usr/bin/python", b"tmp/python", target_is_directory=True)
|
|
||||||
11 | Path("tmp/python").symlink_to("usr/bin/python", target_is_directory=True) # Ok
|
|
||||||
12 |
|
|
||||||
|
|
||||||
PTH211 [*] `os.symlink` should be replaced by `Path.symlink_to`
|
|
||||||
--> PTH211.py:10:1
|
|
||||||
|
|
|
||||||
9 | os.symlink("usr/bin/python", "tmp/python", target_is_directory=True)
|
|
||||||
10 | os.symlink(b"usr/bin/python", b"tmp/python", target_is_directory=True)
|
|
||||||
| ^^^^^^^^^^
|
|
||||||
11 | Path("tmp/python").symlink_to("usr/bin/python", target_is_directory=True) # Ok
|
|
||||||
|
|
|
||||||
help: Replace with `Path(...).symlink_to(...)`
|
|
||||||
7 | Path("tmp/python").symlink_to("usr/bin/python") # Ok
|
|
||||||
8 |
|
|
||||||
9 | os.symlink("usr/bin/python", "tmp/python", target_is_directory=True)
|
|
||||||
- os.symlink(b"usr/bin/python", b"tmp/python", target_is_directory=True)
|
|
||||||
10 + Path(b"tmp/python").symlink_to(b"usr/bin/python", target_is_directory=True)
|
|
||||||
11 | Path("tmp/python").symlink_to("usr/bin/python", target_is_directory=True) # Ok
|
|
||||||
12 |
|
|
||||||
13 | fd = os.open(".", os.O_RDONLY)
|
|
||||||
|
|
||||||
PTH211 `os.symlink` should be replaced by `Path.symlink_to`
|
|
||||||
--> PTH211.py:17:1
|
|
||||||
|
|
|
||||||
15 | os.close(fd)
|
|
||||||
16 |
|
|
||||||
17 | os.symlink(src="usr/bin/python", dst="tmp/python", unknown=True)
|
|
||||||
| ^^^^^^^^^^
|
|
||||||
18 | os.symlink("usr/bin/python", dst="tmp/python", target_is_directory=False)
|
|
||||||
|
|
|
||||||
help: Replace with `Path(...).symlink_to(...)`
|
|
||||||
|
|
||||||
PTH211 [*] `os.symlink` should be replaced by `Path.symlink_to`
|
|
||||||
--> PTH211.py:18:1
|
|
||||||
|
|
|
||||||
17 | os.symlink(src="usr/bin/python", dst="tmp/python", unknown=True)
|
|
||||||
18 | os.symlink("usr/bin/python", dst="tmp/python", target_is_directory=False)
|
|
||||||
| ^^^^^^^^^^
|
|
||||||
19 |
|
|
||||||
20 | os.symlink(src="usr/bin/python", dst="tmp/python", dir_fd=None)
|
|
||||||
|
|
|
||||||
help: Replace with `Path(...).symlink_to(...)`
|
|
||||||
15 | os.close(fd)
|
|
||||||
16 |
|
|
||||||
17 | os.symlink(src="usr/bin/python", dst="tmp/python", unknown=True)
|
|
||||||
- os.symlink("usr/bin/python", dst="tmp/python", target_is_directory=False)
|
|
||||||
18 + Path("tmp/python").symlink_to("usr/bin/python")
|
|
||||||
19 |
|
|
||||||
20 | os.symlink(src="usr/bin/python", dst="tmp/python", dir_fd=None)
|
|
||||||
21 |
|
|
||||||
|
|
||||||
PTH211 [*] `os.symlink` should be replaced by `Path.symlink_to`
|
|
||||||
--> PTH211.py:20:1
|
|
||||||
|
|
|
||||||
18 | os.symlink("usr/bin/python", dst="tmp/python", target_is_directory=False)
|
|
||||||
19 |
|
|
||||||
20 | os.symlink(src="usr/bin/python", dst="tmp/python", dir_fd=None)
|
|
||||||
| ^^^^^^^^^^
|
|
||||||
21 |
|
|
||||||
22 | os.symlink("usr/bin/python", dst="tmp/python", target_is_directory= True )
|
|
||||||
|
|
|
||||||
help: Replace with `Path(...).symlink_to(...)`
|
|
||||||
17 | os.symlink(src="usr/bin/python", dst="tmp/python", unknown=True)
|
|
||||||
18 | os.symlink("usr/bin/python", dst="tmp/python", target_is_directory=False)
|
|
||||||
19 |
|
|
||||||
- os.symlink(src="usr/bin/python", dst="tmp/python", dir_fd=None)
|
|
||||||
20 + Path("tmp/python").symlink_to("usr/bin/python")
|
|
||||||
21 |
|
|
||||||
22 | os.symlink("usr/bin/python", dst="tmp/python", target_is_directory= True )
|
|
||||||
23 | os.symlink("usr/bin/python", dst="tmp/python", target_is_directory="nonboolean")
|
|
||||||
|
|
||||||
PTH211 [*] `os.symlink` should be replaced by `Path.symlink_to`
|
|
||||||
--> PTH211.py:22:1
|
|
||||||
|
|
|
||||||
20 | os.symlink(src="usr/bin/python", dst="tmp/python", dir_fd=None)
|
|
||||||
21 |
|
|
||||||
22 | os.symlink("usr/bin/python", dst="tmp/python", target_is_directory= True )
|
|
||||||
| ^^^^^^^^^^
|
|
||||||
23 | os.symlink("usr/bin/python", dst="tmp/python", target_is_directory="nonboolean")
|
|
||||||
|
|
|
||||||
help: Replace with `Path(...).symlink_to(...)`
|
|
||||||
19 |
|
|
||||||
20 | os.symlink(src="usr/bin/python", dst="tmp/python", dir_fd=None)
|
|
||||||
21 |
|
|
||||||
- os.symlink("usr/bin/python", dst="tmp/python", target_is_directory= True )
|
|
||||||
22 + Path("tmp/python").symlink_to("usr/bin/python", target_is_directory=True)
|
|
||||||
23 | os.symlink("usr/bin/python", dst="tmp/python", target_is_directory="nonboolean")
|
|
||||||
|
|
||||||
PTH211 `os.symlink` should be replaced by `Path.symlink_to`
|
|
||||||
--> PTH211.py:23:1
|
|
||||||
|
|
|
||||||
22 | os.symlink("usr/bin/python", dst="tmp/python", target_is_directory= True )
|
|
||||||
23 | os.symlink("usr/bin/python", dst="tmp/python", target_is_directory="nonboolean")
|
|
||||||
| ^^^^^^^^^^
|
|
||||||
|
|
|
||||||
help: Replace with `Path(...).symlink_to(...)`
|
|
||||||
Loading…
Reference in New Issue