From 66823a78e4e04fc5f685263f309661b526668bc8 Mon Sep 17 00:00:00 2001 From: Thibault Czarniak Date: Wed, 11 Sep 2024 15:07:57 +0200 Subject: [PATCH] Fixed a few minor issues in CatchThrowable, NullParameter and UnsafeTraversableMethods --- rules/src/main/scala/fix/CatchThrowable.scala | 2 +- rules/src/main/scala/fix/NullParameter.scala | 2 +- rules/src/main/scala/fix/UnsafeTraversableMethods.scala | 8 ++++---- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/rules/src/main/scala/fix/CatchThrowable.scala b/rules/src/main/scala/fix/CatchThrowable.scala index 775b4cc..59eff91 100644 --- a/rules/src/main/scala/fix/CatchThrowable.scala +++ b/rules/src/main/scala/fix/CatchThrowable.scala @@ -12,7 +12,7 @@ class CatchThrowable extends SemanticRule("CatchThrowable") { private def diag(pos: Position) = Diagnostic( "", - "Checks for try blocks that catch Throwable..", + "Checks for try blocks that catch Throwable.", pos, "Did you intend to catch all throwables? Consider catching a more specific exception class.", LintSeverity.Warning diff --git a/rules/src/main/scala/fix/NullParameter.scala b/rules/src/main/scala/fix/NullParameter.scala index ac93575..e2585f7 100644 --- a/rules/src/main/scala/fix/NullParameter.scala +++ b/rules/src/main/scala/fix/NullParameter.scala @@ -20,7 +20,7 @@ class NullParameter extends SemanticRule("NullParameter") { override def fix(implicit doc: SemanticDocument): Patch = { doc.tree.collect { - case Term.ArgClause(values, _) => values.collect { + case Term.Apply.After_4_6_0(_, Term.ArgClause(values, _)) => values.collect { case Lit.Null() => Patch.lint(diag(values.head.pos)) case _ => Patch.empty } diff --git a/rules/src/main/scala/fix/UnsafeTraversableMethods.scala b/rules/src/main/scala/fix/UnsafeTraversableMethods.scala index e1dffa6..570657c 100644 --- a/rules/src/main/scala/fix/UnsafeTraversableMethods.scala +++ b/rules/src/main/scala/fix/UnsafeTraversableMethods.scala @@ -34,12 +34,12 @@ class UnsafeTraversableMethods extends SemanticRule("UnsafeTraversableMethods") override def fix(implicit doc: SemanticDocument): Patch = { doc.tree.collect { - case Term.Select(qual @ Term.Name(_), Term.Name(str)) + case t @ Term.Select(qual @ Term.Name(_), Term.Name(str)) if unsafeMethods.contains(str) - && Util.inheritsFrom(qual, "scala/collection/Iterable#") => Patch.lint(diag(qual.pos)) - case Term.Select(Term.Apply.After_4_6_0(qual @ Term.Name(_), _), Term.Name(str)) + && Util.inheritsFrom(qual, "scala/collection/Iterable#") => Patch.lint(diag(t.pos)) + case t @ Term.Select(Term.Apply.After_4_6_0(qual @ Term.Name(_), _), Term.Name(str)) if unsafeMethods.contains(str) - && Util.inheritsFrom(qual, "scala/collection/Iterable#") => Patch.lint(diag(qual.pos)) + && Util.inheritsFrom(qual, "scala/collection/Iterable#") => Patch.lint(diag(t.pos)) case _ => Patch.empty }.asPatch }