Skip to content

Commit 6773b83

Browse files
committed
more default dotfiles, lint single char exts, reword config
1 parent 4ef8f9d commit 6773b83

File tree

7 files changed

+29
-23
lines changed

7 files changed

+29
-23
lines changed

CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5575,6 +5575,7 @@ Released 2018-09-13
55755575
[`allow-one-hash-in-raw-strings`]: https://doc.rust-lang.org/clippy/lint_configuration.html#allow-one-hash-in-raw-strings
55765576
[`absolute-paths-max-segments`]: https://doc.rust-lang.org/clippy/lint_configuration.html#absolute-paths-max-segments
55775577
[`absolute-paths-allowed-crates`]: https://doc.rust-lang.org/clippy/lint_configuration.html#absolute-paths-allowed-crates
5578-
[`allowed-file-extensions`]: https://doc.rust-lang.org/clippy/lint_configuration.html#allowed-file-extensions
5578+
[`allowed-dotfiles`]: https://doc.rust-lang.org/clippy/lint_configuration.html#allowed-dotfiles
55795579
[`enforce-iter-loop-reborrow`]: https://doc.rust-lang.org/clippy/lint_configuration.html#enforce-iter-loop-reborrow
55805580
<!-- end autogenerated links to configuration documentation -->
5581+
mentation -->

