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