Skip to content

Commit 6c6a841

Browse files
committedFeb 7, 2015
Clean up lint found by IntelliJ IDEA
1 parent c4d41b3 commit 6c6a841

11 files changed

+95
-94
lines changed
 

‎.gitignore

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
.DS_Store
22
/target/
33
/project/target/
4-
/project/project/target
4+
/project/project/
55
*~
66
*.orig
77
*.log
88
*.jar
99
*.class
1010

11+
.idea
12+
*.iml

‎README.md

+5-4
Original file line numberDiff line numberDiff line change
@@ -222,18 +222,19 @@ Rule lists from other static analysis tools:
222222
* Scapegoat(Scala) - https://github.com/sksamuel/scalac-scapegoat-plugin#inspections
223223
* WartRemover(Scala) - https://github.com/typelevel/wartremover#warts
224224
* Scala Abide(Scala) - https://github.com/scala/scala-abide
225-
* SuperSafe™(Scala) - http://www.artima.com/supersafe_user_guide.html
225+
* ($)SuperSafe™(Scala) - http://www.artima.com/supersafe_user_guide.html
226+
* IntelliJ IDEA(Scala/...) - https://www.jetbrains.com/idea/features/scala.html
226227
* Findbugs(JVM) - http://findbugs.sourceforge.net/bugDescriptions.html
227228
* CheckStyle(Java) - http://checkstyle.sourceforge.net/availablechecks.html
228229
* PMD(Java) - http://pmd.sourceforge.net/snapshot/pmd-java/rules/index.html
229230
* Error-prone(Java) - https://code.google.com/p/error-prone/wiki/BugPatterns
230231
* CodeNarc(Groovy) - http://codenarc.sourceforge.net/codenarc-rule-index.html
231-
* PVS-Studio(C++) - http://www.viva64.com/en/d/
232-
* Coverity(C++) - http://www.slideshare.net/Coverity/static-analysis-primer-22874326 (6,7)
232+
* ($)PVS-Studio(C++) - http://www.viva64.com/en/d/
233+
* ($)Coverity(C++/Java/...) - http://www.slideshare.net/Coverity/static-analysis-primer-22874326 (6,7)
233234
* CppCheck(C++) - http://sourceforge.net/apps/mediawiki/cppcheck/index.php?title=Main_Page#Checks
234235
* Clang(C++/ObjC) - http://clang-analyzer.llvm.org/available_checks.html
235236
* OCLint(C++/ObjC) - http://docs.oclint.org/en/dev/rules/index.html
236-
* Fortify(Java/C++/...) - http://www.hpenterprisesecurity.com/vulncat/en/vulncat/index.html
237+
* ($)Fortify(Java/C++/...) - http://www.hpenterprisesecurity.com/vulncat/en/vulncat/index.html
237238

238239
### Some resources
239240
* A quick overview of writing compiler plugins: http://www.scala-lang.org/node/140

‎build.sbt

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ libraryDependencies ++= Seq(
1515
"junit" % "junit" % "4.12" % "test",
1616
"com.novocode" % "junit-interface" % "0.11" % "test")
1717

