1 use crate::{EarlyContext, EarlyLintPass, LintContext};
2 use rustc_errors::Applicability;
3 use syntax::ast::{ExprKind, Stmt, StmtKind};
6 pub REDUNDANT_SEMICOLON,
8 "detects unnecessary trailing semicolons"
11 declare_lint_pass!(RedundantSemicolon => [REDUNDANT_SEMICOLON]);
13 impl EarlyLintPass for RedundantSemicolon {
14 fn check_stmt(&mut self, cx: &EarlyContext<'_>, stmt: &Stmt) {
15 if let StmtKind::Semi(expr) = &stmt.kind {
16 if let ExprKind::Tup(ref v) = &expr.kind {
18 // Strings of excess semicolons are encoded as empty tuple expressions
19 // during the parsing stage, so we check for empty tuple expressions
20 // which span only semicolons
21 if let Ok(source_str) = cx.sess().source_map().span_to_snippet(stmt.span) {
22 if source_str.chars().all(|c| c == ';') {
23 let multiple = (stmt.span.hi() - stmt.span.lo()).0 > 1;
24 let msg = if multiple {
25 "unnecessary trailing semicolons"
27 "unnecessary trailing semicolon"
29 let mut err = cx.struct_span_lint(REDUNDANT_SEMICOLON, stmt.span, &msg);
30 let suggest_msg = if multiple {
31 "remove these semicolons"
33 "remove this semicolon"
39 Applicability::MaybeIncorrect,