Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
  • May 26 2017 22:35
    olafurpg synchronize #947
  • May 26 2017 22:23
    olafurpg synchronize #947
  • May 26 2017 22:22
    olafurpg synchronize #947
  • May 26 2017 22:20
    olafurpg opened #947
  • May 26 2017 22:07
    olafurpg commented #943
  • May 26 2017 21:53

    olafurpg on v1.0.0-RC1

    (compare)

  • May 26 2017 21:46

    olafurpg on master

    Upgrade to non-broken metaconfi… Merge pull request #946 from ol… (compare)

  • May 26 2017 21:46
    olafurpg closed #946
  • May 26 2017 21:25
    olafurpg opened #946
  • May 26 2017 14:44

    olafurpg on master

    documentation fix: binPackParen… Merge pull request #945 from na… (compare)

  • May 26 2017 14:44
    olafurpg closed #945
  • May 26 2017 14:43
    olafurpg commented #943
  • May 26 2017 14:39
    olafurpg commented #943
  • May 26 2017 14:03
    pjrt commented #943
  • May 26 2017 13:36
    pjrt commented #943
  • May 26 2017 13:12
    nadavwr opened #945
  • May 25 2017 22:57
    ScalaWilliam commented #943
  • May 25 2017 21:34
    pauldraper commented #890
  • May 25 2017 21:34
    pauldraper commented #890
  • May 25 2017 17:23
    olafurpg commented #943
Eric K Richardson
@ekrich

Is there any possible way to achieve this without doing it all by hand? https://github.com/scala-js/scala-js/blob/master/CODINGSTYLE.md#scaladoc

Basically this is Javadoc style but allowing the first line and aligning one space after the second asterisk. It would be good to allow single line as well.

The beauty of this is that it looks like C and Java comments or just multi-line comments but when you fold the comment in like VSCode or some other editor the first line still shows in the UI.