18-
libraryDependencies <+= (scalaVersion) { (scalaVersion) =>
18+
libraryDependencies <+= scalaVersion { (scalaVersion) =>
1919
"org.scala-lang" % "scala-compiler" % scalaVersion
2020
}
2121

‎src/main/scala/LinterOptions.scala

+5-5
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
package com.foursquare.lint
1818

19-
import annotation.tailrec
19+
import scala.annotation.tailrec
2020

2121
case class LinterOptions(disabledWarningNames: Seq[String] = Nil, printWarningNames: Boolean = false)
2222

@@ -33,8 +33,8 @@ object LinterOptions {
3333
case Array(option, warningNames) =>
3434
val (validNames, invalidNames) = warningNames.split(WarningNameDelimiter).partition(Warning.NameToWarning.contains)
3535
if (validNames.nonEmpty && invalidNames.isEmpty) Right(validNames)
36-
else Left(s"The '${option}' option referenced invalid warnings: ${invalidNames.mkString(", ")}")
37-
case _ => Left(s"The '${fullOption}' option was not of the expected form.")
36+
else Left(s"The '$option' option referenced invalid warnings: ${invalidNames.mkString(", ")}")
37+
case _ => Left(s"The '$fullOption' option was not of the expected form.")
3838
}
3939

4040
@tailrec
@@ -48,8 +48,8 @@ object LinterOptions {
4848
case option :: xs if option.startsWith(PrintWarningNames) => option.split(OptionKeyValueDelimiter) match {
4949
case Array(_, value @ ("true" | "false")) => Right(linterOptions.copy(printWarningNames = value.toBoolean))
5050
case Array(_) if option == PrintWarningNames => Right(linterOptions.copy(printWarningNames = true))
51-
case _ => Left(s"The '${option}' option was not of the expected form")
51+
case _ => Left(s"The '$option' option was not of the expected form")
5252
}
53-
case unknownOption :: _ => Left(s"The option '${unknownOption}' is unrecognized.")
53+
case unknownOption :: _ => Left(s"The option '$unknownOption' is unrecognized.")
5454
}
5555
}

‎src/main/scala/LinterPlugin.scala

+17-19
Original file line numberDiff line numberDiff line change
@@ -16,21 +16,22 @@
1616

1717
package com.foursquare.lint
1818

19-
import scala.tools.nsc.{ Global, Phase }
19+
import scala.collection.mutable
2020
import scala.tools.nsc.plugins.{ Plugin, PluginComponent }
21-
import collection.mutable
21+
import scala.tools.nsc.{ Global, Phase }
2222

