Skip to content

Update scalafmt-core to 3.0.3 #369

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .scalafmt.conf
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
version = "2.7.5"
version = "3.0.3"
project.git = true
assumeStandardLibraryStripMargin = true
xmlLiterals.assumeFormatted = true
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
12 changes: 7 additions & 5 deletions scalac-scoverage-plugin/src/main/scala/scoverage/coverage.scala
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ import scala.collection.mutable

import scoverage.DoubleFormat.twoFractionDigits

/** @author Stephen Samuel
/** @author
* Stephen Samuel
*/
case class Coverage()
extends CoverageMetrics
Expand Down Expand Up @@ -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.
*/
Expand Down Expand Up @@ -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.
Expand Down
125 changes: 61 additions & 64 deletions scalac-scoverage-plugin/src/main/scala/scoverage/plugin.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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 =>
Expand Down Expand Up @@ -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))
Expand Down Expand Up @@ -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)
* <stable> <caseaccessor> <accessor> <paramaccessor> def req: com.sksamuel.scoverage.samples.MarketOrderRequest
* <stable> <caseaccessor> <accessor> <paramaccessor> def client: akka.actor.ActorRef
/** Case class accessors for vals EG for case class CreditReject(req:
* MarketOrderRequest, client: ActorRef) <stable> <caseaccessor>
* <accessor> <paramaccessor> def req:
* com.sksamuel.scoverage.samples.MarketOrderRequest <stable>
* <caseaccessor> <accessor> <paramaccessor> def client:
* akka.actor.ActorRef
*/
case d: DefDef if d.symbol.isCaseAccessor => tree

Expand All @@ -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
* <stable> <accessor> def MaxCredit: scala.math.BigDecimal = CreditEngine.this.MaxCredit
* <stable> <accessor> def alwaysTrue: String = InstrumentLoader.this.alwaysTrue
* Eg <stable> <accessor> def MaxCredit: scala.math.BigDecimal =
* CreditEngine.this.MaxCredit <stable> <accessor> 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
* <accessor> private def _clientName: String =
* <accessor> def cancellable: akka.actor.Cancellable = PriceEngine.this.cancellable
* <accessor> def cancellable_=(x$1: akka.actor.Cancellable): Unit = PriceEngine.this.cancellable = x$1
/** Accessors are auto generated setters and getters. Eg <accessor>
* private def _clientName: String = <accessor> def cancellable:
* akka.actor.Cancellable = PriceEngine.this.cancellable <accessor> 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 <synthetic> def hashCode(): Int
* <synthetic> def copy$default$1: com.sksamuel.scoverage.samples.MarketOrderRequest
* <synthetic> def <init>$default$3: Option[org.joda.time.LocalDate] @scala.annotation.unchecked.uncheckedVariance = scala.None
/** eg override <synthetic> def hashCode(): Int <synthetic> def
* copy$default$1: com.sksamuel.scoverage.samples.MarketOrderRequest
* <synthetic> def <init>$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)
Expand Down Expand Up @@ -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
*
Expand All @@ -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

Expand All @@ -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>)
* Foo#Bar // represented as SelectFromTypeTree(Ident(<Foo>), <Bar>)
* foo.Bar // represented as Select(Ident(<foo>), <Bar>) Foo#Bar //
* represented as SelectFromTypeTree(Ident(<Foo>), <Bar>)
*/
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

Expand Down Expand Up @@ -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

/** <synthetic> val default: A1 => B1 =
* <synthetic> val x1: Any = _
/** <synthetic> val default: A1 => B1 = <synthetic> val x1: Any = _
*/
case v: ValDef if v.symbol.isSynthetic => tree

Expand All @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,16 +107,18 @@ class ScoverageXmlWriter(
</package>
}

/** 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
* <a href="http://www.w3.org/TR/2000/REC-xml-20001006#NT-Char">the
* standard</a>. This method will return an empty
* String if the input is null or empty.
* standard</a>. 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()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
package coverage.sample
class ClassContainingHtml {
def some_html = <div>HTML content</div>
}
package coverage.sample

class ClassContainingHtml {
def some_html = <div>HTML content</div>
}
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand All @@ -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)
}
Expand Down
Loading