Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
  • 18:16
    SethTisue edited #1699
  • 18:15
    SethTisue commented #1699
  • 15:39
    mvasyliv commented #1653
  • Nov 23 08:02
    bjaglin commented #1703
  • Nov 23 08:02
    bjaglin commented #1703
  • Nov 23 06:32
    aalbul commented #1703
  • Nov 22 10:54

    mlachkar on gh-pages

    Deploy website Deploy website … (compare)

  • Nov 22 10:51

    bjaglin on main

    RedundantSyntax: honor suppress… Merge pull request #1703 from b… (compare)

  • Nov 22 10:51
    bjaglin closed #1703
  • Nov 22 10:51
    bjaglin edited #1703
  • Nov 22 08:55
    bjaglin synchronize #1703
  • Nov 22 08:44
    bjaglin edited #1703
  • Nov 22 08:44
    bjaglin edited #1703
  • Nov 22 08:43
    bjaglin edited #1703
  • Nov 22 08:43
    bjaglin opened #1703
  • Nov 20 17:42

    mlachkar on gh-pages

    Deploy website Deploy website … (compare)

  • Nov 20 17:39

    bjaglin on main

    Update community-rules.md Merge pull request #1702 from w… (compare)

  • Nov 20 17:39
    bjaglin closed #1702
  • Nov 20 17:37

    mlachkar on gh-pages

    Deploy website Deploy website … (compare)

  • Nov 20 17:34

    bjaglin on main

    Update scalafmt-core to 3.6.1 Merge pull request #1701 from s… (compare)

Ólafur Páll Geirsson
@olafurpg
the “dependency:” syntax is only needed if you dont configure scalafixDependencies
Should it be “scala-collection-migrations” instead of “-compat”?
Natan Silnitsky
@natansil
@olafurpg both of your suggestions fail (while Collection213Upgrade doesn't fail)
scalafix dependency:RoughlyMapValues@org.scala-lang.modules:scala-collection-migrations:2.6.0
[error] (Compile / scalafix) scalafix.sbt.InvalidArgument: Unknown rule 'RoughlyMapValues'
scalafix RoughlyMapValues
[error] (Compile / scalafix) scalafix.sbt.InvalidArgument: Unknown rule 'RoughlyMapValues'
scalafix Collection213Upgrade
[info] compiling 69 Scala sources...
Ólafur Páll Geirsson
@olafurpg
Im not familiar with the RoughlyMapValues rule, have you reported an issue to that repo?
If Collection213Upgrade ia working successfully then it sounds like everything is OK on your side
Natan Silnitsky
@natansil
Cool. Thanks! I will report the issue then...
Brice Jaglin
@bjaglin
Oliver Schrenk
@oschrenk
I have a project still running sbt 1.4.9. Is there a scalafix rule to (help me) migrate to sbt 1.5.7?
Oliver Schrenk
@oschrenk

At https://eed3si9n.com/sbt-1.5.0 I found

scalafix --rules=https://gist.githubusercontent.com/eed3si9n/57e83f5330592d968ce49f0d5030d4d5/raw/7f576f16a90e432baa49911c9a66204c354947bb/Sbt0_13BuildSyntax.scala *.sbt project/*.scala

But it fails with

 scalafix.sbt.InvalidArgument: 2 errors
Oliver Schrenk
@oschrenk

Oh. That page doesn't mention to install scalfix via coursier. It's only mentioned at syntactic Scalafix rule for unified slash syntax

Curious why the same command works then but not from within sbt.

Ólafur Páll Geirsson
@olafurpg
@oschrenk the sbt plugin has its own cli parser to integrate natively with sbt (for example, allow tab completions). The sbt plugin also has a different execution model, an unscoped “scalafix” command in the sbt shell runs scalatix independently for every project in the build (with the liat of sources and classpath configured per project/config pair) while the cli runs once against the recursive list of scala files
Also, the sbt shell doesn’t do glob expansion
earldouglas
@earldouglas:matrix.org
[m]
Is there a way to set the Scalafix configuration directly via an sbt setting, rather than through an external .scalafix.conf file?
I'm writing an sbt plugin that uses a Scalafix rule, and I don't want users to need to add a .scalafix.conf file.
Ólafur Páll Geirsson
@olafurpg
@earldouglas:matrix.org one workaround is to generate a .scalafix.conf file from the sbt plugin
You can configure sbt-scalafix to read the config from a custom file, which can live under target/ so that users don't see it
Brice Jaglin
@bjaglin

@earldouglas:matrix.org another possibility is to inject CLI args programmatically

Either by redefining scalafix/scalafixAll

Compile / scalafix := (Compile /scalafix).partialInput(" --settings.DisableSyntax.noSemicolons DisableSyntax").evaluated // also needed for Test
scalafixAll := scalafixAll.partialInput(" --settings.DisableSyntax.noSemicolons DisableSyntax").evaluated

or by declaring a new task using the built-in input keys (safer and less confusing for the end-user....)

lazy val lint = taskKey[Unit]("")
lint := scalafixAll.toTask(" --settings.DisableSyntax.noSemicolons DisableSyntax").value
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'.