3 replies
Basically, Scala Native uses scalafmt and has a similar style to Scala.js as Scala Native followed and leveraged off of Scala.js. We are trying to upgrade but running into large diffs. If we could get a few things then we could upgrade and it might be closer for perhaps Scala.js being able to adopt as well. I can't speak for the project but there have been some attempts to try.
Eric K Richardson
@ekrich
It seems that format: off / format: on is not respected inside java/scaladoc for ascii art.
1 reply
Eric K Richardson
@ekrich
Now that Scalafmt can wrap docs, maybe this would be a good idea.
@kitbellew Would that be hard?
Eric K Richardson
@ekrich
Is this still valid - works but not seeing it in the docs.
project.excludeFilters = [
  scalalib/
]
2 replies
Eric K Richardson
@ekrich
@kitbellew Shouldn't something like this be default prior to the format here based on significant whitespace because you need the line after the foreach?
-    times.foreach {
-      case (k, v) =>
-        val key = k.split(":")(1)
-        totalTimes(key) = totalTimes.getOrElse(key, 0L) + v
-        totalThreads(key) = totalThreads.getOrElse(key, 0L) + 1
+    times.foreach { case (k, v) =>
+      val key = k.split(":")(1)
+      totalTimes(key) = totalTimes.getOrElse(key, 0L) + v
+      totalThreads(key) = totalThreads.getOrElse(key, 0L) + 1
13 replies
Eric K Richardson
@ekrich
I noticed that implicit a => after a higher order function with a control block is fine in Scala 3 but the case needs to be on the next line. So it seems to me the multilineCaseOnly may be good choice.
Eric K Richardson
@ekrich
The above is me answering on mobile - you can't keep it in the same thread.
heksenlied
@heksenlied:matrix.org
[m]
Is it possible to do rewrite to Scala 3 syntax under Scala213Source3 dialect?
Albert Meltzer
@kitbellew
@heksenlied:matrix.org no, most of the rewrites require actual scala 3 and optional braces support.
Eric K Richardson
@ekrich
@kitbellew I followed up over here because it has more to it than just what I was talking to you about. :point_up: May 25, 2021 7:36 AM
Ugo Matrangolo
@umatrangolo

Hi. I’m trying to align constructor arguments for a class like:

case class Foo(
  firstParam: Int,
  secondParam: String,
  thirdParam: Boolean 
)

to something where all type names are aligned vertically.

Reading the documentation looks like I have to define a:

align.tokens.add = [ { code = ":", owner = " ??? " }]

Can’ t find the correct owner bit tough. Sticking this into AST explorer looks like
I have to use Term.Param that works but works also for everything else outside
classes.

How can I tell Scalafmt to apply this formatting rule only to terms inside a case class. Tried

Defn.Class.Ctor.Primary.Term.Param

wout success. I presume is not the right way to nest AST node names.

2 replies
Eric K Richardson
@ekrich
@kitbellew Thanks for the help. I think this is good PR - scala-native/scala-native#2315
Eric K Richardson
@ekrich
@tgodzik Did we get all the libraries ported that are needed for Scala Native scalafmt? We did the ones for metaconfig, looks like scalameta is ready? Any other blockers?
jayzhee
@jayzhee
Does ScalaFMT support Scala 3? I have my configuration version set to 3.0.0-RC3, but attempting to run sbt scalafmtAll will show a bunch of errors when I use Scala 3 features like significant indentation, or transparent inline defs
jayzhee
@jayzhee
For example (this was taken from the scala forums): https://scastie.scala-lang.org/Er8YVwOOQo2z5WyCDMhTxg
I have this in a package called newtype, and in a file called package.scala.
This shows the following messages when running sbt scalafmtAll:
[error] scala/scala3-test/src/main/scala/newtype/package.scala:5: error: expected class or object definition identifier
[error] open class NewType[A]:
[error] ^: scala/scala3-test/src/main/scala/newtype/package.scala
[error] (Compile / scalafmt) scala/newtype/package.scala:5: error: expected class or object definition identifier
[error] open class NewType[A]:
[error] ^: scala/scala3-test/src/main/scala/newtype/package.scala
[error] Total time: 2 s, completed May 28, 2021 2:15:09 AM
Fabrizio Colonna
@ColOfAbRiX
try by adding runner.dialect = scala3
jayzhee
@jayzhee
That did it, thanks a bunch!!
vimalaguti
@vimalaguti

Hi, couldn't find in the doc, in the method def do you know how to align the parameters to the parentheses?

def wuff(
        a: Int,
        b: Int
        )

in intellij formatter it's called "indent first parameter if on new line" + "align when multiline"

5 replies
Eric K Richardson
@ekrich

We don't really like what happens when an if ( some long logic) {wraps with the current default so we tried danglingParentheses.ctrlSite = false but then we think maybe the closing ) { should be on the next line because this is hard to read.

if (host.indexOf(':') != -1 && host.indexOf(']') == -1 &&
  host.indexOf('[') == -1) {
  hostVar = "[" + host + "]"
}

It is hard to tell the if continuation from the statement inside the body. Any suggestions? How is this suppose to look with the Scala 3 then?

9 replies
Eric K Richardson
@ekrich
I don't see any ident for control sites.
Eric K Richardson
@ekrich
Eric K Richardson
@ekrich
-      if ((fromIndex < 0) || (fromIndex >= _size) || (toIndex > size())
-          || (toIndex < fromIndex)) {
+      if (
+        (fromIndex < 0) || (fromIndex >= _size) || (toIndex > size())
+        || (toIndex < fromIndex)
+      ) {
This just seems counter to anything seen in the wild.
Eric K Richardson
@ekrich
We are very close with exception of the default wrapping the if conditions on the next line which looks very strange. https://github.com/scala-native/scala-native/pull/2315#issuecomment-851529817
Eric K Richardson
@ekrich
@kitbellew Should I put in a feature request or issue where this can be discussed? I sure would like to be able to complete the transition for version 3. We are very close.
2 replies
Eric K Richardson
@ekrich
@kitbellew Thanks you for your hard work on scalafmt. As I say in the feature request scalameta/scalafmt#2573, we are pretty excited to upgrade and to be ready for Scala 3 as well. cc @olafurpg
Eric K Richardson
@ekrich

I tried out the new version - was trying snapshot too and the change reduced the lines in the diff by over 1000. This looks like we get the 4 spaces as well as the 2 spaces via line continuation due to wrapping.

indent.ctrlSite = 4
danglingParentheses.ctrlSite = false
       if (host != null) {
-        if (host.indexOf(':') != -1 && host.indexOf(']') == -1 && host.indexOf(
-              '[') == -1) {
+        if (host.indexOf(':') != -1 && host
+              .indexOf(']') == -1 && host.indexOf('[') == -1) {
           hostVar = "[" + host + "]"

Most if the time it is just 4 but in some weird wrap cases it becomes 6. I think purposely wrapping can fix it. And it does.

        if (host.indexOf(':') != -1 &&
            host.indexOf(']') == -1 &&
            host.indexOf('[') == -1) {
          hostVar = "[" + host + "]"
        }

Very cool - pretty sure with a few changes to code we will be able to upgrade - thanks so much.

4 replies
Eric K Richardson
@ekrich
Here is an example:
       if (!((ch >= 'a' && ch <= 'z') || (ch >= 'A' && ch <= 'Z') ||
-          (ch >= '0' && ch <= '9') || legal.indexOf(ch) > -1)) {
+            (ch >= '0' && ch <= '9') || legal.indexOf(ch) > -1)) {
3 replies
Eric K Richardson
@ekrich
I must be doing something wrong here - it wraps the example.
@@ -50,11 +49,8 @@
   /** Returns this value bit-shifted right by the specified number of bits,
-   *         filling the new left bits with zeroes.
-   * @example {{{ 21 >>> 3 == 2 // in binary: 010101 >>> 3 == 010 }}}
-   * @example
-   * {{{
-   * 4294967275 >>> 3 == 536870909
-   * // in binary: 
-   * 11111111 11111111 11111111 11101011 >>> 3 ==
-   * 00011111 11111111 11111111 11111101
-   * }}}
+   *  filling the new left bits with zeroes.
+   *  @example
+   *    {{{21 >>> 3 == 2 // in binary: 010101 >>> 3 == 010}}}
+   *  @example
+   *    {{{ 4294967275 >>> 3 == 536870909 // in binary: 11111111 11111111
+   *    11111111 11101011 >>> 3 == 00011111 11111111 11111111 11111101 }}}
    */
3 replies
charego
@charego

Hi everybody. I have a long function with two parameter groups:

private def myLongFunctionName(param1: Option[String], param2: Seq[Int])(f: Long => Boolean): Seq[String] = {
  ...
}

Is it possible to configure scalafmt to prefer breaking on the first parameter group?

private def myLongFunctionName(
  param1: Option[String],
  param2: Seq[Int]
)(f: Long => Boolean): Seq[String] = {
  ...
}
2 replies
Saskia Gennrich
@pektinasen
Hello, is there a way to align the <- and = in a for comprehension.
like this:
    for {
      aLongName <- Future(1)
      short      = aLongName + 1
      _         <- println(short))
    } yield ()
Saskia Gennrich
@pektinasen
I was playing around with {code = "<-", owner = "Term.ForYield"}, in align tokens, but have to admit I don't really understand how align.tokens and owner works.
4 replies
Eric K Richardson
@ekrich
@kitbellew I just wanted to let you know that I was able to work around any formats where it was not obvious one the indent by just doing some intentional wrapping. I put the opening ( in a long if condition on a new line therefore making the first indent 4 and then the next 6 for example. Just waiting on some reviews but it looks like the upgrade for Scala Native will happen - I really like some of the new defaults - very easy to read - we have on 4 non-defaults and a few other misc things. I am super excited. Super great work you and others have been doing! :rocket:
Albert Meltzer
@kitbellew
glad you're finally at the finish line
Wim Verreydt
@wimve

Hi, it seems that sbt-scalafmt is no longer available on maven central? https://repo1.maven.org/maven2/org/scalameta/sbt-scalafmt/2.4.2/
It is still in the search index though (probably explaining the geen maven badge on the installation documentation page) https://search.maven.org/artifact/org.scalameta/sbt-scalafmt/2.4.2/jar

What repository should I use to import this?

Wim Verreydt
@wimve
Tnx for the info! In the end, it tuned out that I was running into an SBT issue https://github.com/sbt/sbt/issues/5263/. The fmt plugin import was configured correctly after all but the exception made it look like it was searching in the wrong place.
Felix Bruckmeier
@felixbr

Hi,

Is Scala3 using already supported?

I've tried to replace implicit with using and the compiler is happy but scalafmt (3.0.0-RC5) isn't:

private def fetchEntry(
  vertical: Vertical
)(using db: DBConnections) = ...

// OR

private def fetchEntry(
  vertical: Vertical
)(using DBConnections) = ...

In both cases I get:

error:   : expected but identifier found
)(using db: DBConnections) =
        ^:

If you need more information I can also open an issue but I thought it may be a known problem (or me being dumb) 🙂

Fabio Labella
@SystemFw
@felixbr try runner.dialect = scala3
Felix Bruckmeier
@felixbr
@SystemFw Thanks, that does the trick 👍
Eric K Richardson
@ekrich
WIll using {{{ and }}} keep scalafmt from messing with html? If so, will the html still render ok?
1 reply
Tag '@throws' must be followed by a symbol name
5 replies
Seems like the current wrapping cause scaladoc errors?
Eric K Richardson
@ekrich
I just put in an issue for the second problem as the first is a known issue. scalameta/scalafmt#2609
Eric K Richardson
@ekrich
Does runner.dialect work on cross projects with Scala 2 and 3 code?
Albert Meltzer
@kitbellew
no. you need to use fileOverride