diff --git a/.scalafmt.conf b/.scalafmt.conf index eb30fc05..69f27a1c 100644 --- a/.scalafmt.conf +++ b/.scalafmt.conf @@ -1,4 +1,4 @@ -version = "2.7.5" +version = "3.0.2" project.git = true assumeStandardLibraryStripMargin = true xmlLiterals.assumeFormatted = true diff --git a/scalac-scoverage-plugin/src/main/scala/scoverage/CoverageFilter.scala b/scalac-scoverage-plugin/src/main/scala/scoverage/CoverageFilter.scala index 189720ad..b58fef34 100644 --- a/scalac-scoverage-plugin/src/main/scala/scoverage/CoverageFilter.scala +++ b/scalac-scoverage-plugin/src/main/scala/scoverage/CoverageFilter.scala @@ -7,7 +7,8 @@ import scala.util.matching.Regex /** Methods related to filtering the instrumentation and coverage. * - * @author Stephen Samuel + * @author + * Stephen Samuel */ trait CoverageFilter { def isClassIncluded(className: String): Boolean @@ -36,8 +37,8 @@ class RegexCoverageFilter( val excludedSymbolPatterns = excludedSymbols.map(_.r.pattern) /** We cache the excluded ranges to avoid scanning the source code files - * repeatedly. For a large project there might be a lot of source code - * data, so we only hold a weak reference. + * repeatedly. For a large project there might be a lot of source code data, + * so we only hold a weak reference. */ val linesExcludedByScoverageCommentsCache : mutable.Map[SourceFile, List[Range]] = mutable.WeakHashMap.empty @@ -61,7 +62,8 @@ class RegexCoverageFilter( excludedFilePatterns.isEmpty || !isFileMatch(file) } - /** True if the line containing `position` has not been excluded by a magic comment. + /** True if the line containing `position` has not been excluded by a magic + * comment. */ def isLineIncluded(position: Position): Boolean = { if (position.isDefined) { diff --git a/scalac-scoverage-plugin/src/main/scala/scoverage/Location.scala b/scalac-scoverage-plugin/src/main/scala/scoverage/Location.scala index 94a6fcef..2af5b61f 100644 --- a/scalac-scoverage-plugin/src/main/scala/scoverage/Location.scala +++ b/scalac-scoverage-plugin/src/main/scala/scoverage/Location.scala @@ -2,9 +2,12 @@ package scoverage import scala.tools.nsc.Global -/** @param packageName the name of the enclosing package - * @param className the name of the closest enclosing class - * @param fullClassName the fully qualified name of the closest enclosing class +/** @param packageName + * the name of the enclosing package + * @param className + * the name of the closest enclosing class + * @param fullClassName + * the fully qualified name of the closest enclosing class */ case class Location( packageName: String, diff --git a/scalac-scoverage-plugin/src/main/scala/scoverage/coverage.scala b/scalac-scoverage-plugin/src/main/scala/scoverage/coverage.scala index aaad4cb2..5b413758 100644 --- a/scalac-scoverage-plugin/src/main/scala/scoverage/coverage.scala +++ b/scalac-scoverage-plugin/src/main/scala/scoverage/coverage.scala @@ -6,7 +6,8 @@ import scala.collection.mutable import scoverage.DoubleFormat.twoFractionDigits -/** @author Stephen Samuel +/** @author + * Stephen Samuel */ case class Coverage() extends CoverageMetrics @@ -103,9 +104,9 @@ case class MeasuredClass(fullClassName: String, statements: Iterable[Statement]) def source: String = statements.head.source def loc = statements.map(_.line).max - /** The class name for display is the FQN minus the package, - * for example "com.a.Foo.Bar.Baz" should display as "Foo.Bar.Baz" - * and "com.a.Foo" should display as "Foo". + /** The class name for display is the FQN minus the package, for example + * "com.a.Foo.Bar.Baz" should display as "Foo.Bar.Baz" and "com.a.Foo" should + * display as "Foo". * * This is used in the class lists in the package and overview pages. */ @@ -206,7 +207,8 @@ trait CoverageMetrics { def invokedBranches: Iterable[Statement] = branches.filter(_.count > 0) def invokedBranchesCount = invokedBranches.size - /** @see http://stackoverflow.com/questions/25184716/scoverage-ambiguous-measurement-from-branch-coverage + /** @see + * http://stackoverflow.com/questions/25184716/scoverage-ambiguous-measurement-from-branch-coverage */ def branchCoverage: Double = { // if there are zero branches, then we have a single line of execution. diff --git a/scalac-scoverage-plugin/src/main/scala/scoverage/plugin.scala b/scalac-scoverage-plugin/src/main/scala/scoverage/plugin.scala index 02b6c557..0b3ee20a 100644 --- a/scalac-scoverage-plugin/src/main/scala/scoverage/plugin.scala +++ b/scalac-scoverage-plugin/src/main/scala/scoverage/plugin.scala @@ -138,10 +138,9 @@ class ScoverageInstrumentationComponent( override val runsBefore: List[String] = List("patmat") ::: extraBeforePhase.toList - /** Our options are not provided at construction time, but shortly after, - * so they start as None. - * You must call "setOptions" before running any commands that rely on - * the options. + /** Our options are not provided at construction time, but shortly after, so + * they start as None. You must call "setOptions" before running any commands + * that rely on the options. */ private var options: ScoverageOptions = new ScoverageOptions() private var coverageFilter: CoverageFilter = AllCoverageFilter @@ -198,10 +197,10 @@ class ScoverageInstrumentationComponent( // contains the location of the last node var location: Location = _ - /** The 'start' of the position, if it is available, else -1 - * We cannot use 'isDefined' to test whether pos.start will work, as some - * classes (e.g. scala.reflect.internal.util.OffsetPosition have - * isDefined true, but throw on `start` + /** The 'start' of the position, if it is available, else -1 We cannot use + * 'isDefined' to test whether pos.start will work, as some classes (e.g. + * scala.reflect.internal.util.OffsetPosition have isDefined true, but + * throw on `start` */ def safeStart(tree: Tree): Int = scala.util.Try(tree.pos.start).getOrElse(-1) @@ -517,15 +516,15 @@ class ScoverageInstrumentationComponent( // case a: GenericApply if a.symbol.isConstructor && a.symbol.enclClass.isAnonymousFunction => tree // case a: GenericApply if a.symbol.isConstructor => instrument(a) - /** When an apply has no parameters, or is an application of purely literals or idents - * then we can simply instrument the outer call. Ie, we can treat it all as one single statement - * for the purposes of code coverage. - * This will include calls to case apply. + /** When an apply has no parameters, or is an application of purely + * literals or idents then we can simply instrument the outer call. Ie, + * we can treat it all as one single statement for the purposes of code + * coverage. This will include calls to case apply. */ case a: GenericApply if allConstArgs(a.args) => instrument(a, a) - /** Applications of methods with non trivial args means the args themselves - * must also be instrumented + /** Applications of methods with non trivial args means the args + * themselves must also be instrumented */ //todo remove once scala merges into Apply proper case a: ApplyToImplicitArgs => @@ -560,17 +559,15 @@ class ScoverageInstrumentationComponent( a ) - /** pattern match with syntax `Assign(lhs, rhs)`. - * This AST node corresponds to the following Scala code: - * lhs = rhs + /** pattern match with syntax `Assign(lhs, rhs)`. This AST node + * corresponds to the following Scala code: lhs = rhs */ case assign: Assign => treeCopy.Assign(assign, assign.lhs, process(assign.rhs)) - /** pattern match with syntax `Block(stats, expr)`. - * This AST node corresponds to the following Scala code: - * { stats; expr } - * If the block is empty, the `expr` is set to `Literal(Constant(()))`. + /** pattern match with syntax `Block(stats, expr)`. This AST node + * corresponds to the following Scala code: { stats; expr } If the + * block is empty, the `expr` is set to `Literal(Constant(()))`. */ case b: Block => treeCopy.Block(b, transformStatements(b.stats), transform(b.expr)) @@ -624,10 +621,12 @@ class ScoverageInstrumentationComponent( // we can ignore primary constructors because they are just empty at this stage, the body is added later. case d: DefDef if d.symbol.isPrimaryConstructor => tree - /** Case class accessors for vals - * EG for case class CreditReject(req: MarketOrderRequest, client: ActorRef) - * def req: com.sksamuel.scoverage.samples.MarketOrderRequest - * def client: akka.actor.ActorRef + /** Case class accessors for vals EG for case class CreditReject(req: + * MarketOrderRequest, client: ActorRef) + * def req: + * com.sksamuel.scoverage.samples.MarketOrderRequest + * def client: + * akka.actor.ActorRef */ case d: DefDef if d.symbol.isCaseAccessor => tree @@ -652,34 +651,35 @@ class ScoverageInstrumentationComponent( /** Stable getters are methods generated for access to a top level val. * Should be ignored as this is compiler generated code. * - * Eg - * def MaxCredit: scala.math.BigDecimal = CreditEngine.this.MaxCredit - * def alwaysTrue: String = InstrumentLoader.this.alwaysTrue + * Eg def MaxCredit: scala.math.BigDecimal = + * CreditEngine.this.MaxCredit def alwaysTrue: + * String = InstrumentLoader.this.alwaysTrue */ case d: DefDef if d.symbol.isStable && d.symbol.isGetter => tree - /** Accessors are auto generated setters and getters. - * Eg - * private def _clientName: String = - * def cancellable: akka.actor.Cancellable = PriceEngine.this.cancellable - * def cancellable_=(x$1: akka.actor.Cancellable): Unit = PriceEngine.this.cancellable = x$1 + /** Accessors are auto generated setters and getters. Eg + * private def _clientName: String = def cancellable: + * akka.actor.Cancellable = PriceEngine.this.cancellable def + * cancellable_=(x$1: akka.actor.Cancellable): Unit = + * PriceEngine.this.cancellable = x$1 */ case d: DefDef if d.symbol.isAccessor => tree // was `abstract' for members | trait is virtual case d: DefDef if tree.symbol.isDeferred => tree - /** eg - * override def hashCode(): Int - * def copy$default$1: com.sksamuel.scoverage.samples.MarketOrderRequest - * def $default$3: Option[org.joda.time.LocalDate] @scala.annotation.unchecked.uncheckedVariance = scala.None + /** eg override def hashCode(): Int def + * copy$default$1: com.sksamuel.scoverage.samples.MarketOrderRequest + * def $default$3: Option[org.joda.time.LocalDate] + * @scala.annotation.unchecked.uncheckedVariance = scala.None */ case d: DefDef if d.symbol.isSynthetic => tree /** Match all remaining def definitions * - * If the return type is not specified explicitly (i.e. is meant to be inferred), - * this is expressed by having `tpt` set to `TypeTree()` (but not to an `EmptyTree`!). + * If the return type is not specified explicitly (i.e. is meant to be + * inferred), this is expressed by having `tpt` set to `TypeTree()` + * (but not to an `EmptyTree`!). */ case d: DefDef => updateLocation(d) @@ -755,8 +755,8 @@ class ScoverageInstrumentationComponent( m } - /** match with syntax `New(tpt)`. - * This AST node corresponds to the following Scala code: + /** match with syntax `New(tpt)`. This AST node corresponds to the + * following Scala code: * * `new` T * @@ -770,13 +770,9 @@ class ScoverageInstrumentationComponent( * * is the following code: * - * Apply( - * Apply( - * TypeApply( - * Select(New(TypeTree(typeOf[Example])), nme.CONSTRUCTOR) - * TypeTree(typeOf[Int])), - * List(Literal(Constant(2)))), - * List(Literal(Constant(3)))) + * Apply( Apply( TypeApply( Select(New(TypeTree(typeOf[Example])), + * nme.CONSTRUCTOR) TypeTree(typeOf[Int])), + * List(Literal(Constant(2)))), List(Literal(Constant(3)))) */ case n: New => n @@ -792,21 +788,22 @@ class ScoverageInstrumentationComponent( case r: Return => treeCopy.Return(r, transform(r.expr)) - /** pattern match with syntax `Select(qual, name)`. - * This AST node corresponds to the following Scala code: + /** pattern match with syntax `Select(qual, name)`. This AST node + * corresponds to the following Scala code: * * qualifier.selector * - * Should only be used with `qualifier` nodes which are terms, i.e. which have `isTerm` returning `true`. - * Otherwise `SelectFromTypeTree` should be used instead. + * Should only be used with `qualifier` nodes which are terms, i.e. + * which have `isTerm` returning `true`. Otherwise `SelectFromTypeTree` + * should be used instead. * - * foo.Bar // represented as Select(Ident(), ) - * Foo#Bar // represented as SelectFromTypeTree(Ident(), ) + * foo.Bar // represented as Select(Ident(), ) Foo#Bar // + * represented as SelectFromTypeTree(Ident(), ) */ case s: Select if location == null => tree - /** I think lazy selects are the LHS of a lazy assign. - * todo confirm we can ignore + /** I think lazy selects are the LHS of a lazy assign. todo confirm we + * can ignore */ case s: Select if s.symbol.isLazy => tree @@ -850,12 +847,12 @@ class ScoverageInstrumentationComponent( case _: TypeTree => super.transform(tree) - /** We can ignore lazy val defs as they are implemented by a generated defdef + /** We can ignore lazy val defs as they are implemented by a generated + * defdef */ case v: ValDef if v.symbol.isLazy => tree - /** val default: A1 => B1 = - * val x1: Any = _ + /** val default: A1 => B1 = val x1: Any = _ */ case v: ValDef if v.symbol.isSynthetic => tree @@ -877,14 +874,14 @@ class ScoverageInstrumentationComponent( /** This AST node corresponds to any of the following Scala code: * - * mods `val` name: tpt = rhs - * mods `var` name: tpt = rhs - * mods name: tpt = rhs // in signatures of function and method definitions - * self: Bar => // self-types + * mods `val` name: tpt = rhs mods `var` name: tpt = rhs mods name: tpt + * = rhs // in signatures of function and method definitions self: Bar + * => // self-types * * For user defined value statements, we will instrument the RHS. * - * This includes top level non-lazy vals. Lazy vals are generated as stable defs. + * This includes top level non-lazy vals. Lazy vals are generated as + * stable defs. */ case v: ValDef => updateLocation(v) diff --git a/scalac-scoverage-plugin/src/main/scala/scoverage/report/BaseReportWriter.scala b/scalac-scoverage-plugin/src/main/scala/scoverage/report/BaseReportWriter.scala index 158c3e51..587bea96 100644 --- a/scalac-scoverage-plugin/src/main/scala/scoverage/report/BaseReportWriter.scala +++ b/scalac-scoverage-plugin/src/main/scala/scoverage/report/BaseReportWriter.scala @@ -8,10 +8,12 @@ class BaseReportWriter(sourceDirectories: Seq[File], outputDir: File) { private val formattedSourcePaths: Seq[String] = sourceDirectories filter (_.isDirectory) map (_.getCanonicalPath + File.separator) - /** Converts absolute path to relative one if any of the source directories is it's parent. - * If there is no parent directory, the path is returned unchanged (absolute). + /** Converts absolute path to relative one if any of the source directories is + * it's parent. If there is no parent directory, the path is returned + * unchanged (absolute). * - * @param src absolute file path in canonical form + * @param src + * absolute file path in canonical form */ def relativeSource(src: String): String = relativeSource(src, formattedSourcePaths) diff --git a/scalac-scoverage-plugin/src/main/scala/scoverage/report/ScoverageXmlWriter.scala b/scalac-scoverage-plugin/src/main/scala/scoverage/report/ScoverageXmlWriter.scala index 7f1f8208..307add40 100644 --- a/scalac-scoverage-plugin/src/main/scala/scoverage/report/ScoverageXmlWriter.scala +++ b/scalac-scoverage-plugin/src/main/scala/scoverage/report/ScoverageXmlWriter.scala @@ -107,16 +107,18 @@ class ScoverageXmlWriter( } - /** This method ensures that the output String has only - * valid XML unicode characters as specified by the - * XML 1.0 standard. For reference, please see + /** This method ensures that the output String has only valid XML unicode + * characters as specified by the XML 1.0 standard. For reference, please see * the - * standard. This method will return an empty - * String if the input is null or empty. + * standard. This method will return an empty String if the input is null + * or empty. * - * @param in The String whose non-valid characters we want to remove. - * @return The in String, stripped of non-valid characters. - * @see http://blog.mark-mclaren.info/2007/02/invalid-xml-characters-when-valid-utf8_5873.html + * @param in + * The String whose non-valid characters we want to remove. + * @return + * The in String, stripped of non-valid characters. + * @see + * http://blog.mark-mclaren.info/2007/02/invalid-xml-characters-when-valid-utf8_5873.html */ def escape(in: String): String = { val out = new StringBuilder() diff --git a/scalac-scoverage-plugin/src/test/resources/scoverage/forHtmlWriter/src/main/scala/ClassContainingHtml.scala b/scalac-scoverage-plugin/src/test/resources/scoverage/forHtmlWriter/src/main/scala/ClassContainingHtml.scala index 49ce9185..ad963f3c 100644 --- a/scalac-scoverage-plugin/src/test/resources/scoverage/forHtmlWriter/src/main/scala/ClassContainingHtml.scala +++ b/scalac-scoverage-plugin/src/test/resources/scoverage/forHtmlWriter/src/main/scala/ClassContainingHtml.scala @@ -1,5 +1,5 @@ -package coverage.sample - -class ClassContainingHtml { - def some_html =
HTML content
-} +package coverage.sample + +class ClassContainingHtml { + def some_html =
HTML content
+} diff --git a/scalac-scoverage-plugin/src/test/scala/scoverage/PluginCoverageTest.scala b/scalac-scoverage-plugin/src/test/scala/scoverage/PluginCoverageTest.scala index 481747f4..7035a583 100644 --- a/scalac-scoverage-plugin/src/test/scala/scoverage/PluginCoverageTest.scala +++ b/scalac-scoverage-plugin/src/test/scala/scoverage/PluginCoverageTest.scala @@ -84,8 +84,8 @@ class PluginCoverageTest assert(!compiler.reporter.hasErrors) assert(!compiler.reporter.hasWarnings) - /** should have the following statements instrumented: - * the selector, clause 1 + /** should have the following statements instrumented: the selector, clause + * 1 */ compiler.assertNMeasuredStatements(2) } @@ -101,8 +101,8 @@ class PluginCoverageTest assert(!compiler.reporter.hasErrors) assert(!compiler.reporter.hasWarnings) - /** should have the following statements instrumented: - * the selector, guard 1, clause 1, guard 2, clause 2, clause 3 + /** should have the following statements instrumented: the selector, guard + * 1, clause 1, guard 2, clause 2, clause 3 */ compiler.assertNMeasuredStatements(6) } diff --git a/scalac-scoverage-runtime/js/src/main/scala/scalajssupport/FileWriter.scala b/scalac-scoverage-runtime/js/src/main/scala/scalajssupport/FileWriter.scala index 04dde5a7..84fe5dcf 100644 --- a/scalac-scoverage-runtime/js/src/main/scala/scalajssupport/FileWriter.scala +++ b/scalac-scoverage-runtime/js/src/main/scala/scalajssupport/FileWriter.scala @@ -1,6 +1,7 @@ package scalajssupport -/** Emulates a subset of the java.io.FileWriter API required for scoverage to work. +/** Emulates a subset of the java.io.FileWriter API required for scoverage to + * work. */ class FileWriter(file: File, append: Boolean) { def this(file: File) = this(file, false) diff --git a/scalac-scoverage-runtime/js/src/main/scala/scalajssupport/Source.scala b/scalac-scoverage-runtime/js/src/main/scala/scalajssupport/Source.scala index 13f018e6..ab4f7b5e 100644 --- a/scalac-scoverage-runtime/js/src/main/scala/scalajssupport/Source.scala +++ b/scalac-scoverage-runtime/js/src/main/scala/scalajssupport/Source.scala @@ -2,8 +2,8 @@ package scalajssupport import scala.io.{Source => OrigSource} -/** This implementation of Source loads the whole file in memory, which is not really efficient, but - * it is not a problem for scoverage operations. +/** This implementation of Source loads the whole file in memory, which is not + * really efficient, but it is not a problem for scoverage operations. */ object Source { def fromFile(file: File) = { diff --git a/scalac-scoverage-runtime/shared/src/main/scala/scoverage/Invoker.scala b/scalac-scoverage-runtime/shared/src/main/scala/scoverage/Invoker.scala index 482749a0..20c4eacd 100644 --- a/scalac-scoverage-runtime/shared/src/main/scala/scoverage/Invoker.scala +++ b/scalac-scoverage-runtime/shared/src/main/scala/scoverage/Invoker.scala @@ -19,19 +19,21 @@ object Invoker { private val dataDirToIds = ThreadSafeMap.empty[String, ThreadSafeMap[Int, Any]] - /** We record that the given id has been invoked by appending its id to the coverage - * data file. + /** We record that the given id has been invoked by appending its id to the + * coverage data file. * - * This will happen concurrently on as many threads as the application is using, - * so we use one file per thread, named for the thread id. + * This will happen concurrently on as many threads as the application is + * using, so we use one file per thread, named for the thread id. * - * This method is not thread-safe if the threads are in different JVMs, because - * the thread IDs may collide. - * You may not use `scoverage` on multiple processes in parallel without risking - * corruption of the measurement file. + * This method is not thread-safe if the threads are in different JVMs, + * because the thread IDs may collide. You may not use `scoverage` on + * multiple processes in parallel without risking corruption of the + * measurement file. * - * @param id the id of the statement that was invoked - * @param dataDir the directory where the measurement data is held + * @param id + * the id of the statement that was invoked + * @param dataDir + * the directory where the measurement data is held */ def invoked( id: Int,