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
Albert Meltzer
@kitbellew
the documentation does not describe something as specific as _*. the expectation is that you will realize that you are dealing with a rewrite rule, and will find the appropriate sections. also, since such a rewrite is not enabled by default, you must have explicitly enabled it in your configuration file.
heksesang
@heksenlied:matrix.org
[m]
The rewrite rules are very broad, and it's not possible to disable a certain part of the rewrite?
I want rewrite rules, but I don't want that part that breaks my code.
I assume it's related to the new syntax rewrite, which is an all or nothing kinda rewrite.
1 reply
Tynan McAuley
@tymcauley

Hello! I'm trying to figure out how to get scalafmt to avoid changing code that looks like this example: https://github.com/chipsalliance/rocket-chip/blob/185cac830746df9a22465e3267e6d47e01567bc3/src/main/scala/system/Configs.scala#L14-L22

If I use the following example:

class Foo extends Bar(
  new A ++
  new B ++
  new C
)

And a simple .scalafmt.conf:

version = "3.3.1"        
runner.dialect = scala212

Then I get a result like this:

-class Foo extends Bar(
-  new A ++
-  new B ++
-  new C
-)
+class Foo
+    extends Bar(
+      new A ++
+        new B ++
+        new C
+    )

If the extends has to move to a new line, that's okay (although it'd be nice to not do that), but I'd really like to avoid different amounts of indentation on new A vs new B/new C.

From reading the config docs, it seemed to me like setting indentOperator.topLevelOnly = false should align all of the new tokens, but it seems to have no effect on this case. Any clues on which config options I should explore? Thanks for any help!

Oron Port
@soronpo
IMO, scalafmt's style is correct and will prevent you from coding mistakes. E.g., how do you know that you didn't accidentally forget a ++?
Even if there is a way to disable this, I think you should adopt this style, and not resist it.
Tynan McAuley
@tymcauley

It looks like forgetting a ++ is a parse error, so scalafmt won't even run if you don't include that. So in that sense, regardless of what style scalafmt chooses, scalafmt will indeed help prevent that coding mistake :)

However, I don't see how the different indent for the first new vs all subsequent news will help with preventing coding mistakes. If this list is particularly long, then scalafmt wants it to look like this:

class Foo
    extends Bar(
      new A ++
        new B ++
        new C ++
        new D ++
        new E ++
        new F
    )

The difference seems pretty arbitrary to me, especially when compared to how scalafmt handles other infix operators, like in this example from the config docs.

And now, looking more closely at those docs, I see that this was a case of me not using indentOperator properly. This is the scalafmt.conf solution:

indentOperator.topLevelOnly = false
indentOperator.excludeRegex = "^(&&|\\|\\||\\+\\+)$"

I had previously failed to add ++ to the excludeRegex. Once I do that, I get this result, which is much better:

-class Foo extends Bar(
-    new A ++
-    new B ++
-    new C
-  )
+class Foo
+    extends Bar(
+      new A ++
+      new B ++
+      new C
+    )
Albert Meltzer
@kitbellew
@tymcauley binPack.parentConstructors
Tynan McAuley
@tymcauley
Fantastic, that does the trick for keeping class Foo extends Bar( on one line, thanks! In case others are curious, I used binPack.parentConstructors = keep.
Bob Glamm
@glamm

I've done a bit of searching, but I can't seem to figure out how to not get the following code to indent 8 spaces with indent.main=4:

    ContextRoutes.of[C, F] {
        case ContextRequest(context, request) => request match {
                case GET -> Root => Ok(context.configuration.asJson)    // XXX indented 8 spaces here instead of 4

Is there some configuration parameter that will fix the indentation to 4 spaces instead of 8?

Albert Meltzer
@kitbellew
@glamm what does the rest of outer case look like?
@glamm request match {} is indented 4 relative to case Context, and case GET is indented 4 relative to request
Bob Glamm
@glamm
@kitbellew The outer case is a partial function with a single case - case ContextRequest(context, request) is the only case.
I suppose it makes more sense as
    ContextRoutes.of[C, F] { case ContextRequest(context, request) =>
        request match {
            case GET -> Root => Ok(context.configuration.asJson)
jaacko-torus
@jaacko-torus
I might have missed it, but is there a way to indent using the tab character instead of spaces?
1 reply
ex0ns
@ex0ns

I'm having some issue upgrading to 3.3.0, the alignment

       case iaEx: IllegalArgumentException => errorFuture[Seq[User]](IllegalArgument(iaEx.getMessage))
-      case e: Exception                   => errorFuture[Seq[User]](UnexpectedError(s"Unexpected error: ${e.getMessage}"))
+      case e: Exception => errorFuture[Seq[User]](UnexpectedError(s"Unexpected error: ${e.getMessage}"))

It's not aligned on the arrow anymore =>and I don't know what changed

5 replies
LUC DUZAN
@strokyl
Hello everybody, is there a way to forbide X with Y and replace it by X & Y (new scala 3 syntax for intersection type)
Peng Cheng
@tribbloid

My VSCode extension doesn't do parsing.

Instead it just show the error message : ""identifier expected but import found" scalameta"

Like the below screenshot

Screenshot from 2022-01-29 02-30-31.png
what's the problem?
Peng Cheng
@tribbloid
found the problem: scalameta/metals#2595
Prateek Asthana
@prateeka

how do i ensure block-comment line-breaks are respected? For example, below original code:

  /**
    * General description:
    * 1. point 1
    * 2. point 2
    */

after formatting becomes

  /** General description:
    *   1. point 1 2. point 2
    */

instead, i would like to continue having line-breaks like the original code.

my scalafmt.conf is:

runner.dialect = scala3
version=3.4.0

i am using Intellij 2021.3.1

3 replies
Martin Allaire
@mallaire77

Hello, is there a way to always apply new line on any def/val, like

val test = Test("Hello World")

to

val test =
  Test("Hello World")
1 reply
Anne
@AnneThor
Hello! I am wondering what the effect of setting runner.dialect=scala213 is in comparison to scala212 or scala211, does this mean basically to parse everything as scala 2.13 and flag anything incompatible? What would the real differences be in terms of formatting?
Matthew de Detrich
@mdedetrich
Does anyone know what happened with the unindentTopLevelOperators that was removed in Scalafmt 3.0 and if there is an equivalent setting?
Albert Meltzer
@kitbellew
@mdedetrich it was mentioned on the releases page
Matthew de Detrich
@mdedetrich
@kitbellew Can you provide the text? I tried looking for it and couldn't find a mention of it at https://github.com/scalameta/scalafmt/releases/tag/v3.0.0 or in the changelog https://scalameta.org/scalafmt/docs/changelog.html
2 replies

Or is

newlines.topLevelStatementBlankLines meant to be the replacement?

Matthew de Detrich
@mdedetrich
(and if so do you know the specific settings for newlines.topLevelStatementBlankLines which is equivalent to the old unindentTopLevelOperators)
Oliver Schrenk
@oschrenk

How would I force rewrite if/else blocks to always have braces?

# original
if(cond)
  foo()
else
  bar()

# formatted
if(cond) {
  foo()
} else {
  bar()
}

If found scalameta/scalafmt#1463 but it was closed in Oct 2020.

Albert Meltzer
@kitbellew
@oschrenk it's described in the documentation
desophos
@desophos
Hi, is it possible to force a line break after the open brace and before the close brace of a for comprehension with newlines.source = fold? Example: https://gist.github.com/desophos/19d53e9019ca78bb5adc01ac660f0f1c
2 replies
I couldn't find any mention of this in the documentation or github issues
Steve Jones
@sjfloat
I clobbered my version of scalafmt (and scala and scalac) with coursier and it's not obvious how to get back to 2.13.1
Maybe it's more of a coursier question. Is there a better channel for that?
Giovanni Sciavicco
@Benevole_gitlab

What's the deal with single newlines being all over the place in case of i.e. method definitions (not sure what's the proper expression in scalafmt language)???

This makes the code look like shotgun edited and IMHO not exactly too readable. This creates confusion when a .scala file has more than one method. See this:

    alignment = Pos.CenterRight

    style = borderStyle

  def createProgressPanel(): Node = new HBox(6):

    val slider = new Slider()

    val progressIndicator: ProgressIndicator = new ProgressIndicator():
Albert Meltzer
@kitbellew
@Benevole_gitlab if you believe there's a problem, please submit an issue on GitHub, with all the necessary information requested
tpetillot
@tpetillot

Hi folks!
Any configuration to prevent following formatting:

/*
 *   1. xxxxxxxxxxxxxxxxxxxxxxx
 *   2. yyyyyyyyyyyyyyyyyyyyyy
 *   3. zzzzzzzzzzzzzzzzzzzzzzzz
 */

// into

/*
 *   1. xxxxxxxxxxxxxxxxxxxxxxx 2.  yyyyyyyyyyyyyyyyyyyyyy 3. zzzzzzzzzzzzzzzzzzzzzzzz
 */

Thanks!

Oron Port
@soronpo
@tpetillot If you want enumeration, you need write
/*
 *   1. xxxxxxxxxxxxxxxxxxxxxxx
 *   1. yyyyyyyyyyyyyyyyyyyyyy
 *   1. zzzzzzzzzzzzzzzzzzzzzzzz
 */
Scaladoc should figure out the proper enum
I recently experienced this myself. Maybe there is a way to turn it off.
I must admit that I don't really like this. If we look at the code raw, then we see all bullets with the same number. This is highly annoying, IMO.
tpetillot
@tpetillot
Sad... I'll use it that way until fixed... thanks for the tip @soronpo
Albert Meltzer
@kitbellew
@tpetillot i will assume you used /** (and not /*). if you read https://docs.scala-lang.org/overviews/scaladoc/for-library-authors.html#other-formatting-notes, you will see that in scaladoc, you don't write actual numbers, you use a label to indicate what numbering/bulleting type should be used when this scaladoc is output. scaladoc is a markup language, not intended for reading in .scala but when it's output as .html.
if you wish to write arbitrary text in code, then either use /* or set docstrings.wrap = no.
Alex Cameron
@ac27182

Our team uses the scalikejdbc library quite heavily, and as a team we would like to preserve the existing style of the queries we write.

However we cannot find the right configuration keys to toggle which would give us more flexibility with the method chaining in the scalafmt configuration

Does anyone in this channel have any suggestions?

Below is an example of the style we would like to maintain, and what we want to avoid

// existing style
select
  .from(Table1 as t1)
  .innerJoin(Table2 as t2).on(sqls.eq(t2.someKey, t1.someKey))
  .innerJoin(Table3 as t3).on(sqls.eq(t3.someKey, t2.someKey))
  .where(???)
...
// what we wish to avoid
select
  .from(Table1 as t1)
  .innerJoin(Table2 as t2)
  .on(sqls.eq(t2.someKey, t1.someKey))
  .innerJoin(Table3 as t3)
  .on(sqls.eq(t3.someKey, t2.someKey))
  .where(???)
...
Albert Meltzer
@kitbellew
@ac27182 try source keep
Alex Cameron
@ac27182
@kitbellew I'll check it out thank you
Roberto Leibman
@rleibman
I'm seeing this error on a scala3 project (i.e. using runner.dialect = scala3):
[error] org.scalafmt.dynamic.ScalafmtDynamicError$ScalafmtInterfaceMethodDeprecated: Method Scalafmt.withRespectVersion is deprecated
[error]     at org.scalafmt.dynamic.ScalafmtDynamic.withRespectVersion(ScalafmtDynamic.scala:62)
2 replies