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
Martijn Hoekstra
@martijnhoekstra
Werr having an open source day at $WORK, and have a PR, scalameta/scalafmt#2832
It would be an amazing success if we could get a review today. I know it's much to ask, but if someone has the time today, id be very grateful
Eric K Richardson
@ekrich
That is what I call service with a smile.
martingd
@martingd
@kitbellew Sorry, I have been busy, but I have now submitted an issue:
scalameta/scalafmt#2834
Daniele Sassoli
@DanieleSassoli
Hi guys, I'm running version 2.7.5 of scalafmt and wanting to upgrade to 3.0.8, however newlines.alwaysBeforeTopLevelStatements doesn't seem to be recognised anymore, I can't find any indications of it being deprecated/removed or an alternative being introduce. You guys got any guidance?
Daniele Sassoli
@DanieleSassoli

Maybe I just found it, is

newlines.topLevelStatementBlankLines = [
  { blanks { beforeAll = 1 } }
]

equivalent of newlines.alwaysBeforeTopLevelStatements?

2 replies
Oron Port
@soronpo
Is it a known issue that scalafmt that is configured with a Scala 3 dialect also applies it to build.sbt which renders it uncompilable?
heksesang
@heksenlied:matrix.org
[m]
It also applies it to build.sc, so I had to make an exclude-rule for it.
Alexander Ioffe
@deusaquilus

Hey Guys, quick question. I have some def fields that I want to line with an annotation:

object Obj {
  @Anno("blah") def foo: String
  @Anno("blahblah") def bar: String
  @Anno("blahblahblah") def bar: String
}
// should turn into:
object Obj {
  @Anno("blah")         def foo: String
  @Anno("blahblah")     def bar: String
  @Anno("blahblahblah") def bar: String
}

I tried doing (to align by the last :

align.tokens."+" = [{
  code = ")"
  owners = [{
    regex = "Init"
    parents = [ "Mod\\.Annot" ]
  }]
}]

Doesn't seem to work though. Any advice?

26 replies
sebarys
@sebarys

Hi
I have project with following structure

  • /src/main/scala - app code
  • /src/test/scala - unit tests code
  • /src/it/scala - integration tests code

How I can configure scalafmt to include files under /src/it/scala?

I've tried

project.includePaths = [
    "glob:**/src/it/scala/**.scala"
]

but it don't work

thanks for any hints in advance :)
Albert Meltzer
@kitbellew
@sebarys let me guess... you're not really using scalafmt, are you?
sebarys
@sebarys
@kitbellew my full config if that help
version = 3.1.1
runner.dialect = scala213
align.arrowEnumeratorGenerator = true
align.tokens.add = [{code = "<-"}, {code = "extends"}, {code = "%"}, {code = "%%"},  {code = ":="}]
comments.wrap = standalone
comments.wrapStandaloneSlcAsSlc = true
maxColumn = 140
newlines.beforeCurlyLambdaParams = multilineWithCaseOnly
newlines.implicitParamListModifierPrefer = before
newlines.topLevelStatements = [before, after]
preset = IntelliJ
rewrite.rules = [PreferCurlyFors, RedundantParens, SortModifiers, Imports]
rewrite.imports.sort = original
rewrite.trailingCommas.style = keep
rewrite.redundantBraces.stringInterpolation = true
project.excludeFilters = [
    com.some.autogenerated.code.package
]
I just want force scalafmt to format Scala files in other directories than /src/main/scala and /src/test/scala
Albert Meltzer
@kitbellew
@sebarys which command do you run in order to invoke the formatter?
6 replies
adding inConfig(IntegrationTest)(org.scalafmt.sbt.ScalafmtPlugin.scalafmtConfigSettings) do the trick
then scalafmtAll also format IntegrationTest files
dhffdefi
@dhffdefi_twitter

I'm having trouble with undesirable indentations. For example, I want the following:

tryMax(5) {
    exec(
        foo1()
    )
}.exitHereIfFailed
.exec(
    foo2()
)

but I get this:

tryMax(5) {
    exec(
        foo1()
    )
}.exitHereIfFailed
    .exec(
        foo2()
    )

I've tried a variety of configuration options and I can't figure out why it's indenting all chained code after the .exitHereIfFailed call. This leads to cascading indents on long chains and is a real pain.

Is there a config setting that will stop this?

Albert Meltzer
@kitbellew
@dhffdefi_twitter no setting. an expression which continues beyond a single line is indented, with few exceptions
Megan Wachs
@mwachs5
I've noticed that bumping to 3.1.2 from 3.0.0 , // comments now have an enforced first space, eg /// My comment would be // / My comment. While I like this, is this behavior opt-out at all, for a smoother transition?
2 replies
Megan Wachs
@mwachs5
Is there a way to specify alignment groups at a finer granularity? For example, i can see how to make more symbols add to the Assign group, but can I be more specific about the usages of =? Specifically, I am interested in having def ____ = align with subsequent def ___ = but not interact with val ____ =
Tobias Roeser
@lefou
Hi there! Scalafmt.withRespectVersion is deprecated, but lacks any information why and what to use instead. Can anybody help me decide what to do instead, as our integration in Mill is using this method?
Albert Meltzer
@kitbellew
@lefou if you used true as the parameter, you don't need to do anything, just remove the call; if you used false, however, then that option is no longer supported. the configuration file is required to have an explicit version, and that's the version that will be used.
1 reply
heksesang
@heksenlied:matrix.org
[m]
def and: A => And[E, B] =
    rule.andThen {
      case and @ And(_*) => and
      case x             => And(x)
    }
How do I make it not try to "fix" _* to * when writing with the new Scala 3 syntax (and the related rewrites enabled in the config)?
Albert Meltzer
@kitbellew
@heksenlied:matrix.org can you clarify, please? do you want to disable the syntax rewrite?
heksesang
@heksenlied:matrix.org
[m]
It rewrites _ to . Which isn't valid syntax at all.
But no idea what configuration makes it rewrite _* to *.
1 reply
heksesang
@heksenlied:matrix.org
[m]
@kitbellew: I cannot find it in the docs.
Albert Meltzer
@kitbellew
@heksenlied:matrix.org can you help me understand how you look for it, in case we need to modify the structure of the documentation page
heksesang
@heksenlied:matrix.org
[m]
I try to search for _*. As I don't really know what config option it would fall under.
When it transforms _* into *, I have no idea what it actually tries to do because * alone is not valid syntax, which makes it difficult to understand what option I am looking for.
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