mirror of https://github.com/astral-sh/ruff
Add documentation for the pathlib rules (#5815)
Reviving https://github.com/astral-sh/ruff/pull/2348 step by step Pt 1: docs Tracking issue: https://github.com/astral-sh/ruff/issues/2646.
This commit is contained in:
parent
5f2014b0b8
commit
d62183b07d
|
|
@ -17,11 +17,15 @@ use ruff_macros::{derive_message_formats, violation};
|
|||
///
|
||||
/// ## Examples
|
||||
/// ```python
|
||||
/// import os
|
||||
///
|
||||
/// os.path.getsize(__file__)
|
||||
/// ```
|
||||
///
|
||||
/// Use instead:
|
||||
/// ```python
|
||||
/// from pathlib import Path
|
||||
///
|
||||
/// Path(__file__).stat().st_size
|
||||
/// ```
|
||||
///
|
||||
|
|
|
|||
|
|
@ -17,11 +17,15 @@ use ruff_macros::{derive_message_formats, violation};
|
|||
///
|
||||
/// ## Examples
|
||||
/// ```python
|
||||
/// import os
|
||||
///
|
||||
/// os.path.getsize(__file__)
|
||||
/// ```
|
||||
///
|
||||
/// Use instead:
|
||||
/// ```python
|
||||
/// from pathlib import Path
|
||||
///
|
||||
/// Path(__file__).stat().st_size
|
||||
/// ```
|
||||
///
|
||||
|
|
|
|||
|
|
@ -17,11 +17,15 @@ use ruff_macros::{derive_message_formats, violation};
|
|||
///
|
||||
/// ## Examples
|
||||
/// ```python
|
||||
/// import os
|
||||
///
|
||||
/// os.path.getsize(__file__)
|
||||
/// ```
|
||||
///
|
||||
/// Use instead:
|
||||
/// ```python
|
||||
/// from pathlib import Path
|
||||
///
|
||||
/// Path(__file__).stat().st_size
|
||||
/// ```
|
||||
///
|
||||
|
|
|
|||
|
|
@ -17,11 +17,15 @@ use ruff_macros::{derive_message_formats, violation};
|
|||
///
|
||||
/// ## Examples
|
||||
/// ```python
|
||||
/// import os
|
||||
///
|
||||
/// os.path.getsize(__file__)
|
||||
/// ```
|
||||
///
|
||||
/// Use instead:
|
||||
/// ```python
|
||||
/// from pathlib import Path
|
||||
///
|
||||
/// Path(__file__).stat().st_size
|
||||
/// ```
|
||||
///
|
||||
|
|
|
|||
|
|
@ -21,28 +21,50 @@ pub(crate) fn replaceable_by_pathlib(checker: &mut Checker, expr: &Expr) {
|
|||
.semantic()
|
||||
.resolve_call_path(expr)
|
||||
.and_then(|call_path| match call_path.as_slice() {
|
||||
// PTH100
|
||||
["os", "path", "abspath"] => Some(OsPathAbspath.into()),
|
||||
// PTH101
|
||||
["os", "chmod"] => Some(OsChmod.into()),
|
||||
["os", "mkdir"] => Some(OsMkdir.into()),
|
||||
// PTH102
|
||||
["os", "makedirs"] => Some(OsMakedirs.into()),
|
||||
// PTH103
|
||||
["os", "mkdir"] => Some(OsMkdir.into()),
|
||||
// PTH104
|
||||
["os", "rename"] => Some(OsRename.into()),
|
||||
// PTH105
|
||||
["os", "replace"] => Some(OsReplace.into()),
|
||||
// PTH106
|
||||
["os", "rmdir"] => Some(OsRmdir.into()),
|
||||
// PTH107
|
||||
["os", "remove"] => Some(OsRemove.into()),
|
||||
// PTH108
|
||||
["os", "unlink"] => Some(OsUnlink.into()),
|
||||
// PTH109
|
||||
["os", "getcwd"] => Some(OsGetcwd.into()),
|
||||
["os", "getcwdb"] => Some(OsGetcwd.into()),
|
||||
// PTH110
|
||||
["os", "path", "exists"] => Some(OsPathExists.into()),
|
||||
// PTH111
|
||||
["os", "path", "expanduser"] => Some(OsPathExpanduser.into()),
|
||||
// PTH112
|
||||
["os", "path", "isdir"] => Some(OsPathIsdir.into()),
|
||||
// PTH113
|
||||
["os", "path", "isfile"] => Some(OsPathIsfile.into()),
|
||||
// PTH114
|
||||
["os", "path", "islink"] => Some(OsPathIslink.into()),
|
||||
// PTH116
|
||||
["os", "stat"] => Some(OsStat.into()),
|
||||
// PTH117
|
||||
["os", "path", "isabs"] => Some(OsPathIsabs.into()),
|
||||
// PTH118
|
||||
["os", "path", "join"] => Some(OsPathJoin.into()),
|
||||
// PTH119
|
||||
["os", "path", "basename"] => Some(OsPathBasename.into()),
|
||||
// PTH120
|
||||
["os", "path", "dirname"] => Some(OsPathDirname.into()),
|
||||
// PTH121
|
||||
["os", "path", "samefile"] => Some(OsPathSamefile.into()),
|
||||
// PTH122
|
||||
["os", "path", "splitext"] => Some(OsPathSplitext.into()),
|
||||
// PTH202
|
||||
["os", "path", "getsize"] => Some(OsPathGetsize.into()),
|
||||
|
|
@ -52,8 +74,11 @@ pub(crate) fn replaceable_by_pathlib(checker: &mut Checker, expr: &Expr) {
|
|||
["os", "path", "getmtime"] => Some(OsPathGetmtime.into()),
|
||||
// PTH205
|
||||
["os", "path", "getctime"] => Some(OsPathGetctime.into()),
|
||||
["", "open"] => Some(BuiltinOpen.into()),
|
||||
// PTH123
|
||||
["" | "builtin", "open"] => Some(BuiltinOpen.into()),
|
||||
// PTH124
|
||||
["py", "path", "local"] => Some(PyPath.into()),
|
||||
// PTH115
|
||||
// Python 3.9+
|
||||
["os", "readlink"] if checker.settings.target_version >= PythonVersion::Py39 => {
|
||||
Some(OsReadlink.into())
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue