Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
  • Aug 18 19:16
    rvacaru synchronize #1650
  • Aug 18 18:06
    rvacaru synchronize #1650
  • Aug 18 17:52
    scala-steward opened #1659
  • Aug 18 09:41
    rvacaru synchronize #1650
  • Aug 18 09:41
    rvacaru synchronize #1650
  • Aug 18 09:11
    rvacaru synchronize #1650
  • Aug 18 00:00
    ssahayam-zd commented #1658
  • Aug 17 21:54
    bjaglin commented #1658
  • Aug 17 21:54
    bjaglin commented #1658
  • Aug 17 21:39
    bjaglin edited #1658
  • Aug 17 11:02
    ssanj commented #1658
  • Aug 16 12:08
    bjaglin edited #1658
  • Aug 16 12:08
    bjaglin opened #1658
  • Aug 15 20:38

    mlachkar on gh-pages

    Deploy website Deploy website … (compare)

  • Aug 15 20:38

    mlachkar on gh-pages

    Deploy website Deploy website … (compare)

  • Aug 15 20:35

    bjaglin on main

    remote gitter shield Merge pull request #1655 from s… (compare)

  • Aug 15 20:35
    bjaglin closed #1655
  • Aug 15 20:35
    bjaglin ready_for_review #1655
  • Aug 15 20:35

    bjaglin on main

    Update scalafmt-core to 3.5.9 Merge pull request #1656 from s… (compare)

  • Aug 15 20:35
    bjaglin closed #1656
