Declare lint.

This commit is contained in:
xiongmao86 2020-01-02 13:12:23 +08:00
parent 3a788452e2
commit 96334d0d7c
4 changed files with 46 additions and 0 deletions

View File

@ -1093,6 +1093,7 @@ Released 2018-09-13
[`extend_from_slice`]: https://rust-lang.github.io/rust-clippy/master/index.html#extend_from_slice
[`extra_unused_lifetimes`]: https://rust-lang.github.io/rust-clippy/master/index.html#extra_unused_lifetimes
[`fallible_impl_from`]: https://rust-lang.github.io/rust-clippy/master/index.html#fallible_impl_from
[`filetype_is_file`]: https://rust-lang.github.io/rust-clippy/master/index.html#filetype_is_file
[`filter_map`]: https://rust-lang.github.io/rust-clippy/master/index.html#filter_map
[`filter_map_next`]: https://rust-lang.github.io/rust-clippy/master/index.html#filter_map_next
[`filter_next`]: https://rust-lang.github.io/rust-clippy/master/index.html#filter_next

View File

@ -612,6 +612,7 @@ pub fn register_plugins(store: &mut lint::LintStore, sess: &Session, conf: &Conf
&methods::CLONE_ON_COPY,
&methods::CLONE_ON_REF_PTR,
&methods::EXPECT_FUN_CALL,
&methods::FILETYPE_IS_FILE,
&methods::FILTER_MAP,
&methods::FILTER_MAP_NEXT,
&methods::FILTER_NEXT,
@ -1199,6 +1200,7 @@ pub fn register_plugins(store: &mut lint::LintStore, sess: &Session, conf: &Conf
LintId::of(&methods::CLONE_DOUBLE_REF),
LintId::of(&methods::CLONE_ON_COPY),
LintId::of(&methods::EXPECT_FUN_CALL),
LintId::of(&methods::FILETYPE_IS_FILE),
LintId::of(&methods::FILTER_NEXT),
LintId::of(&methods::FLAT_MAP_IDENTITY),
LintId::of(&methods::INEFFICIENT_TO_STRING),
@ -1384,6 +1386,7 @@ pub fn register_plugins(store: &mut lint::LintStore, sess: &Session, conf: &Conf
LintId::of(&mem_replace::MEM_REPLACE_OPTION_WITH_NONE),
LintId::of(&mem_replace::MEM_REPLACE_WITH_DEFAULT),
LintId::of(&methods::CHARS_LAST_CMP),
LintId::of(&methods::FILETYPE_IS_FILE),
LintId::of(&methods::INTO_ITER_ON_REF),
LintId::of(&methods::ITER_CLONED_COLLECT),
LintId::of(&methods::ITER_NTH_ZERO),

View File

@ -1130,6 +1130,40 @@ declare_clippy_lint! {
"Check for offset calculations on raw pointers to zero-sized types"
}
declare_clippy_lint! {
/// **What it does:** Checks for `FileType::is_file()`.
///
/// **Why is this bad?** When people testing a file type with `FileType::is_file`
/// they are testing whether a path is something they can get bytes from. But
/// `is_file` doesn't cover special file types in unix-like systems. and not covering
/// symlink in windows. Using `!FileType::is_dir()` is a better way to that intention.
///
/// **Example:**
///
/// ```rust,ignore
/// let metadata = std::fs::metadata("foo.txt")?;
/// let filetype = metadata.file_type();
///
/// if filetype.is_file() {
/// // read file
/// }
/// ```
///
/// should be writing as:
///
/// ```rust,ignore
/// let metadata = std::fs::metadata("foo.txt")?;
/// let filetype = metadata.file_type();
///
/// if !filetype.is_dir() {
/// // read file
/// }
/// ```
pub FILETYPE_IS_FILE,
style,
"`FileType::is_file` is not recommended to test for readable file type."
}
declare_lint_pass!(Methods => [
OPTION_UNWRAP_USED,
RESULT_UNWRAP_USED,
@ -1177,6 +1211,7 @@ declare_lint_pass!(Methods => [
UNINIT_ASSUMED_INIT,
MANUAL_SATURATING_ARITHMETIC,
ZST_OFFSET,
FILETYPE_IS_FILE,
]);
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Methods {

View File

@ -560,6 +560,13 @@ pub const ALL_LINTS: [Lint; 346] = [
deprecation: None,
module: "fallible_impl_from",
},
Lint {
name: "filetype_is_file",
group: "style",
desc: "`FileType::is_file` is not recommended to test for readable file type.",
deprecation: None,
module: "methods",
},
Lint {
name: "filter_map",
group: "pedantic",