Skip to content

Commit

Permalink
Commit with just personally changed files.
Browse files Browse the repository at this point in the history
  • Loading branch information
ofeeg committed Aug 27, 2023
0 parents commit f43bc18
Show file tree
Hide file tree
Showing 6 changed files with 5,097 additions and 0 deletions.
692 changes: 692 additions & 0 deletions clippy_lints/src/declared_lints.rs

Large diffs are not rendered by default.

30 changes: 30 additions & 0 deletions clippy_lints/src/methods/join_absolute_paths.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
use clippy_utils::diagnostics::span_lint_and_then;
use clippy_utils::ty::is_type_diagnostic_item;
use rustc_ast::ast::LitKind;
use rustc_hir::{Expr, ExprKind};
use rustc_lint::LateContext;
use rustc_span::symbol::sym::Path;

use super::JOIN_ABSOLUTE_PATHS;

pub(super) fn check<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'tcx>, join_arg: &'tcx Expr<'tcx>) {
let ty = cx.typeck_results().expr_ty(expr).peel_refs();
if is_type_diagnostic_item(cx, ty, Path)
&& let ExprKind::Lit(spanned) = &join_arg.kind
&& let LitKind::Str(symbol, _) = spanned.node
&& (symbol.as_str().starts_with('/') || symbol.as_str().starts_with('\\'))
{
span_lint_and_then(
cx,
JOIN_ABSOLUTE_PATHS,
join_arg.span,
"argument to `Path::join` starts with a path separator",
|diag| {
diag
.note("joining a path starting with separator will replace the path instead")
.help(r#"if this is unintentional, try removing the starting separator"#)
.help(r#"if this is intentional, try creating a new Path instead"#);
},
);
}
}
Loading

0 comments on commit f43bc18

Please sign in to comment.