Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update metaconfig-docs to 0.10.0 #1530

Merged

Conversation

scala-steward
Copy link
Contributor

Updates com.geirsson:metaconfig-docs from 0.9.15 to 0.10.0.
GitHub Release Notes - Version Diff

I'll automatically update this PR to resolve conflicts as long as you don't change it yourself.

If you'd like to skip this version, you can just close this PR. If you have any feedback, just mention me in the comments below.

Configure Scala Steward for your repository with a .scala-steward.conf file.

Have a fantastic day writing Scala!

Files still referring to the old version number

The following files still refer to the old version number (0.9.15).
You might want to review and update them manually.

CONTRIBUTING.md
Ignore future updates

Add this to your .scala-steward.conf file to ignore future updates of this dependency:

updates.ignore = [ { groupId = "com.geirsson", artifactId = "metaconfig-docs" } ]

labels: library-update, early-semver-major, semver-spec-minor, old-version-remains, commit-count:1

@tgodzik
Copy link
Contributor

tgodzik commented Feb 1, 2022

As suspected we need to add pprint dependency 🤔

We could also use metaconfig version for the rules in the scalafix config.

@bjaglin
Copy link
Collaborator

bjaglin commented Feb 9, 2022

Follow #1522
See scalameta/metaconfig#154 (comment)

As suspected we need to add pprint dependency 🤔

👍 will amend this

We could also use metaconfig version for the rules in the scalafix config.

what do you mean?

@bjaglin bjaglin force-pushed the update/metaconfig-docs-0.10.0 branch 5 times, most recently from 3a89fb5 to 055d1d6 Compare February 9, 2022 11:32
TPrint.make[PathMatcher](_ => "<glob>")
implicit val confPrint: TPrint[Conf] =
TPrint.make[Conf](implicit cfg => TPrint.implicitly[ScalafixConfig].render)
implicit val absolutePathPrint: _root_.pprint.TPrint[AbsolutePath] =
Copy link
Collaborator

@bjaglin bjaglin Feb 9, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I updated the code to compile, but I believe (no tests seem to prevent regressions of 7811980) that all these pprint.TPrint instances are now effectively useless since they are no longer picked up.

