better-tostring


License

License

GroupId

GroupId

com.kubukoz
ArtifactId

ArtifactId

better-tostring_2.12.11
Last Version

Last Version

0.3.2
Release Date

Release Date

Type

Type

jar
Description

Description

better-tostring
better-tostring
Project URL

Project URL

https://github.com/kubukoz/better-toString
Project Organization

Project Organization

com.kubukoz
Source Code Management

Source Code Management

https://github.com/polyvariant/better-tostring

Download better-tostring_2.12.11

How to add to project

<!-- https://jarcasting.com/artifacts/com.kubukoz/better-tostring_2.12.11/ -->
<dependency>
    <groupId>com.kubukoz</groupId>
    <artifactId>better-tostring_2.12.11</artifactId>
    <version>0.3.2</version>
</dependency>
// https://jarcasting.com/artifacts/com.kubukoz/better-tostring_2.12.11/
implementation 'com.kubukoz:better-tostring_2.12.11:0.3.2'
// https://jarcasting.com/artifacts/com.kubukoz/better-tostring_2.12.11/
implementation ("com.kubukoz:better-tostring_2.12.11:0.3.2")
'com.kubukoz:better-tostring_2.12.11:jar:0.3.2'
<dependency org="com.kubukoz" name="better-tostring_2.12.11" rev="0.3.2">
  <artifact name="better-tostring_2.12.11" type="jar" />
</dependency>
@Grapes(
@Grab(group='com.kubukoz', module='better-tostring_2.12.11', version='0.3.2')
)
libraryDependencies += "com.kubukoz" % "better-tostring_2.12.11" % "0.3.2"
[com.kubukoz/better-tostring_2.12.11 "0.3.2"]

Dependencies

compile (2)

Group / Artifact Type Version
org.scala-lang : scala-compiler jar 2.12.11
org.scala-lang : scala-library jar 2.12.11

Project Modules

There are no modules declared in this project.

better-tostring

License Latest version Maven Central

A Scala compiler plugin that replaces the default toString implementation of case classes with a more verbose one.

Example

Without the plugin:

final case class User(name: String, age: Int)

User("Joe", 18).toString() // "User(Joe, 18)"

With the plugin:

User("Joe", 18).toString() // "User(name = Joe, age = 18)"

Usage

In sbt:

libraryDependencies += compilerPlugin("com.kubukoz" % "better-tostring" % version cross CrossVersion.full)

The plugin is currently published for the following Scala versions:

  • 2.12.11, 2.12.12, 2.12.13
  • 2.13.4, 2.13.5, 2.13.6
  • 3.0.0

For older Scala versions, see previous versions of better-tostring.

As a rule of thumb, active support will include at least 3 latest stable versions of 2.12, 2.13 and 3.0 for the foreseeable future.

What does the plugin actually do?

  1. Only case classes located directly in packages or objects are changed. Nested classes and classes local to functions are currently ignored.
  2. Only the fields in the first parameter list are shown.
  3. If the class is nested in an object (but not a package object), the object's name and a dot are prepended.
  4. If the class already overrides toString directly, it's not replaced.

Roadmap

  • Ignore classes that inherit toString from a type that isn't Object (#34)
  • Potentially ignore value classes (#19)

If you have ideas for improving the plugin, feel free to create an issue and we'll consider making it happen :)

Customization?

tl;dr there is none.

The plugin makes certain assumptions about what is a better toString. We aim for a useful and reasonably verbose description of the data type, which could make it easier to find certain issues with your tests (mismatching values in a field) or see the labels in debug logs.

We also want the plugin to become minimal in the implementation and easy to use (plug & play), without lots of configuration options, so the representation of the data types will not be customizable. The format may change over time without prior notice, so you shouldn't rely on the exact representation (as is the case with any toString methods), but any changes in behavior will be communicated in the release notes.

If you need a different toString, we suggest that you implement one yourself. You may also want to look at pprint.

Maintainers

The maintainers of this project (people who can merge PRs and make releases) are:

Community

This project supports the Scala code of conduct and wants communication on all its channels (GitHub etc.) to be inclusive environments.

If you have any concerns about someone's behavior on these channels, contact Jakub Kozłowski.

com.kubukoz

Polyvariant

Making Scala a better language, one library at a time.

Versions

Version
0.3.2
0.3.1
0.3.0
0.2.10
0.2.9
0.2.8
0.2.7
0.2.6
0.2.5
0.2.4
0.2.3
0.2.2
0.2.1
0.2.0
0.1.0