Skip to content

Commit

Permalink
Rename pathlib rules to match updated naming convention (#3660)
Browse files Browse the repository at this point in the history
  • Loading branch information
charliermarsh authored Mar 22, 2023
1 parent 3ec1ea8 commit 875f61c
Show file tree
Hide file tree
Showing 12 changed files with 268 additions and 269 deletions.
46 changes: 23 additions & 23 deletions crates/ruff/src/checkers/ast/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2886,30 +2886,30 @@ where

// flake8-use-pathlib
if self.settings.rules.any_enabled(&[
Rule::PathlibAbspath,
Rule::PathlibChmod,
Rule::PathlibMkdir,
Rule::PathlibMakedirs,
Rule::PathlibRename,
Rule::OsPathAbspath,
Rule::OsChmod,
Rule::OsMkdir,
Rule::OsMakedirs,
Rule::OsRename,
Rule::PathlibReplace,
Rule::PathlibRmdir,
Rule::PathlibRemove,
Rule::PathlibUnlink,
Rule::PathlibGetcwd,
Rule::PathlibExists,
Rule::PathlibExpanduser,
Rule::PathlibIsDir,
Rule::PathlibIsFile,
Rule::PathlibIsLink,
Rule::PathlibReadlink,
Rule::PathlibStat,
Rule::PathlibIsAbs,
Rule::PathlibJoin,
Rule::PathlibBasename,
Rule::PathlibSamefile,
Rule::PathlibSplitext,
Rule::PathlibOpen,
Rule::PathlibPyPath,
Rule::OsRmdir,
Rule::OsRemove,
Rule::OsUnlink,
Rule::OsGetcwd,
Rule::OsPathExists,
Rule::OsPathExpanduser,
Rule::OsPathIsdir,
Rule::OsPathIsfile,
Rule::OsPathIslink,
Rule::OsReadlink,
Rule::OsStat,
Rule::OsPathIsabs,
Rule::OsPathJoin,
Rule::OsPathBasename,
Rule::OsPathSamefile,
Rule::OsPathSplitext,
Rule::BuiltinOpen,
Rule::PyPath,
]) {
flake8_use_pathlib::helpers::replaceable_by_pathlib(self, func);
}
Expand Down
48 changes: 24 additions & 24 deletions crates/ruff/src/codes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -638,31 +638,31 @@ pub fn code_to_rule(linter: Linter, code: &str) -> Option<Rule> {
(Tryceratops, "401") => Rule::VerboseLogMessage,

// flake8-use-pathlib
(Flake8UsePathlib, "100") => Rule::PathlibAbspath,
(Flake8UsePathlib, "101") => Rule::PathlibChmod,
(Flake8UsePathlib, "102") => Rule::PathlibMkdir,
(Flake8UsePathlib, "103") => Rule::PathlibMakedirs,
(Flake8UsePathlib, "104") => Rule::PathlibRename,
(Flake8UsePathlib, "100") => Rule::OsPathAbspath,
(Flake8UsePathlib, "101") => Rule::OsChmod,
(Flake8UsePathlib, "102") => Rule::OsMkdir,
(Flake8UsePathlib, "103") => Rule::OsMakedirs,
(Flake8UsePathlib, "104") => Rule::OsRename,
(Flake8UsePathlib, "105") => Rule::PathlibReplace,
(Flake8UsePathlib, "106") => Rule::PathlibRmdir,
(Flake8UsePathlib, "107") => Rule::PathlibRemove,
(Flake8UsePathlib, "108") => Rule::PathlibUnlink,
(Flake8UsePathlib, "109") => Rule::PathlibGetcwd,
(Flake8UsePathlib, "110") => Rule::PathlibExists,
(Flake8UsePathlib, "111") => Rule::PathlibExpanduser,
(Flake8UsePathlib, "112") => Rule::PathlibIsDir,
(Flake8UsePathlib, "113") => Rule::PathlibIsFile,
(Flake8UsePathlib, "114") => Rule::PathlibIsLink,
(Flake8UsePathlib, "115") => Rule::PathlibReadlink,
(Flake8UsePathlib, "116") => Rule::PathlibStat,
(Flake8UsePathlib, "117") => Rule::PathlibIsAbs,
(Flake8UsePathlib, "118") => Rule::PathlibJoin,
(Flake8UsePathlib, "119") => Rule::PathlibBasename,
(Flake8UsePathlib, "120") => Rule::PathlibDirname,
(Flake8UsePathlib, "121") => Rule::PathlibSamefile,
(Flake8UsePathlib, "122") => Rule::PathlibSplitext,
(Flake8UsePathlib, "123") => Rule::PathlibOpen,
(Flake8UsePathlib, "124") => Rule::PathlibPyPath,
(Flake8UsePathlib, "106") => Rule::OsRmdir,
(Flake8UsePathlib, "107") => Rule::OsRemove,
(Flake8UsePathlib, "108") => Rule::OsUnlink,
(Flake8UsePathlib, "109") => Rule::OsGetcwd,
(Flake8UsePathlib, "110") => Rule::OsPathExists,
(Flake8UsePathlib, "111") => Rule::OsPathExpanduser,
(Flake8UsePathlib, "112") => Rule::OsPathIsdir,
(Flake8UsePathlib, "113") => Rule::OsPathIsfile,
(Flake8UsePathlib, "114") => Rule::OsPathIslink,
(Flake8UsePathlib, "115") => Rule::OsReadlink,
(Flake8UsePathlib, "116") => Rule::OsStat,
(Flake8UsePathlib, "117") => Rule::OsPathIsabs,
(Flake8UsePathlib, "118") => Rule::OsPathJoin,
(Flake8UsePathlib, "119") => Rule::OsPathBasename,
(Flake8UsePathlib, "120") => Rule::OsPathDirname,
(Flake8UsePathlib, "121") => Rule::OsPathSamefile,
(Flake8UsePathlib, "122") => Rule::OsPathSplitext,
(Flake8UsePathlib, "123") => Rule::BuiltinOpen,
(Flake8UsePathlib, "124") => Rule::PyPath,

// flake8-logging-format
(Flake8LoggingFormat, "001") => Rule::LoggingStringFormat,
Expand Down
48 changes: 24 additions & 24 deletions crates/ruff/src/registry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -587,31 +587,31 @@ ruff_macros::register_rules!(
rules::tryceratops::rules::ErrorInsteadOfException,
rules::tryceratops::rules::VerboseLogMessage,
// flake8-use-pathlib
rules::flake8_use_pathlib::violations::PathlibAbspath,
rules::flake8_use_pathlib::violations::PathlibChmod,
rules::flake8_use_pathlib::violations::PathlibMkdir,
rules::flake8_use_pathlib::violations::PathlibMakedirs,
rules::flake8_use_pathlib::violations::PathlibRename,
rules::flake8_use_pathlib::violations::OsPathAbspath,
rules::flake8_use_pathlib::violations::OsChmod,
rules::flake8_use_pathlib::violations::OsMkdir,
rules::flake8_use_pathlib::violations::OsMakedirs,
rules::flake8_use_pathlib::violations::OsRename,
rules::flake8_use_pathlib::violations::PathlibReplace,
rules::flake8_use_pathlib::violations::PathlibRmdir,
rules::flake8_use_pathlib::violations::PathlibRemove,
rules::flake8_use_pathlib::violations::PathlibUnlink,
rules::flake8_use_pathlib::violations::PathlibGetcwd,
rules::flake8_use_pathlib::violations::PathlibExists,
rules::flake8_use_pathlib::violations::PathlibExpanduser,
rules::flake8_use_pathlib::violations::PathlibIsDir,
rules::flake8_use_pathlib::violations::PathlibIsFile,
rules::flake8_use_pathlib::violations::PathlibIsLink,
rules::flake8_use_pathlib::violations::PathlibReadlink,
rules::flake8_use_pathlib::violations::PathlibStat,
rules::flake8_use_pathlib::violations::PathlibIsAbs,
rules::flake8_use_pathlib::violations::PathlibJoin,
rules::flake8_use_pathlib::violations::PathlibBasename,
rules::flake8_use_pathlib::violations::PathlibDirname,
rules::flake8_use_pathlib::violations::PathlibSamefile,
rules::flake8_use_pathlib::violations::PathlibSplitext,
rules::flake8_use_pathlib::violations::PathlibOpen,
rules::flake8_use_pathlib::violations::PathlibPyPath,
rules::flake8_use_pathlib::violations::OsRmdir,
rules::flake8_use_pathlib::violations::OsRemove,
rules::flake8_use_pathlib::violations::OsUnlink,
rules::flake8_use_pathlib::violations::OsGetcwd,
rules::flake8_use_pathlib::violations::OsPathExists,
rules::flake8_use_pathlib::violations::OsPathExpanduser,
rules::flake8_use_pathlib::violations::OsPathIsdir,
rules::flake8_use_pathlib::violations::OsPathIsfile,
rules::flake8_use_pathlib::violations::OsPathIslink,
rules::flake8_use_pathlib::violations::OsReadlink,
rules::flake8_use_pathlib::violations::OsStat,
rules::flake8_use_pathlib::violations::OsPathIsabs,
rules::flake8_use_pathlib::violations::OsPathJoin,
rules::flake8_use_pathlib::violations::OsPathBasename,
rules::flake8_use_pathlib::violations::OsPathDirname,
rules::flake8_use_pathlib::violations::OsPathSamefile,
rules::flake8_use_pathlib::violations::OsPathSplitext,
rules::flake8_use_pathlib::violations::BuiltinOpen,
rules::flake8_use_pathlib::violations::PyPath,
// flake8-logging-format
rules::flake8_logging_format::violations::LoggingStringFormat,
rules::flake8_logging_format::violations::LoggingPercentFormat,
Expand Down
59 changes: 29 additions & 30 deletions crates/ruff/src/rules/flake8_use_pathlib/helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,10 @@ use ruff_python_ast::types::Range;
use crate::checkers::ast::Checker;
use crate::registry::AsRule;
use crate::rules::flake8_use_pathlib::violations::{
PathlibAbspath, PathlibBasename, PathlibChmod, PathlibDirname, PathlibExists,
PathlibExpanduser, PathlibGetcwd, PathlibIsAbs, PathlibIsDir, PathlibIsFile, PathlibIsLink,
PathlibJoin, PathlibMakedirs, PathlibMkdir, PathlibOpen, PathlibPyPath, PathlibReadlink,
PathlibRemove, PathlibRename, PathlibReplace, PathlibRmdir, PathlibSamefile, PathlibSplitext,
PathlibStat, PathlibUnlink,
BuiltinOpen, OsChmod, OsGetcwd, OsMakedirs, OsMkdir, OsPathAbspath, OsPathBasename,
OsPathDirname, OsPathExists, OsPathExpanduser, OsPathIsabs, OsPathIsdir, OsPathIsfile,
OsPathIslink, OsPathJoin, OsPathSamefile, OsPathSplitext, OsReadlink, OsRemove, OsRename,
OsRmdir, OsStat, OsUnlink, PathlibReplace, PyPath,
};
use crate::settings::types::PythonVersion;

Expand All @@ -20,34 +19,34 @@ pub fn replaceable_by_pathlib(checker: &mut Checker, expr: &Expr) {
.ctx
.resolve_call_path(expr)
.and_then(|call_path| match call_path.as_slice() {
["os", "path", "abspath"] => Some(PathlibAbspath.into()),
["os", "chmod"] => Some(PathlibChmod.into()),
["os", "mkdir"] => Some(PathlibMkdir.into()),
["os", "makedirs"] => Some(PathlibMakedirs.into()),
["os", "rename"] => Some(PathlibRename.into()),
["os", "path", "abspath"] => Some(OsPathAbspath.into()),
["os", "chmod"] => Some(OsChmod.into()),
["os", "mkdir"] => Some(OsMkdir.into()),
["os", "makedirs"] => Some(OsMakedirs.into()),
["os", "rename"] => Some(OsRename.into()),
["os", "replace"] => Some(PathlibReplace.into()),
["os", "rmdir"] => Some(PathlibRmdir.into()),
["os", "remove"] => Some(PathlibRemove.into()),
["os", "unlink"] => Some(PathlibUnlink.into()),
["os", "getcwd"] => Some(PathlibGetcwd.into()),
["os", "getcwdb"] => Some(PathlibGetcwd.into()),
["os", "path", "exists"] => Some(PathlibExists.into()),
["os", "path", "expanduser"] => Some(PathlibExpanduser.into()),
["os", "path", "isdir"] => Some(PathlibIsDir.into()),
["os", "path", "isfile"] => Some(PathlibIsFile.into()),
["os", "path", "islink"] => Some(PathlibIsLink.into()),
["os", "stat"] => Some(PathlibStat.into()),
["os", "path", "isabs"] => Some(PathlibIsAbs.into()),
["os", "path", "join"] => Some(PathlibJoin.into()),
["os", "path", "basename"] => Some(PathlibBasename.into()),
["os", "path", "dirname"] => Some(PathlibDirname.into()),
["os", "path", "samefile"] => Some(PathlibSamefile.into()),
["os", "path", "splitext"] => Some(PathlibSplitext.into()),
["", "open"] => Some(PathlibOpen.into()),
["py", "path", "local"] => Some(PathlibPyPath.into()),
["os", "rmdir"] => Some(OsRmdir.into()),
["os", "remove"] => Some(OsRemove.into()),
["os", "unlink"] => Some(OsUnlink.into()),
["os", "getcwd"] => Some(OsGetcwd.into()),
["os", "getcwdb"] => Some(OsGetcwd.into()),
["os", "path", "exists"] => Some(OsPathExists.into()),
["os", "path", "expanduser"] => Some(OsPathExpanduser.into()),
["os", "path", "isdir"] => Some(OsPathIsdir.into()),
["os", "path", "isfile"] => Some(OsPathIsfile.into()),
["os", "path", "islink"] => Some(OsPathIslink.into()),
["os", "stat"] => Some(OsStat.into()),
["os", "path", "isabs"] => Some(OsPathIsabs.into()),
["os", "path", "join"] => Some(OsPathJoin.into()),
["os", "path", "basename"] => Some(OsPathBasename.into()),
["os", "path", "dirname"] => Some(OsPathDirname.into()),
["os", "path", "samefile"] => Some(OsPathSamefile.into()),
["os", "path", "splitext"] => Some(OsPathSplitext.into()),
["", "open"] => Some(BuiltinOpen.into()),
["py", "path", "local"] => Some(PyPath.into()),
// Python 3.9+
["os", "readlink"] if checker.settings.target_version >= PythonVersion::Py39 => {
Some(PathlibReadlink.into())
Some(OsReadlink.into())
}
_ => None,
})
Expand Down
50 changes: 25 additions & 25 deletions crates/ruff/src/rules/flake8_use_pathlib/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,38 +23,38 @@ mod tests {
let diagnostics = test_path(
Path::new("flake8_use_pathlib").join(path).as_path(),
&settings::Settings::for_rules(vec![
Rule::PathlibAbspath,
Rule::PathlibChmod,
Rule::PathlibMkdir,
Rule::PathlibMakedirs,
Rule::PathlibRename,
Rule::OsPathAbspath,
Rule::OsChmod,
Rule::OsMkdir,
Rule::OsMakedirs,
Rule::OsRename,
Rule::PathlibReplace,
Rule::PathlibRmdir,
Rule::PathlibRemove,
Rule::PathlibUnlink,
Rule::PathlibGetcwd,
Rule::PathlibExists,
Rule::PathlibExpanduser,
Rule::PathlibIsDir,
Rule::PathlibIsFile,
Rule::PathlibIsLink,
Rule::PathlibReadlink,
Rule::PathlibStat,
Rule::PathlibIsAbs,
Rule::PathlibJoin,
Rule::PathlibBasename,
Rule::PathlibDirname,
Rule::PathlibSamefile,
Rule::PathlibSplitext,
Rule::PathlibOpen,
Rule::OsRmdir,
Rule::OsRemove,
Rule::OsUnlink,
Rule::OsGetcwd,
Rule::OsPathExists,
Rule::OsPathExpanduser,
Rule::OsPathIsdir,
Rule::OsPathIsfile,
Rule::OsPathIslink,
Rule::OsReadlink,
Rule::OsStat,
Rule::OsPathIsabs,
Rule::OsPathJoin,
Rule::OsPathBasename,
Rule::OsPathDirname,
Rule::OsPathSamefile,
Rule::OsPathSplitext,
Rule::BuiltinOpen,
]),
)?;
insta::assert_yaml_snapshot!(snapshot, diagnostics);
Ok(())
}

#[test_case(Rule::PathlibPyPath, Path::new("py_path_1.py"); "PTH024_1")]
#[test_case(Rule::PathlibPyPath, Path::new("py_path_2.py"); "PTH024_2")]
#[test_case(Rule::PyPath, Path::new("py_path_1.py"); "PTH024_1")]
#[test_case(Rule::PyPath, Path::new("py_path_2.py"); "PTH024_2")]
fn rules_pypath(rule_code: Rule, path: &Path) -> Result<()> {
let snapshot = format!("{}_{}", rule_code.noqa_code(), path.to_string_lossy());
let diagnostics = test_path(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ source: crates/ruff/src/rules/flake8_use_pathlib/mod.rs
expression: diagnostics
---
- kind:
name: PathlibPyPath
name: PyPath
body: "`py.path` is in maintenance mode, use `pathlib` instead"
suggestion: ~
fixable: false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ source: crates/ruff/src/rules/flake8_use_pathlib/mod.rs
expression: diagnostics
---
- kind:
name: PathlibPyPath
name: PyPath
body: "`py.path` is in maintenance mode, use `pathlib` instead"
suggestion: ~
fixable: false
Expand Down
Loading

0 comments on commit 875f61c

Please sign in to comment.