|
16 | 16 |
|
17 | 17 | package com.foursquare.lint
|
18 | 18 |
|
19 |
| -import scala.tools.nsc.{ Global, Phase } |
| 19 | +import scala.collection.mutable |
20 | 20 | import scala.tools.nsc.plugins.{ Plugin, PluginComponent }
|
21 |
| -import collection.mutable |
| 21 | +import scala.tools.nsc.{ Global, Phase } |
22 | 22 |
|
23 | 23 | class LinterPlugin(val global: Global) extends Plugin {
|
| 24 | + import com.foursquare.lint.Utils._ |
24 | 25 | import global._
|
25 |
| - import Utils._ |
26 | 26 |
|
27 | 27 | val name = "linter"
|
28 | 28 | val description = "a static analysis compiler plugin to help protect against bugs and style problems"
|
29 | 29 | val components = List[PluginComponent](PreTyperComponent, PostTyperComponent, PostTyperInterpreterComponent, PostRefChecksComponent)
|
30 | 30 |
|
31 | 31 | 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" |
34 | 35 | ).map(" -P:" + name + ":" + _).mkString("\n"))
|
35 | 36 |
|
36 | 37 | override def processOptions(options: List[String], error: String => Unit): Unit = {
|
@@ -1670,7 +1671,7 @@ class LinterPlugin(val global: Global) extends Plugin {
|
1670 | 1671 | class PostTyperInterpreterTraverser(unit: CompilationUnit) extends Traverser {
|
1671 | 1672 | implicit val unitt = unit
|
1672 | 1673 | var treePosHolder: Tree = null
|
1673 |
| - import Utils._ |
| 1674 | + import com.foursquare.lint.Utils._ |
1674 | 1675 | val utils = new Utils[global.type](global)
|
1675 | 1676 | import utils._
|
1676 | 1677 |
|
@@ -2617,11 +2618,11 @@ class LinterPlugin(val global: Global) extends Plugin {
|
2617 | 2618 | str.exactValue
|
2618 | 2619 | .map(v => Values(v.size))
|
2619 | 2620 | .getOrElse(
|
2620 |
| - if(str.getMinLength == str.getMaxLength) |
| 2621 | + if(str.getMinLength == str.getMaxLength) |
2621 | 2622 | Values(str.getMinLength)
|
2622 | 2623 | else if(str.getMinLength == 0 && str.getMaxLength == Int.MaxValue)
|
2623 | 2624 | Values.empty
|
2624 |
| - else |
| 2625 | + else |
2625 | 2626 | Values(str.getMinLength, str.getMaxLength)
|
2626 | 2627 | ).addCondition(_ >= 0).addCondition(_ < str.getMaxLength)
|
2627 | 2628 | )
|
@@ -2854,7 +2855,7 @@ class LinterPlugin(val global: Global) extends Plugin {
|
2854 | 2855 | val posFiltering = treePosHolder.toString matches (".*?[ .]"+ f + """ *[(].*, *("{2}|"{6}) *[)]""")
|
2855 | 2856 |
|
2856 | 2857 | val special = """.\^$*+?()\[{\\|"""
|
2857 |
| - val plainString = s"""([^${special}]|[\\\\][${special}])+""" |
| 2858 | + val plainString = s"""([^$special]|[\\\\][$special])+""" |
2858 | 2859 |
|
2859 | 2860 | if(posFiltering && (p0 matches plainString+"\\$"))
|
2860 | 2861 | warn(treePosHolder, RegexWarning(s"This $f can be substituted with stripSuffix", error = false))
|
@@ -3010,15 +3011,12 @@ class LinterPlugin(val global: Global) extends Plugin {
|
3010 | 3011 | }
|
3011 | 3012 | } catch {
|
3012 | 3013 | case e: Exception =>
|
3013 |
| - e.printStackTrace |
3014 | 3014 | empty
|
3015 | 3015 | }
|
3016 | 3016 |
|
3017 | 3017 | case Apply(Ident(name), _params) if defModels contains name.toString =>
|
3018 | 3018 | 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) |
3022 | 3020 |
|
3023 | 3021 | case If(_cond, expr1, expr2) =>
|
3024 | 3022 | val (e1, e2) = (traverseString(expr1), traverseString(expr2))
|
@@ -3173,8 +3171,8 @@ class LinterPlugin(val global: Global) extends Plugin {
|
3173 | 3171 | knownPieces = knownPieces map { _.reverse })
|
3174 | 3172 |
|
3175 | 3173 | 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) |
3178 | 3176 | new StringAttrs(
|
3179 | 3177 | exactValue = exactValue.map { _.trim },
|
3180 | 3178 | minLength = newMinLength,
|
@@ -3212,10 +3210,10 @@ class LinterPlugin(val global: Global) extends Plugin {
|
3212 | 3210 | def alwaysIsEmpty: Boolean = getMaxLength == 0
|
3213 | 3211 | def alwaysNonEmpty: Boolean = getMinLength > 0
|
3214 | 3212 |
|
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) |
3219 | 3217 |
|
3220 | 3218 | def +(s: String): StringAttrs =
|
3221 | 3219 | new StringAttrs(
|
|
0 commit comments