-
Notifications
You must be signed in to change notification settings - Fork 396
Enable scalafmt on library/. #2701
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
Conversation
Instead of the slightly confusing `@native` and `= native`. To do this we `import scala.scalajs.js` even though we are in that very package.
Only in `library/`.
Review by @gzm0 |
Refer to this link for build results (access rights to CI server needed): https://scala-webapps.epfl.ch/jenkins/job/scalajs-pr/3580/ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Big proponent of this!
I'm assuming you want to do this for the whole codebase, but just roll it out incrementally (proponent of that as well :))
if (thiz.equals(anotherString)) 0 | ||
else if ((thiz.asInstanceOf[js.Dynamic] < | ||
anotherString.asInstanceOf[js.Dynamic]).asInstanceOf[Boolean]) -1 | ||
else if ((dynThiz < dynOther).asInstanceOf[Boolean]) -1 | ||
else 1 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did you verify that this can still be inlined the same way?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I haven't verified. I'm quite certain it can, because val dynThiz
and val dynOther
are pure aliases, which will always be aliased away as LocalDef
s.
@@ -94,16 +94,14 @@ object JSNumberOps { | |||
@deprecated( | |||
"A Long is converted to Double to perform JavaScript " + | |||
"operations. This is almost certainly not what you want. " + | |||
"Use `.toDouble` explicitly if you need it.", | |||
"0.6.0") | |||
"Use `.toDouble` explicitly if you need it.", "0.6.0") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wrong commit?
implicit def enableJSNumberOps(x: Long): JSNumberOps = | ||
x.toDouble.asInstanceOf[JSNumberOps] | ||
|
||
@deprecated( | ||
"A Long is converted to Double to perform JavaScript " + | ||
"operations. This is almost certainly not what you want. " + | ||
"Use `.toDouble` explicitly if you need it.", | ||
"0.6.0") | ||
"Use `.toDouble` explicitly if you need it.", "0.6.0") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wrong commit?
@@ -199,6 +200,7 @@ final class UndefOrOps[A](val self: UndefOr[A]) extends AnyVal { | |||
@inline final def collect[B](pf: PartialFunction[A, B]): UndefOr[B] = | |||
if (isEmpty) undefined | |||
else pf.applyOrElse(this.forceGet, (_: A) => undefined).asInstanceOf[UndefOr[B]] | |||
// scalafmt: { maxColumn = 80 } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would avoid these kind of smaller, local format changes. While for that particular piece of code, it'll probably indeed look nicer, it feels like the maintenance overhead is substantial, for not a lot of gain. (js.Function files are different there IMO).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I made a pretty honest trial at fitting this under 80 characters, and it ended up much much worse. That's why a soft limit is important: it is important to be able to escape the length limit if the alternative is significantly worse.
@field @getter @setter | ||
@field | ||
@getter | ||
@setter |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wrong commit?
@@ -80,7 +80,7 @@ object Bits { | |||
*/ | |||
def numberHashCode(value: Double): Int = { | |||
val iv = rawToInt(value) | |||
if (iv == value && 1.0/value != Double.NegativeInfinity) iv | |||
if (iv == value && 1.0 / value != Double.NegativeInfinity) iv |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wrong commit?
@@ -46,7 +46,7 @@ private[runtime] object RuntimeString { | |||
|
|||
def codePointAt(thiz: String, index: Int): Int = { | |||
val high = thiz.charAt(index) | |||
if (index+1 < thiz.length) { | |||
if (index + 1 < thiz.length) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wrong commit?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No this is an undesirable (but tolerated) change. Arithmetic operations on the side of a comparison operator should not have spaces around it, to highlight the relative priority. This is filed as https://github.com/olafurpg/scalafmt/issues/511
NativeJSString.fromCharCode( | ||
(offsetCp >> 10) | 0xd800, (offsetCp & 0x3ff) | 0xdc00) | ||
NativeJSString | ||
.fromCharCode((offsetCp >> 10) | 0xd800, (offsetCp & 0x3ff) | 0xdc00) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wrong commit?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, this is an undesirable (but tolerated) change. It should be as before: wrapping the arguments should get higher precedence than a "select chain" if the select chain consists of an only select. This is filed as https://github.com/olafurpg/scalafmt/issues/503
@@ -19,8 +19,7 @@ class UndefinedBehaviorError(message: String, cause: Throwable) | |||
def this(cause: Throwable) = | |||
this( | |||
"An undefined behavior was detected" + | |||
(if (cause == null) "" else ": " + cause.getMessage), | |||
cause) | |||
(if (cause == null) "" else ": " + cause.getMessage), cause) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wrong commit?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, this is an undesirable (but tolerated) change. An argument spanning two lines or more should not share one of its lines with another argument. This is filed as https://github.com/olafurpg/scalafmt/issues/502
@@ -187,7 +187,7 @@ package object runtime { | |||
if (f0 / twoPowFbits >= 2) { | |||
//val e = e0 + 1.0 // not used | |||
val f = 1.0 | |||
if (e0 > bias-1) { // === (e > bias) because e0 is whole | |||
if (e0 > bias - 1) { // === (e > bias) because e0 is whole |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wrong commit?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The long-term plan is definitely to enable this on the whole codebase. However, without soft line length limit I am not super confident :s
@@ -46,7 +46,7 @@ private[runtime] object RuntimeString { | |||
|
|||
def codePointAt(thiz: String, index: Int): Int = { | |||
val high = thiz.charAt(index) | |||
if (index+1 < thiz.length) { | |||
if (index + 1 < thiz.length) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No this is an undesirable (but tolerated) change. Arithmetic operations on the side of a comparison operator should not have spaces around it, to highlight the relative priority. This is filed as https://github.com/olafurpg/scalafmt/issues/511
NativeJSString.fromCharCode( | ||
(offsetCp >> 10) | 0xd800, (offsetCp & 0x3ff) | 0xdc00) | ||
NativeJSString | ||
.fromCharCode((offsetCp >> 10) | 0xd800, (offsetCp & 0x3ff) | 0xdc00) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, this is an undesirable (but tolerated) change. It should be as before: wrapping the arguments should get higher precedence than a "select chain" if the select chain consists of an only select. This is filed as https://github.com/olafurpg/scalafmt/issues/503
@@ -19,8 +19,7 @@ class UndefinedBehaviorError(message: String, cause: Throwable) | |||
def this(cause: Throwable) = | |||
this( | |||
"An undefined behavior was detected" + | |||
(if (cause == null) "" else ": " + cause.getMessage), | |||
cause) | |||
(if (cause == null) "" else ": " + cause.getMessage), cause) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, this is an undesirable (but tolerated) change. An argument spanning two lines or more should not share one of its lines with another argument. This is filed as https://github.com/olafurpg/scalafmt/issues/502
@@ -52,6 +53,7 @@ private[niocharset] object UTF_8 // scalastyle:ignore | |||
// > 11110111 | |||
-1, -1, -1, -1, -1, -1, -1, -1 | |||
) | |||
// format: on |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, this is perfectly warranted (hence no comment referencing a scalafmt issue).
Repr <: TypedArray[T, Repr]]( | ||
array: Repr, dest: scala.Array[T]): scala.Array[T] = { | ||
Repr <: TypedArray[T, Repr]](array: Repr, | ||
dest: scala.Array[T]): scala.Array[T] = { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, this is an undesirable (but barely tolerated) change: if the type argument list spans more than one line, it should not share a line with term parameters. The term parameters should start on their own line. This is filed as https://github.com/olafurpg/scalafmt/issues/504
val high = (value >>> 32).toInt | ||
val low = value.toInt | ||
dataView.setInt32(index + (if (littleEndian) 4 else 0), high, littleEndian) | ||
dataView.setInt32(index + (if (littleEndian) 0 else 4), low, littleEndian) | ||
dataView.setInt32(index + (if (littleEndian) 0 else 4), low, littleEndian) | ||
// scalafmt: { maxColumn = 80 } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, the formatting change is in the wrong commit.
The line length limit change is a poor man's implementation of the soft limit at 80 characters. The wrapping to stay under 80 characters is significantly worse than going a few characters over the limit. The soft limit problem is filed as https://github.com/olafurpg/scalafmt/issues/232, although it has been closed as Won't fix.
@field @getter @setter | ||
@field | ||
@getter | ||
@setter |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is an undesirable change. scalafmt 0.5.2 will have an option not to affect the line grouping of annotations, IIUC.
@@ -199,6 +200,7 @@ final class UndefOrOps[A](val self: UndefOr[A]) extends AnyVal { | |||
@inline final def collect[B](pf: PartialFunction[A, B]): UndefOr[B] = | |||
if (isEmpty) undefined | |||
else pf.applyOrElse(this.forceGet, (_: A) => undefined).asInstanceOf[UndefOr[B]] | |||
// scalafmt: { maxColumn = 80 } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I made a pretty honest trial at fitting this under 80 characters, and it ended up much much worse. That's why a soft limit is important: it is important to be able to escape the length limit if the alternative is significantly worse.
if (thiz.equals(anotherString)) 0 | ||
else if ((thiz.asInstanceOf[js.Dynamic] < | ||
anotherString.asInstanceOf[js.Dynamic]).asInstanceOf[Boolean]) -1 | ||
else if ((dynThiz < dynOther).asInstanceOf[Boolean]) -1 | ||
else 1 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I haven't verified. I'm quite certain it can, because val dynThiz
and val dynOther
are pure aliases, which will always be aliased away as LocalDef
s.
OK, I see. In that case, can you add this to the commit description so it is clear why formatting changes in two different commits. Also, it might be a good idea to link the issues in the commit. |
And for now, I'm fine with leaving the AdHoc soft-line length settings. |
Closing as this would probably have to be redone from scratch at this point. |
No description provided.