Skip to content
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

Formatting: enable all redundantXxx parameters #4610

Merged
merged 1 commit into from
Nov 27, 2024
Merged
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
8 changes: 5 additions & 3 deletions .scalafmt.conf
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ align {
stripMargin = true
}
newlines {
avoidForSimpleOverflow = [punct, slc, tooLong]
avoidForSimpleOverflow = all
ignoreInSyntax = false
source = fold
}
Expand All @@ -40,8 +40,10 @@ rewrite {
]
}
redundantBraces {
ifElseExpressions = true
stringInterpolation = true
preset = all
}
redundantParens {
preset = all
}
sortModifiers.preset = styleGuide
trailingCommas.style = "always"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ object Cli extends CliUtils {
}

private val isNative: Boolean = isScalaNative ||
("true" == System.getProperty("scalafmt.native-image", "false"))
"true" == System.getProperty("scalafmt.native-image", "false")

private def getProposedConfigVersion(options: CliOptions): String =
s"version = $stableVersion"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ object TermDisplay extends TermUtils {
assert(decile <= 10)

fraction.fold(" " * 6)(p => f"${100.0 * p}%5.1f%%") + " [" +
("#" * decile) + (" " * (10 - decile)) + "] " + downloaded +
"#" * decile + " " * (10 - decile) + "] " + downloaded +
" source files formatted"
}
}
Expand Down Expand Up @@ -193,7 +193,7 @@ object TermDisplay extends TermUtils {

val info = infos.remove(url)

if (success) doneQueue += (url -> update0(info))
if (success) doneQueue += url -> update0(info)
}