earldouglas
@earldouglas:matrix.org
[m]
@olafurpg: Thanks, that's what I'm currently doing. It works, but it feels like there could be a better way.
@bjaglin: Ah ha, that looks like what I need. Thanks!
earldouglas
@earldouglas:matrix.org
[m]
:point_up: Edit: @bjaglin: Thanks, that looks like what I need. Is there a way to have the redefined compile use this, since I'm using scalafixOnCompile? Or could I re-redefine compile to do so?
Brice Jaglin
@bjaglin
@earldouglas:matrix.org scalafix is evaluated by compilewhen scalafixOnCompile is set (https://github.com/scalacenter/sbt-scalafix/blob/0a4dfc6a32d67b701235876fe5658f04c9c9687a/src/main/scala/scalafix/sbt/ScalafixPlugin.scala#L108-L116), so redefining scalafix like suggested in the first option should do the trick.
earldouglas
@earldouglas:matrix.org
[m]
That worked; thanks!
Brice Jaglin
@bjaglin

@/all Thanks to all our contributors, Scalafix 0.10.0-RC1 is out with the following highlights:

  • Breaking changes for rule authors (see release notes)
  • Compatibility checks when loading external rules
  • Deprecated keys & dependency to coursier-small removed from ScalafixPlugin
  • sbt-scalafix now only supports sbt 1.3+
  • scalafixEnable no longer overrides projects' scalaVersion unless really necessary
  • A new logo, visible in the docs -> https://scalacenter.github.io/scalafix/

More details on the full release notes:

Your user/rule author feedback is welcome on this release candidate.
If no major issue or obstacle is found in RC1, a final release will be cut on April 7th.

Jack Koenig
@jackkoenig
How should one include custom rules in ScalaFix without them being published? I've used --rules file:<path> in the past, but it seems to complain about missing SemanticDB for a SemanticRule, which is a little odd because ScalaFix needs to compile the rule anyway
Brice Jaglin
@bjaglin
@jackkoenig non-published rules can indeed be compiled on the fly via the --rules file:<path> syntax (https://scalacenter.github.io/scalafix/docs/developers/tutorial.html#using-file). Missing SemanticDB does not seem related to that feature but to the scalafix invocation itself. Do semantic built-in rules like RemoveUnused work? If you are using sbt, https://scalacenter.github.io/scalafix/docs/developers/local-rules.html could be an option for running project-specific rules.
Brice Jaglin
@bjaglin

scalafix & sbt-scalafix 0.10.0 are out with the following highlights:

  • New RedundantSyntax built-in rule
  • Bug fixes in ExplicitResultTypes & RemoveUnused
  • Breaking changes for rule authors (see release notes)
  • Compatibility checks when loading external rules
  • Deprecated keys & dependency to coursier-small removed from ScalafixPlugin
  • sbt-scalafix now only supports sbt 1.3+
  • sbt scalafixEnable no longer overrides projects' scalaVersion unless really necessary
  • A new logo, visible in the docs -> https://scalacenter.github.io/scalafix/

More details on the full release notes:

Thanks to the 6 contributors!

Jinto Thomas
@ttj4
hello everyone, I'm very new to scalafix, I'm testing out the scalafix cli, I have added the dependency as "ch.epfl.scala" %% "scalafix-cli" % "0.10.0-RC1" (i'm on scala 2.13.8) and getting this error not found: https://repo1.maven.org/maven2/ch/epfl/scala/scalafix-cli_2.13/0.10.0-RC1/scalafix-cli_2.13-0.10.0-RC1.pom
https://repo1.maven.org/maven2/ch/epfl/scala/scalafix-cli_2.13.8/0.10.0-RC1/scalafix-cli_2.13.8-0.10.0-RC1.pom this is the link I see in maven central, scalafix-cli_2.13 vs scalafix-cli_2.13.8
should I use it like "ch.epfl.scala" % "scalafix-cli_2.13.8" % "0.10.0-RC1"
Brice Jaglin
@bjaglin
Hi @ttj4 , I am assuming you use sbt? If so you should use "ch.epfl.scala" % "scalafix-cli" % "0.10.0" cross CrossVersion.full if you want to get the artifact safely. But if you want to run scalafix rules from your application, I recommend you use the Java API in scalafix-interfaces to avoid challenges with scala versions - scalafix-cli is really meant to be used as a CLI application, not directly (even though it contains the implementation of ScalafixArguments). scalafix-interfaces is what the most common scalafix clients (sbt, mill, maven, metals) use.
Jinto Thomas
@ttj4
ah I see, let me look into scalafix-interfaces then
Jinto Thomas
@ttj4

I think it might take sometime for me to change to the code with scalafix-interfaces. Now I;m actually stuck with this error, it doesn't recognise anything from scalafix.conf

SCALAFIX ARGS : List(--scalac-options, -Wunused, --scala-version, 2.13.8, --files, /Users/user/workspace/org/common/common, --config, scalafix.conf, --classpath, /Users/user/workspace/org/common/common-library/target/classes:/Users/user/workspace/org/common/library/target/test-classes:/Users/user/Library/Caches/Coursier/v1/https/repo1.maven.org/maven2/org/scala-lang/scala-library/2.13.8/scala-library-2.13.8.jar, --syntactic)
error: 26 errors
[E0] Unknown rule 'DurationIsFinite'
[E1] Unknown rule 'FixCollectionConverters'
[E2] Unknown rule 'FixFutureConverters'
[E3] Unknown rule 'FixUnit'
[E4] Unknown rule 'FixArrayDeep'
[E5] Unknown rule 'FixPostfixSyntax'
[E6] Unknown rule 'FixExecutionContextGlobal'
[E7] Unknown rule 'FixExplicitRight'
[E8] Unknown rule 'FixSymbolLiterals'
........

is it something you have seen before?

Brice Jaglin
@bjaglin

it doesn't recognise anything from scalafix.conf

Well, it looks like it does since it's trying to run the default rules declared there, right? I see these are not built-in rules though, where are these defined? Aren't you missing --tool-classpath?

Also, you would probably benefit from using the with* methods from the Java API instead of passing untyped arguments I guess.
Jack Koenig
@jackkoenig
How can I invoke community rules running ScalaFix CLI? I have the dependency on my classpath (eg. org.scala-lang::scala-rewrites:0.1.3 trying to run rule fix.scala213.ScalaSeq). I have fix.scala213.ScalaSeq listed in rules inside of my .scalafix.conf but get the error error: {"rules": ["fix.scala213.ScalaSeq"]} has no field 'fix'.
I have tried all kind of spellings of the rule, and I can confirm the scala-rewrites jar contains META-INF/services/scalafix.v1.Rule with several rules listed, including fix.scala213.ScalaSeq
Brice Jaglin
@bjaglin
@jackkoenig did you try to run the rule explicitly as a CLI arg instead of in the config file to see if that was working?
Jinto Thomas
@ttj4
@bjaglin I thought toolClass path will be picked from the default value, I cannot actually see any samples where --tools-classpath is passed. meanwhile I looked at the maven plugin, and came up with a simple test to test the interfaces api
    val pluginClassLoaderWithScalafix = getClass.getClassLoader
    val scalafix = Scalafix.classloadInstance(pluginClassLoaderWithScalafix)
val config = ConfigFactory.parseResources("scalafix.conf")
    val rules = config.getStringList("rules")
    scalafix
      .newArguments()
          .withRules(rules)
      .run()
but this also produces the same result - unknown rule.
Brice Jaglin
@bjaglin

@ttj4

I thought toolClass path will be picked from the default value

what do you mean by default value? scalafix needs to know whereFixUnit is defined, it cannot tell where to load external rules from. I assume FixUnit is a rule you wrote, but I can't tell if there are part of your project (https://scalacenter.github.io/scalafix/docs/developers/local-rules.html) or available in published as artifacts (https://scalacenter.github.io/scalafix/docs/developers/tutorial.html#publish-the-rule-to-maven-central) ? Both sbt-scalafix and mill-scalafix allow loading external rules, check their usage of withToolclasspath .

Meriam Lachkar
@mlachkar
@ttj4 Metals do that in their code : they invoke scalafix using scalafix interfaces, maybe you will find it intersting
https://github.com/scalameta/metals/blob/34d9f2803d87845a0aa46f994179075362b56a26/metals/src/main/scala/scala/meta/internal/metals/ScalafixProvider.scala#L311-L321
you need to add the .withToolClasspath(urlClassLoaderWithExternalRule) if you are using external rules.
Jinto Thomas
@ttj4
@mlachkar thank you, I was able to make it work by going over the scalafix-maven plugin (it was easier for me as we rely on maven, thats why I was stuggling with sbt)
Jinto Thomas
@ttj4

@mlachkar I do have a follow-up question though, I'm on scala 2.13.8, I'm unable add scala-collection-migrationsas my external rule due to issues with scala version (artifact available in the central repo is <dependency org="org.scala-lang.modules" name="scala-collection-migrations_2.12" rev="2.7.0"/>

I'm passing withToolClasspath with the following (I'm using coursier to pull them, and is calling the interface api to run the scalafix)

      .addDependencies(
        dep"org.scala-lang.modules:scala-collection-compat_2.13:2.7.0",
        dep"org.scala-lang:scala-rewrites_2.13:0.1.3",
        dep"com.github.liancheng:organize-imports_2.13:0.6.0",
        dep"ch.epfl.scala:scalafix-rules_2.13:0.10.0",
        dep"com.github.vovapolu:scaluzzi_2.13:0.1.21",
        dep"io.github.ghostbuster91.scalafix-unified:unified_2.13:0.0.8")
    )
      .run()
      .map(_.toPath)

Is there any workaround for this? I saw scala-collection-compat do support 2.13.8

Brice Jaglin
@bjaglin
@ttj4 The scalafix scala binary version (which seems to be 2.13 given your deps) must match the project scala binary version only if you use ExplicitResultTypes.

I'm using coursier to pull them

Do you mean you are using coursier yourself? https://www.javadoc.io/static/ch.epfl.scala/scalafix-interfaces/0.10.0/scalafix/interfaces/ScalafixArguments.html#withToolClasspath-java.util.List-java.util.List-java.util.List- does it for you. I don't think the maven plugin uses that, that's why I recommended looking at the sbt or mill plugin.

Jack Koenig
@jackkoenig
@bjaglin taking a look at this again, I have tried both CLI and config file
Does anyone have an example of running ScalaFix with the Cli? The only directions I see on the website are for using with the sbt plugin
Jack Koenig
@jackkoenig
I should add that with the argument --rules 'ScalaSeq', I get the error error: Unknown rule 'ScalaSeq', but when I do the full package of my rules with --rules 'fix.scala213.ScalaSeq' or --rules 'class:fix.scala213.ScalaSeq', I get the error error: {} has no field 'fix'.
Brice Jaglin
@bjaglin
@jackkoenig I reproduced the problem with scalafix --tool-classpath $(cs fetch "org.scala-lang::scala-rewrites:0.1.3") --rules fix.scala213.ScalaSeq: it seems that the rule fail if there is no fix.scala13 path in the config
This does the trick
cat .scalafix.conf         
fix.scala213{}
Jack Koenig
@jackkoenig
Yes! @bjaglin you are a life-saver.
Do you think it would make sense for ScalaFix to have sort of an implicit metaconfig? Or is there really just user-error in that Rule. Put another way, could it be argued that the ScalaFix user API here is slightly unfriendly or is it truly an obvious mistake in the Rule itself?
4 replies
Jinto Thomas
@ttj4
@bjaglin unfortunately I wasn't sure where to look for scala-collection-migrations repo. meanwhile, I was looking at the local rules (https://github.com/scalacenter/scalafix/blob/main/docs/developers/local-rules.md#as-a-separate-sub-project), is it something i can leverage with scalafix-interface?
Brice Jaglin
@bjaglin

@ttj4

unfortunately I wasn't sure where to look for scala-collection-migrations repo

https://github.com/scala/scala-collection-compat/tree/main/scalafix

I was looking at the local rules

Local rules is a feature of sbt-scalafix, so it's built on top of scalafix-interface. Maybe we can zoom out a bit - can you tell us what you are trying to achieve?

Jinto Thomas
@ttj4
@bjaglin I did look at scala-collection-compat, but I was unable to load those rules as it was giving Unknown rule 'Collection213Upgrade' (for all rules in here) as per the repo readme I need to add scala-collection-migrations as dep which is not available for 2.13
as for the local-rules, I'm trying to invoke the scalafix programatically (i',m generating a docker image and running it against multiple microservice projetcts for scala upgrade (also services are on maven), I wanted to write some local rules to get a few repetitive changes in the code
3 replies
Megan Wachs
@mwachs5
Is there a rule to clean up unnecessary string interpolation, so if I do something like s"Hi!" it would flag / turn into "Hi!"
2 replies
catostrophe
@catostrophe
Is there a working example of a scalafix migration available on github that just renames packages of an external dependency?
3 replies
Kilic Ali-Firat
@alifirat
Hey the scalafix community ! Recently, I've created a private rule for my company. I follow the classical path : published into a private artifactory and pulled it in the impacted projects and here is the issue. In addition of updating my build.sbt with ThisBuild / scalafixDependencies += ... I had to include the same line into the libraryDependencies otherwise it wasn't pull and the Scalafix rule cannot be applied. Do I miss something here ? Maybe it's normal to do so ?
2 replies
Sébastien Boulet
@gontard
Hello. I want to exclude generated files from being "scalafixed". What is the idiomatic way to to that with sbt-scalafix?
The files are generated by sbt-akka-grpc and are not listed by unmanagedSources but nethertheless scalafix lints them.
3 replies
Razvan Vacaru
@rvacaru

Hello all, I'm a GSoC contributor for scalafix this summer ( https://summerofcode.withgoogle.com/programs/2022/projects/gQ08FcXb )
I'm running scalafix and would like to use the --setting arg to provide a different config for ExplicitResultTypes.memberKind, but whatever value I provide is interpreted as string instead of list, eg

sbt "scalafix --no-cache --settings.ExplicitResultTypes.memberKind=List(MemberKind.Var)" (also tried [Var] or List(Var)

would you know if this should work and how to provide a list or valid string?

1 reply
Joe Graham
@jgraham-protego
hi all, I have a multi-project sbt file and one of the sub projects is a set of custom scalafix rules, when i add the subproject with CP dependencies dependsOn(my-scalafix-rules% ScalaConfig) and i try and run the rule I get Unknown rule 'X' (where X is a rule defined in my-scalafix-rules/src/main/scalafix/resources/META-INF/scalafix.v1.Rule, what am I doin' wrong here?
1 reply
Razvan Vacaru
@rvacaru
Hi all, I opened my first PR, would be nice if someone could review it: https://github.com/scalacenter/scalafix/pull/1627/files
Have a nice weekend!
Marcin Józefowicz
@marcin-jozefowicz

Hi!
Is there a way to run scala-fix programatically (some kind of SDK API) instead of adding sbt plugin?
Here is my use-case:
I have scala app which prepares zipped sbt projects. During generation the temporary folder for template project I want to run scala-fix which will allow me to change the syntax from scala 2 into scala 3.

Using sbt as separate proccess is not considered as it locks repository. And I want to generate templates in parallel.

4 replies
nlchar
@nlchar

Hi, everyone! Is there a way to apply Scalafix (via commands scalafixAll --check and scalafixAll) to IntegrationTest sbt configuration? I've followed the workaround from #331 like this:

ThisBuild / IntegrationTest / scalafix := ScalafixPlugin.scalafixTaskImpl(IntegrationTest).evaluated

However, scalafixTaskImpl is not reachable. By default, scalafixAll ignores sources in /it/.

2 replies
Brice Jaglin
@bjaglin
:information_source: This room will be deleted soon, replaced by a Discord channel on the Scalameta servers - head over to scalacenter/scalafix#1653 for the discussion