Skip to content

Commit 703f85e

Browse files
committed
why was i doing that manually?
1 parent a239b22 commit 703f85e

File tree

1 file changed

+58
-66
lines changed

1 file changed

+58
-66
lines changed
Lines changed: 58 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
use clippy_utils::diagnostics::span_lint_and_help;
22
use rustc_ast::{
3-
ast::{ItemKind, UseTree, UseTreeKind},
4-
Item,
3+
visit::{walk_item, Visitor},
4+
*,
55
};
6-
use rustc_hir::*;
76
use rustc_lint::{EarlyContext, EarlyLintPass, LateContext, LateLintPass, LintContext};
87
use rustc_middle::lint::in_external_macro;
98
use rustc_session::{declare_tool_lint, impl_lint_pass};
@@ -64,77 +63,70 @@ pub struct ExcessiveIndentation {
6463
impl EarlyLintPass for ExcessiveIndentation {
6564
fn check_item(&mut self, cx: &EarlyContext<'_>, item: &Item) {
6665
match &item.kind {
67-
// TODO:
68-
// Use ✅
69-
// Static ❌
70-
// Const ❌
71-
// Fn ❌
72-
// Mod ❌
73-
// ForeignMod ❌
74-
// Enum ❌
75-
// Struct ❌
76-
// Union ❌
77-
// Trait ❌
78-
// Impl ❌
79-
// MacroDef ❓
80-
// Others don't increase indentation (unless your formatting is really weird) so they won't be included.
81-
ItemKind::Use(use_tree) => walk_use_tree(self, cx, use_tree, 0),
8266
_ => (),
8367
}
8468
}
8569
}
8670

87-
fn check_indent(conf: &mut ExcessiveIndentation, cx: &EarlyContext<'_>, span: Span, indent: u64) -> bool {
88-
if indent > conf.excessive_indentation_threshold {
89-
span_lint_and_help(cx, EXCESSIVE_INDENTATION, span, "a", None, "b");
90-
91-
return true;
92-
}
93-
94-
false
71+
struct IndentationVisitor {
72+
indent: u64,
9573
}
9674

97-
fn walk_use_tree(conf: &mut ExcessiveIndentation, cx: &EarlyContext<'_>, use_tree: &UseTree, indent: u64) {
98-
if check_indent(conf, cx, use_tree.span, indent) {
99-
return;
100-
}
101-
102-
if let UseTreeKind::Nested(use_trees) = use_tree.kind.clone() {
103-
for use_tree in use_trees {
104-
walk_use_tree(conf, cx, &use_tree.0, indent + 1);
105-
}
106-
}
107-
}
108-
109-
impl LateLintPass<'_> for ExcessiveIndentation {
110-
fn check_stmt(&mut self, cx: &LateContext<'_>, stmt: &Stmt<'_>) {
111-
if in_external_macro(cx.sess(), stmt.span) {
112-
return;
113-
}
114-
115-
if let Ok(lines) = cx.sess().source_map().span_to_lines(stmt.span).map(|info| info.lines) {
116-
for line in &lines {
117-
let indentation = if self.excessive_width_ignore_indentation {
118-
line.start_col
119-
} else {
120-
CharPos::from_usize(0)
121-
};
122-
123-
// TODO: yeah, no.
124-
if (line.end_col.to_usize()
125-
- line.start_col.to_usize() * self.excessive_width_ignore_indentation as usize)
126-
> self.excessive_width_threshold as usize
127-
{
128-
span_lint_and_help(
129-
cx,
130-
EXCESSIVE_WIDTH,
131-
stmt.span,
132-
"this line is too long",
133-
None,
134-
"consider running rustfmt or refactoring this",
135-
);
136-
}
75+
impl Visitor<'_> for IndentationVisitor {
76+
fn visit_crate(&mut self, krate: &Crate) {
77+
for item in krate.items {
78+
match item.kind {
79+
// TODO:
80+
// Use ✅
81+
// Static ❌
82+
// Const ❌
83+
// Fn ❌
84+
// Mod ❌
85+
// ForeignMod ❌
86+
// Enum ❌
87+
// Struct ❌
88+
// Union ❌
89+
// Trait ❌
90+
// Impl ❌
91+
// MacroDef ❓
92+
// Others don't increase indentation (unless your formatting is really weird) so they won't be included.
93+
ItemKind::Use(use_tree) => todo!(),
94+
_ => (),
13795
}
13896
}
13997
}
14098
}
99+
100+
// impl LateLintPass<'_> for ExcessiveIndentation {
101+
// fn check_stmt(&mut self, cx: &LateContext<'_>, stmt: &Stmt<'_>) {
102+
// if in_external_macro(cx.sess(), stmt.span) {
103+
// return;
104+
// }
105+
//
106+
// if let Ok(lines) = cx.sess().source_map().span_to_lines(stmt.span).map(|info| info.lines)
107+
// { for line in &lines {
108+
// let indentation = if self.excessive_width_ignore_indentation {
109+
// line.start_col
110+
// } else {
111+
// CharPos::from_usize(0)
112+
// };
113+
//
114+
// // TODO: yeah, no.
115+
// if (line.end_col.to_usize()
116+
// - line.start_col.to_usize() * self.excessive_width_ignore_indentation as
117+
// usize)
118+
// > self.excessive_width_threshold as usize
119+
// {
120+
// span_lint_and_help(
121+
// cx,
122+
// EXCESSIVE_WIDTH,
123+
// stmt.span,
124+
// "this line is too long",
125+
// None,
126+
// "consider running rustfmt or refactoring this",
127+
// );
128+
// }
129+
// }
130+
// }
131+
// }
132+
// }

0 commit comments

Comments
 (0)