if (fallbackMode && success) {
Expand Down Expand Up @@ -229,15 +229,15 @@ object TermDisplay extends TermUtils {

val extra0 =
if (extra.length > baseExtraWidth) extra
.take((baseExtraWidth.max(extra.length - overflow)) - 1) + "…"
.take(baseExtraWidth.max(extra.length - overflow) - 1) + "…"
else extra

val total0 = url.length + 1 + extra0.length
val overflow0 = total0 - width + 1

val url0 =
if (total0 >= width) url.take(
((width - baseExtraWidth - 1).max(url.length - overflow0)) - 1,
(width - baseExtraWidth - 1).max(url.length - overflow0) - 1,
) + "…"
else url

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ private class BestFirstSearch private (range: Set[Range])(implicit
depth: Int,
isOpt: Boolean,
): Option[Option[State]] = {
val key = (start.indentation & 0xffL) | (start.column & 0xffffffL) << 8 |
val key = start.indentation & 0xffL | (start.column & 0xffffffL) << 8 |
(start.depth & 0xffffffffL) << 32
def orElse =
if (isOpt) Some(None) // we wouldn't recurse unless the span was large
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -656,7 +656,7 @@ class FormatOps(
infixes.foreach { ia =>
val cost = maxPrecedence - ia.precedence
if (cost < minCost) {
out += (getMidInfixToken(ia) -> cost)
out += getMidInfixToken(ia) -> cost
minCost = cost
}
}
Expand Down Expand Up @@ -1973,7 +1973,7 @@ class FormatOps(
// https://dotty.epfl.ch/docs/internals/syntax.html
(tf.paramClause match { // LambdaStart
case tpc @ Term.ParamClause(tp :: Nil, mod) =>
(mod.isEmpty && tp.mods.isEmpty && tp.decltpe.isEmpty) ||
mod.isEmpty && tp.mods.isEmpty && tp.decltpe.isEmpty ||
isEnclosedWithinParens(tpc)
case _ => true // multiple params are always in parens
}) =>
Expand All @@ -2000,7 +2000,7 @@ class FormatOps(
okRightBrace: => Boolean,
) =
if (
(nft.right.is[T.LeftBrace] && (nft.meta.rightOwner eq tb)) ||
nft.right.is[T.LeftBrace] && (nft.meta.rightOwner eq tb) ||
tb.pos.start > nft.right.start
) None
else Some(new OptionalBracesRegion {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ class FormatTokens(leftTok2tok: Map[TokenHash, Int])(val arr: Array[FT])
def apply(ft: FT, off: Int): FT = at(ft.meta.idx + off)

@inline
def hasNext(ft: FT): Boolean = ft.meta.idx < (arr.length - 1)
def hasNext(ft: FT): Boolean = ft.meta.idx < arr.length - 1
@inline
def hasPrev(ft: FT): Boolean = ft.meta.idx > 0

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1106,9 +1106,9 @@ class Router(formatOps: FormatOps) {
.withIndents(extraOneArgPerLineIndent, indent),
)
else {
val useOneArgPerLineSplit = (notTooManyArgs && align) ||
(handleImplicit &&
style.newlines.notBeforeImplicitParamListModifier)
val useOneArgPerLineSplit = notTooManyArgs && align ||
handleImplicit &&
style.newlines.notBeforeImplicitParamListModifier
val slbSplit =
if (mustDangleForTrailingCommas) Split.ignored
else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ final class State(
def trailing = nextTok.hasBreak // newline after comment
if (nextSplit.isNL) { // newline before comment
val rtext = tok.meta.right.text
if (rtext.length >= (style.maxColumn - nextIndent) || trailing)
if (rtext.length >= style.maxColumn - nextIndent || trailing)
noOverflowPenalties
else overflowPenalties(columnOnCurrentLine)
} else if (style.comments.wrap.eq(Comments.Wrap.trailing) && trailing) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ object TokenOps {
*/
@inline
def hash(token: T): TokenHash = {
val longHash: Long = (token.productPrefix.hashCode.toLong << (62 - 8)) |
(token.start.toLong << (62 - (8 + 28))) | token.end
val longHash: Long = token.productPrefix.hashCode.toLong << 62 - 8 |
token.start.toLong << 62 - (8 + 28) | token.end
longHash
}

Expand Down Expand Up @@ -77,7 +77,7 @@ object TokenOps {

def isSingleLineIfComment(c: T): Boolean = {
val off = c.start
(c.end - off) >= 2 && {
c.end - off >= 2 && {
val chars = c.input.chars
chars(off) == '/' && chars(off + 1) == '/'
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class TokenTraverser(tokens: Tokens, input: Input) {
if (!formatOff) { if (TokenOps.isFormatOff(tok)) formatOff = true }
else if (TokenOps.isFormatOn(tok)) formatOff = false
else excluded += TokenOps.hash(tok)
map += (tok -> i)
map += tok -> i
i += 1
}
if (input.isInstanceOf[Input.Ammonite]) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ object PositionSyntax {
val span = pos.end - pos.start
val caret =
if (span != 0 && pos.startLine == pos.endLine) "^" * span else "^"
(" " * pos.startColumn) + caret
" " * pos.startColumn + caret
}

private def lineContent(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ trait FormatAssertions {
Seq(
e.shortMessage,
linesBeforeCaret.mkString("\n"),
(" " * e.pos.startColumn) + "^", // arrow
" " * e.pos.startColumn + "^", // arrow
linesAfterCaret.mkString("\n"),
"====== full result: ======",
obtained.stripTrailing(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ object Report {
code(
heatmapBar(result.test.style),
raw(result.obtainedHtml),
span("\n" + ("‾" * result.test.style.maxColumn)),
span("\n" + "‾" * result.test.style.maxColumn),
),
),
),
Expand All @@ -36,12 +36,12 @@ object Report {
val v = Math.pow(2, i).toInt
val color = red(v)
span(background := s"rgb(256, $color, $color)", s" $v ")
} :+ span("\n" + ("_" * scalaStyle.maxColumn) + "\n")
} :+ span("\n" + "_" * scalaStyle.maxColumn + "\n")

def red(visits: Int): Int = {
val v = log(visits, 2)
val ratio = v / MaxVisits.toDouble
val result = Math.min(256, 20 + 256 - (ratio * 256)).toInt
val result = Math.min(256, 20 + 256 - ratio * 256).toInt
result
}

Expand Down