book/src/lint_configuration.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -751,8 +751,8 @@ Which crates to allow absolute paths from
751751
* [`absolute_paths`](https://rust-lang.github.io/rust-clippy/master/index.html#absolute_paths)
752752

753753

754-
## `allowed-file-extensions`
755-
Additional file extensions to allow
754+
## `allowed-dotfiles`
755+
Additional dotfiles (files or directories starting with a dot) to allow
756756

757757
**Default Value:** `{}` (`rustc_data_structures::fx::FxHashSet<String>`)
758758

clippy_lints/src/lib.rs

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -661,24 +661,19 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf:
661661
let allow_unwrap_in_tests = conf.allow_unwrap_in_tests;
662662
let suppress_restriction_lint_in_const = conf.suppress_restriction_lint_in_const;
663663
store.register_late_pass(move |_| Box::new(approx_const::ApproxConstant::new(msrv())));
664-
let allowed_file_extensions = conf
665-
.allowed_file_extensions
664+
let allowed_dotfiles = conf
665+
.allowed_dotfiles
666666
.iter()
667667
.cloned()
668-
.chain(
669-
methods::DEFAULT_ALLOWED_FILE_EXTENSIONS
670-
.iter()
671-
.copied()
672-
.map(ToOwned::to_owned),
673-
)
668+
.chain(methods::DEFAULT_ALLOWED_DOTFILES.iter().copied().map(ToOwned::to_owned))
674669
.collect::<FxHashSet<_>>();
675670
store.register_late_pass(move |_| {
676671
Box::new(methods::Methods::new(
677672
avoid_breaking_exported_api,
678673
msrv(),
679674
allow_expect_in_tests,
680675
allow_unwrap_in_tests,
681-
allowed_file_extensions.clone(),
676+
allowed_dotfiles.clone(),
682677
))
683678
});
684679
store.register_late_pass(move |_| Box::new(matches::Matches::new(msrv())));

clippy_lints/src/methods/mod.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ use clippy_utils::msrvs::{self, Msrv};
121121
use clippy_utils::ty::{contains_ty_adt_constructor_opaque, implements_trait, is_copy, is_type_diagnostic_item};
122122
use clippy_utils::{contains_return, is_bool, is_trait_method, iter_input_pats, peel_blocks, return_ty};
123123
use if_chain::if_chain;
124-
pub use path_ends_with_ext::DEFAULT_ALLOWED_FILE_EXTENSIONS;
124+
pub use path_ends_with_ext::DEFAULT_ALLOWED_DOTFILES;
125125
use rustc_data_structures::fx::FxHashSet;
126126
use rustc_hir as hir;
127127
use rustc_hir::{Expr, ExprKind, Node, Stmt, StmtKind, TraitItem, TraitItemKind};
@@ -3606,7 +3606,7 @@ pub struct Methods {
36063606
msrv: Msrv,
36073607
allow_expect_in_tests: bool,
36083608
allow_unwrap_in_tests: bool,
3609-
allowed_file_extensions: FxHashSet<String>,
3609+
allowed_dotfiles: FxHashSet<String>,
36103610
}
36113611

36123612
impl Methods {
@@ -3616,14 +3616,14 @@ impl Methods {
36163616
msrv: Msrv,
36173617
allow_expect_in_tests: bool,
36183618
allow_unwrap_in_tests: bool,
3619-
allowed_file_extensions: FxHashSet<String>,
3619+
allowed_dotfiles: FxHashSet<String>,
36203620
) -> Self {
36213621
Self {
36223622
avoid_breaking_exported_api,
36233623
msrv,
36243624
allow_expect_in_tests,
36253625
allow_unwrap_in_tests,
3626-
allowed_file_extensions,
3626+
allowed_dotfiles,
36273627
}
36283628
}
36293629
}
@@ -4020,7 +4020,7 @@ impl Methods {
40204020
if let ExprKind::MethodCall(.., span) = expr.kind {
40214021
case_sensitive_file_extension_comparisons::check(cx, expr, span, recv, arg);
40224022
}
4023-
path_ends_with_ext::check(cx, recv, arg, expr, &self.msrv, &self.allowed_file_extensions);
4023+
path_ends_with_ext::check(cx, recv, arg, expr, &self.msrv, &self.allowed_dotfiles);
40244024
},
40254025
("expect", [_]) => {
40264026
match method_call(recv) {

clippy_lints/src/methods/path_ends_with_ext.rs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,23 +12,26 @@ use rustc_lint::LateContext;
1212
use rustc_span::sym;
1313
use std::fmt::Write;
1414

15-
pub const DEFAULT_ALLOWED_FILE_EXTENSIONS: &[&str] = &["git", "svn", "gem", "npm", "vim", "env", "rnd", "ssh", "vnc"];
15+
pub const DEFAULT_ALLOWED_DOTFILES: &[&str] = &[
16+
"git", "svn", "gem", "npm", "vim", "env", "rnd", "ssh", "vnc", "smb", "nvm", "bin",
17+
];
1618

1719
pub(super) fn check(
1820
cx: &LateContext<'_>,
1921
recv: &Expr<'_>,
2022
path: &Expr<'_>,
2123
expr: &Expr<'_>,
2224
msrv: &Msrv,
23-
allowed_paths: &FxHashSet<String>,
25+
allowed_dotfiles: &FxHashSet<String>,
2426
) {
2527
if is_type_diagnostic_item(cx, cx.typeck_results().expr_ty(recv).peel_refs(), sym::Path)
2628
&& !path.span.from_expansion()
2729
&& let ExprKind::Lit(lit) = path.kind
2830
&& let LitKind::Str(path, StrStyle::Cooked) = lit.node
2931
&& let Some(path) = path.as_str().strip_prefix('.')
30-
&& (path.len() == 2 || path.len() == 3)
31-
&& !allowed_paths.contains(path)
32+
&& (1..=3).contains(&path.len())
33+
&& !allowed_dotfiles.contains(path)
34+
&& path.chars().all(char::is_alphanumeric)
3235
{
3336
let mut sugg = snippet(cx, recv.span, "..").into_owned();
3437
if msrv.meets(msrvs::OPTION_IS_SOME_AND) {

clippy_lints/src/utils/conf.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -563,8 +563,8 @@ define_Conf! {
563563
rustc_data_structures::fx::FxHashSet::default()),
564564
/// Lint: PATH_ENDS_WITH_EXT.
565565
///
566-
/// Additional file extensions to allow
567-
(allowed_file_extensions: rustc_data_structures::fx::FxHashSet<String> =
566+
/// Additional dotfiles (files or directories starting with a dot) to allow
567+
(allowed_dotfiles: rustc_data_structures::fx::FxHashSet<String> =
568568
rustc_data_structures::fx::FxHashSet::default()),
569569
/// Lint: EXPLICIT_ITER_LOOP
570570
///

tests/ui/path_ends_with_ext.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,16 @@ fn test(path: &Path) {
1717
// most legitimate "dotfiles" are longer than 3 chars, so we allow them as well
1818
path.ends_with(".bashrc");
1919

20+
// argument from expn shouldn't trigger
2021
path.ends_with(arg!());
22+
23+
path.ends_with("..");
24+
path.ends_with("./a");
25+
path.ends_with(".");
26+
path.ends_with("");
2127
}
2228

29+
// is_some_and was stabilized in 1.70, so suggest map_or(false, ..) if under that
2330
#[clippy::msrv = "1.69"]
2431
fn under_msv(path: &Path) -> bool {
2532
path.ends_with(".md")

0 commit comments

Comments
 (0)