2323
class LinterPlugin(val global: Global) extends Plugin {
24+
import com.foursquare.lint.Utils._
2425
import global._
25-
import Utils._
2626

2727
val name = "linter"
2828
val description = "a static analysis compiler plugin to help protect against bugs and style problems"
2929
val components = List[PluginComponent](PreTyperComponent, PostTyperComponent, PostTyperInterpreterComponent, PostRefChecksComponent)
3030

3131
override val optionsHelp: Option[String] = Some(Seq(
32-
"%s:plus+separated+warning+names".format(LinterOptions.DisableArgument),
33-
"%s:plus+separated+warning+names".format(LinterOptions.EnableOnlyArgument)
32+
LinterOptions.DisableArgument+":plus+separated+warning+names",
33+
LinterOptions.EnableOnlyArgument+":plus+separated+warning+names",
34+
LinterOptions.PrintWarningNames+":true|false"
3435
).map(" -P:" + name + ":" + _).mkString("\n"))
3536

3637
override def processOptions(options: List[String], error: String => Unit): Unit = {
@@ -1670,7 +1671,7 @@ class LinterPlugin(val global: Global) extends Plugin {
16701671
class PostTyperInterpreterTraverser(unit: CompilationUnit) extends Traverser {
16711672
implicit val unitt = unit
16721673
var treePosHolder: Tree = null
1673-
import Utils._
1674+
import com.foursquare.lint.Utils._
16741675
val utils = new Utils[global.type](global)
16751676
import utils._
16761677

@@ -2617,11 +2618,11 @@ class LinterPlugin(val global: Global) extends Plugin {
26172618
str.exactValue
26182619
.map(v => Values(v.size))
26192620
.getOrElse(
2620-
if(str.getMinLength == str.getMaxLength)
2621+
if(str.getMinLength == str.getMaxLength)
26212622
Values(str.getMinLength)
26222623
else if(str.getMinLength == 0 && str.getMaxLength == Int.MaxValue)
26232624
Values.empty
2624-
else
2625+
else
26252626
Values(str.getMinLength, str.getMaxLength)
26262627
).addCondition(_ >= 0).addCondition(_ < str.getMaxLength)
26272628
)
@@ -2854,7 +2855,7 @@ class LinterPlugin(val global: Global) extends Plugin {
28542855
val posFiltering = treePosHolder.toString matches (".*?[ .]"+ f + """ *[(].*, *("{2}|"{6}) *[)]""")
28552856

28562857
val special = """.\^$*+?()\[{\\|"""
2857-
val plainString = s"""([^${special}]|[\\\\][${special}])+"""
2858+
val plainString = s"""([^$special]|[\\\\][$special])+"""
28582859

28592860
if(posFiltering && (p0 matches plainString+"\\$"))
28602861
warn(treePosHolder, RegexWarning(s"This $f can be substituted with stripSuffix", error = false))
@@ -3010,15 +3011,12 @@ class LinterPlugin(val global: Global) extends Plugin {
30103011
}
30113012
} catch {
30123013
case e: Exception =>
3013-
e.printStackTrace
30143014
empty
30153015
}
30163016

30173017
case Apply(Ident(name), _params) if defModels contains name.toString =>
30183018
defModels
3019-
.find(m => m._1 == name.toString && m._2.isRight)
3020-
.map(_._2.right.get)
3021-
.getOrElse(empty)
3019+
.find(m => m._1 == name.toString && m._2.isRight).fold(empty)(_._2.right.get)
30223020

30233021
case If(_cond, expr1, expr2) =>
30243022
val (e1, e2) = (traverseString(expr1), traverseString(expr2))
@@ -3173,8 +3171,8 @@ class LinterPlugin(val global: Global) extends Plugin {
31733171
knownPieces = knownPieces map { _.reverse })
31743172

31753173
def trim: StringAttrs = {
3176-
val newMinLength = exactValue.map(_.trim.size).getOrElse(getTrimmedMinLength)
3177-
val newMaxLength = exactValue.map(_.trim.size).getOrElse(getTrimmedMaxLength)
3174+
val newMinLength = exactValue.fold(getTrimmedMinLength)(_.trim.size)
3175+
val newMaxLength = exactValue.fold(getTrimmedMaxLength)(_.trim.size)
31783176
new StringAttrs(
31793177
exactValue = exactValue.map { _.trim },
31803178
minLength = newMinLength,
@@ -3212,10 +3210,10 @@ class LinterPlugin(val global: Global) extends Plugin {
32123210
def alwaysIsEmpty: Boolean = getMaxLength == 0
32133211
def alwaysNonEmpty: Boolean = getMinLength > 0
32143212

3215-
def getMinLength: Int = exactValue.map(_.size).getOrElse(minLength)
3216-
def getMaxLength: Int = exactValue.map(_.size).getOrElse(maxLength)
3217-
def getTrimmedMinLength: Int = exactValue.map(_.trim.size).getOrElse(trimmedMinLength)
3218-
def getTrimmedMaxLength: Int = exactValue.map(_.trim.size).getOrElse(trimmedMaxLength)
3213+
def getMinLength: Int = exactValue.fold(minLength)(_.size)
3214+
def getMaxLength: Int = exactValue.fold(maxLength)(_.size)
3215+
def getTrimmedMinLength: Int = exactValue.fold(trimmedMinLength)(_.trim.size)
3216+
def getTrimmedMaxLength: Int = exactValue.fold(trimmedMaxLength)(_.trim.size)
32193217

32203218
def +(s: String): StringAttrs =
32213219
new StringAttrs(

‎src/main/scala/Utils.scala

+2-2
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@
1616

1717
package com.foursquare.lint
1818

19+
import scala.collection.mutable
1920
import scala.tools.nsc.Global
20-
import collection.mutable
2121

2222
object Utils {
2323
var linterOptions = LinterOptions()
@@ -60,7 +60,7 @@ class Utils[G <: Global](val global: G) {
6060
used
6161
}
6262

63-
import definitions.{ AnyClass, NothingClass, ObjectClass, Object_==, OptionClass, SeqClass }
63+
import definitions.{ AnyClass, OptionClass }
6464
val JavaConversionsModule: Symbol = rootMirror.getModuleByName(newTermName("scala.collection.JavaConversions"))
6565
val SeqLikeClass: Symbol = rootMirror.getClassByName(newTermName("scala.collection.SeqLike"))
6666
val SeqLikeContains: Symbol = SeqLikeClass.info.member(newTermName("contains"))

0 commit comments

Comments
 (0)