Since scala 2.11 does build against an old metaconfig where pprint is not shaded, I am still wondering what's best:

  1. start consider dropping scala 2.11 support (mostly useful for Make ExplicitResultTypes work with more Scala versions #998)
  2. drop these instances (the real impact on the output should be assessed)
  3. freeze a scala-2.11 version of the implicits in Args.scala (https://github.com/tpolecat/doobie/blob/5d0957d95ec64597452c9476a4586dc90f19c437/build.sbt#L231-L237 or symlinks for the rest?)

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I updated the code to compile, but I believe (no tests seem to prevent regressions of 7811980) that all these pprint.TPrint instances are now effectively useless since they are no longer picked up.

Confirmed

--- <unnamed>
+++ <unnamed>
@@ -1,20 +1,20 @@
 $ sbt "cli/runMain scalafix.cli.Cli --help"
 ...
 [info] running (fork) scalafix.cli.Cli --help
-[info] Scalafix 0.9.34+19-147646c0-SNAPSHOT
+[info] Scalafix 0.9.34+10-055d1d6b-SNAPSHOT
 [info] Usage: scalafix [options] [<path> ...]
 [info] Scalafix is a refactoring and linting tool. Scalafix supports both syntactic and
 [info] semantic linter and rewrite rules. Syntactic rules can run on source code
 [info] without compilation. Semantic rules can run on source code that has been
 [info] compiled with the SemanticDB compiler plugin.
 [info] Common options:
-[info]   --rules | -r [String ...] (default: [])
+[info]   --rules | -r List[String] (default: [])
 [info]     Scalafix rules to run, for example ExplicitResultTypes. The syntax for rules is
 [info]     documented in
 [info]     https://scalacenter.github.io/scalafix/docs/users/configuration#rules
-[info]   --files | -f [<path> ...] (default: [])
+[info]   --files | -f List[AbsolutePath] (default: [])
 [info]     Files or directories (recursively visited) to fix.
-[info]   --config <path> (default: null)
+[info]   --config Option[AbsolutePath] (default: null)
 [info]     File path to a .scalafix.conf configuration file. Defaults to .scalafix.conf in
 [info]     the current working directory, if any.
 [info]   --check
@@ -25,7 +25,7 @@
 [info]   --diff
 [info]     If set, only apply scalafix to added and edited files in git diff against the
 [info]     master branch.
-[info]   --diff-base String (default: null)
+[info]   --diff-base Option[String] (default: null)
 [info]     If set, only apply scalafix to added and edited files in git diff against a
 [info]     provided branch, commit or tag.
 [info]   --syntactic
@@ -46,20 +46,20 @@
 [info]     files that should be fixed must be compiled with semanticdb-scalac.
 [info]     Dependencies are required by rules like ExplicitResultTypes, but the
 [info]     dependencies do not need to be compiled with semanticdb-scalac.
-[info]   --sourceroot <path> (default: null)
+[info]   --sourceroot Option[AbsolutePath] (default: null)
 [info]     Absolute path passed to semanticdb with -P:semanticdb:sourceroot:<path>.
 [info]     Relative filenames persisted in the Semantic DB are absolutized by the
 [info]     sourceroot. Defaults to current working directory if not provided.
-[info]   --semanticdb-targetroots [<path> ...] (default: [])
+[info]   --semanticdb-targetroots List[AbsolutePath] (default: [])
 [info]     Absolute paths passed to semanticdb with -P:semanticdb:targetroot:<path>. Used
 [info]     to locate semanticdb files. By default, Scalafix will try to locate
 [info]     semanticdb files in the classpath
 [info]   --auto-classpath
 [info]     If set, automatically infer the --classpath flag by scanning for directories
 [info]     with META-INF/semanticdb
-[info]   --auto-classpath-roots [<path> ...] (default: [])
+[info]   --auto-classpath-roots List[AbsolutePath] (default: [])
 [info]     Additional directories to scan for --auto-classpath
-[info]   --scalac-options [String ...] (default: [])
+[info]   --scalac-options List[String] (default: [])
 [info]     The scala compiler options used to compile this --classpath, for example
 [info]     -Ywarn-unused-import
 [info]   --scala-version ScalaVersion (default: "2.13.8")
@@ -82,7 +82,7 @@
 [info]     autoload -U _scalafix
 [info]     ```
 [info] Less common options:
-[info]   --exclude [<glob> ...] (default: [])
+[info]   --exclude List[PathMatcher] (default: [])
 [info]     Unix-style glob for files to exclude from fixing. The glob syntax is defined by
 [info]     `nio.FileSystem.getPathMatcher`.
 [info]   --tool-classpath URLClassLoader (default: "<classloader>")
@@ -94,15 +94,15 @@
 [info]     If set, throw exception in the end instead of System.exit
 [info]   --no-stale-semanticdb
 [info]     Don't error on stale semanticdb files.
-[info]   --settings ScalafixConfig (default: {})
+[info]   --settings Conf (default: {})
 [info]     Custom settings to override .scalafix.conf
-[info]   --out-from String (default: null)
+[info]   --out-from Option[String] (default: null)
 [info]     Write fixed output to custom location instead of in-place. Regex is passed as
 [info]     first argument to file.replaceAll(--out-from, --out-to), requires --out-to.
-[info]   --out-to String (default: null)
+[info]   --out-to Option[String] (default: null)
 [info]     Companion of --out-from, string that is passed as second argument to
 [info]     fileToFix.replaceAll(--out-from, --out-to)
 [info]   --auto-suppress-linter-errors
 [info]     Insert /* scalafix:ok */ suppressions instead of reporting linter errors.
-[info]   --cwd <path> (default: "/Users/anabrice/Projects/git/scalafix/scalafix-cli")
+[info]   --cwd AbsolutePath (default: "/Users/anabrice/Projects/git/scalafix/scalafix-cli")
 [info]     The current working directory

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I went for option (3)

@bjaglin bjaglin force-pushed the update/metaconfig-docs-0.10.0 branch from 055d1d6 to ffcd8b9 Compare February 14, 2022 10:54
@bjaglin bjaglin merged commit 9533c97 into scalacenter:main Feb 14, 2022
@bjaglin
Copy link
Collaborator

bjaglin commented Mar 7, 2022

😭 I got back to this (yet unreleased) PR today while trying out rules built with a scalafix-core SNAPSHOT with a stable scalafix-core (something not tested in CI)

➜  simulacrum-scalafix git:(patch-1) ✗ cs launch ch.epfl.scala:scalafix-cli_2.12.15:latest.release -M scalafix.cli.Cli -- --tool-classpath /home/brice/.ivy2/local/org.typelevel/simulacrum-scalafix_2.12/0.5.5-SNAPSHOT/jars/simulacrum-scalafix_2.12.jar                                                   
Exception in thread "main" java.util.ServiceConfigurationError: scalafix.v1.Rule: Provider org.typelevel.simulacrum.fix.TypeClassSupport could not be instantiated
	at java.base/java.util.ServiceLoader.fail(ServiceLoader.java:582)
	at java.base/java.util.ServiceLoader$ProviderImpl.newInstance(ServiceLoader.java:804)
	at java.base/java.util.ServiceLoader$ProviderImpl.get(ServiceLoader.java:722)
	at java.base/java.util.ServiceLoader$3.next(ServiceLoader.java:1395)
	at scala.collection.convert.Wrappers$JIteratorWrapper.next(Wrappers.scala:46)
	at scala.collection.Iterator.foreach(Iterator.scala:943)
	at scala.collection.Iterator.foreach$(Iterator.scala:943)
	at scala.collection.AbstractIterator.foreach(Iterator.scala:1431)
	at scala.collection.generic.Growable.$plus$plus$eq(Growable.scala:62)
	at scala.collection.generic.Growable.$plus$plus$eq$(Growable.scala:53)
	at scala.collection.mutable.ListBuffer.$plus$plus$eq(ListBuffer.scala:184)
	at scala.collection.mutable.ListBuffer.$plus$plus$eq(ListBuffer.scala:47)
	at scala.collection.TraversableOnce.to(TraversableOnce.scala:366)
	at scala.collection.TraversableOnce.to$(TraversableOnce.scala:364)
	at scala.collection.AbstractIterator.to(Iterator.scala:1431)
	at scala.collection.TraversableOnce.toList(TraversableOnce.scala:350)
	at scala.collection.TraversableOnce.toList$(TraversableOnce.scala:350)
	at scala.collection.AbstractIterator.toList(Iterator.scala:1431)
	at scalafix.internal.v1.Rules$.all(Rules.scala:104)
	at scalafix.v1.RuleDecoder$$anon$1.<init>(RuleDecoder.scala:106)
	at scalafix.v1.RuleDecoder$.decoder(RuleDecoder.scala:105)
	at scalafix.internal.v1.Args.ruleDecoder(Args.scala:254)
	at scalafix.internal.v1.Args.configuredRules(Args.scala:288)
	at scalafix.internal.v1.Args.$anonfun$validate$1(Args.scala:420)
	at metaconfig.Configured.andThen(Configured.scala:45)
	at scalafix.internal.v1.Args.validate(Args.scala:416)
	at scalafix.internal.v1.MainOps$.run(MainOps.scala:72)
	at scalafix.v1.Main$.run(Main.scala:34)
	at scalafix.v1.Main$.main(Main.scala:25)
	at scalafix.cli.Cli$.main(Cli.scala:9)
	at scalafix.cli.Cli.main(Cli.scala)
Caused by: java.lang.NoClassDefFoundError: metaconfig/pprint/TPrintColors
	at org.typelevel.simulacrum.fix.TypeClassSupport.<init>(TypeClassSupport.scala:23)
	at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
	at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
	at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
	at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:490)
	at java.base/java.util.ServiceLoader$ProviderImpl.newInstance(ServiceLoader.java:780)
	... 29 more
Caused by: java.lang.ClassNotFoundException: metaconfig.pprint.TPrintColors
	at java.base/java.net.URLClassLoader.findClass(URLClassLoader.java:476)
	at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:589)
	at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:522)
	... 35 more

It's a compatibility issue similar to what's discussed in #1556 (comment), except that it's with metaconfig rather than scalameta and results in an exception rather than false negative matches

That's because scalafix-core is already loaded when external rules are injected in a separate classloader, so their version of scalafix-core (and thus scalameta metaconfig) is ignored. In other words: scalafix-interfaces forces scalafix-cli's scalameta metaconfig version, there is no eviction possible here.

// External rules are built against `scalafix-core` to expose `scalafix.v1.Rule` implementations. The
// classloader loading `scalafix-cli` already contains `scalafix-core` to be able to discover them (which
// is why it must be the parent of the one loading the tool classpath), so effectively, the version/instance
// in the tool classpath will not be used. This is OK, as `scalafix-core` should not break binary
// compatibility, as discussed in https://github.com/scalacenter/scalafix/issues/1108#issuecomment-639853899.
Module scalafixCore = Module.parse("ch.epfl.scala::scalafix-core", ScalaVersion.of(scalaVersion));
ResolutionParams excludeDepsInParentClassloader = ResolutionParams.create()
.addExclusion(scalafixCore.getOrganization(), scalafixCore.getName())

@bjaglin
Copy link
Collaborator

bjaglin commented Mar 7, 2022

Since we have a breaking change upstream, I am ready to accept that rules built against latest versions of scalafix-core needs a recent scalafix client, but we need a more explicit message/error. Ideally this message should be injected at compile time since we don't have control over existing clients.

$ javap -p -c -cp /home/brice/.ivy2/local/org.typelevel/simulacrum-scalafix_2.12/0.5.5-SNAPSHOT/jars/simulacrum-scalafix_2.12.jar org.typelevel.simulacrum.fix.TypeClassSupportConfig\$ | grep pprint 
      41: getstatic     #100                // Field metaconfig/pprint/TPrint$.MODULE$:Lmetaconfig/pprint/TPrint$;
      58: invokevirtual #118                // Method metaconfig/pprint/TPrint$.recolor:(Lfansi/Str;)Lmetaconfig/pprint/TPrint;
      61: getstatic     #121                // Field metaconfig/pprint/TPrintColors$BlackWhite$.MODULE$:Lmetaconfig/pprint/TPrintColors$BlackWhite$;
      64: invokeinterface #127,  2          // InterfaceMethod metaconfig/pprint/TPrint.render:(Lmetaconfig/pprint/TPrintColors;)Lfansi/Str;
      91: getstatic     #100                // Field metaconfig/pprint/TPrint$.MODULE$:Lmetaconfig/pprint/TPrint$;
     108: invokevirtual #118                // Method metaconfig/pprint/TPrint$.recolor:(Lfansi/Str;)Lmetaconfig/pprint/TPrint;
     111: getstatic     #121                // Field metaconfig/pprint/TPrintColors$BlackWhite$.MODULE$:Lmetaconfig/pprint/TPrintColors$BlackWhite$;
     114: invokeinterface #127,  2          // InterfaceMethod metaconfig/pprint/TPrint.render:(Lmetaconfig/pprint/TPrintColors;)Lfansi/Str;
     182: getstatic     #100                // Field metaconfig/pprint/TPrint$.MODULE$:Lmetaconfig/pprint/TPrint$;
     199: invokevirtual #118                // Method metaconfig/pprint/TPrint$.recolor:(Lfansi/Str;)Lmetaconfig/pprint/TPrint;
     202: getstatic     #121                // Field metaconfig/pprint/TPrintColors$BlackWhite$.MODULE$:Lmetaconfig/pprint/TPrintColors$BlackWhite$;
     205: invokeinterface #127,  2          // InterfaceMethod metaconfig/pprint/TPrint.render:(Lmetaconfig/pprint/TPrintColors;)Lfansi/Str;

https://github.com/scalameta/metaconfig/blob/abfcae697e9022308b1842ebcc85903d0f782efc/metaconfig-pprint/shared/src/main/scala-2/metaconfig/pprint/TPrintImpl.scala#L43-L47

Maybe for a while scalafix-core could bring something evicting metaconfig-pprint at build time (via a provided dependency?), to wrap the code generated by the metaconfig macro with some catch/rethrow an exception with an actionnable message.

@bjaglin
Copy link
Collaborator

bjaglin commented Mar 12, 2022

Maybe for a while scalafix-core could bring something evicting metaconfig-pprint at build time (via a provided dependency?), to wrap the code generated by the metaconfig macro with some catch/rethrow an exception with an actionnable message.

#1562 adds an actionable message

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants