Skip to content

Documentation regarding rewrite.yml is misleading: documentation says the default location is rootDir while the actual default is projectDir #241

Open
@vlsi

Description

@vlsi

What version of OpenRewrite are you using?

org.openrewrite.rewrite.gradle.plugin:6.4.3

How are you running OpenRewrite?

./gradlew rewriteDiscover

The are four issues:

  1. Documentation says rootDir is the default location: https://docs.openrewrite.org/reference/gradle-plugin-configuration#configuring-the-rewrite-dsl
    // These are default values, shown for example. It isn't necessary to supply these values manually:
    configFile = project.getRootProject().file("rewrite.yml")

In practice, the default location is projectDir/rewrite.yml:

  1. I would expect OpenRewrite to fail when the user provides a non-existent style. It took me a while to realize that my rewrite.yml was not loaded at all

  2. A better alternative to File configFile would be https://docs.gradle.org/current/dsl/org.gradle.api.resources.TextResourceFactory.html (since Gradle 2.2) as it would reduce IO during the configuration time. In other words, if user does not execute OpenRewrite tasks, users won't need executing IO for rewrite.yml. See https://github.com/gradle/gradle/blob/bb4604586434a1c781ff3996ffaff66d079cb43c/platforms/jvm/code-quality/src/main/groovy/org/gradle/api/plugins/quality/CheckstyleExtension.java#L39

  3. The documentation should probably prefer Kotlin DSL syntax rather than Java DSL as people rarely use Gradle Plugins from Java.
    In other words rootProject should be preferred over getRootProject()

What is the smallest, simplest way to reproduce the problem?

Add the following rewrite.yml to the root dir

---
# See reference at https://docs.openrewrite.org/concepts-explanations/styles#declarative-styles
type: specs.openrewrite.org/v1beta/style
name: io.github.pgjdbc.style.Style
styleConfigs:
  - org.openrewrite.java.style.TabsAndIndentsStyle:
      # See https://github.com/openrewrite/rewrite/issues/3666
      # For now, it should be the same as in .editorconfig
      useTabCharacter: false
      tabSize: 2
      indentSize: 2
      continuationIndent: 4
  - org.openrewrite.java.style.SpacesStyle:
      # See https://github.com/openrewrite/rewrite/blob/1d0aeec11e2d7f239f2f656bfd964b17ca8e4d17/rewrite-java/src/main/java/org/openrewrite/java/style/SpacesStyle.java#L26C14-L26C25
      other:
        afterForSemicolon: true

Configure Gradle plugin:

plugins {
    id("org.openrewrite.rewrite")
}

dependencies {
    rewrite(platform("org.openrewrite.recipe:rewrite-recipe-bom:2.4.1"))
    rewrite("org.openrewrite.recipe:rewrite-static-analysis")
}

rewrite {
    activeStyle("io.github.pgjdbc.style.Style")
    activeRecipe("org.openrewrite.java.OrderImports")
    activeRecipe("org.openrewrite.staticanalysis.MissingOverrideAnnotation")
}

What did you see instead?

Available Styles:
    org.openrewrite.java.IntelliJ
    org.openrewrite.kotlin.IntelliJ
    com.netflix.genie.Style
    org.openrewrite.java.SpringFormat
    com.netflix.eureka.Style
    org.openrewrite.java.GoogleJavaFormat

What is the full stack trace of any errors you encountered?

Available Styles: does not list io.github.pgjdbc.style.Style

Are you interested in contributing a fix to OpenRewrite?

May be

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingdocumentationImprovements or additions to documentationparser-gradle

    Type

    No type

    Projects

    Status

    Backlog

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions