Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
    Ned Twigg
    @nedtwigg
    Also, with apply dependsOn javaCompile, CI will pass even if people commit badly formatted code, because the CI server will fix it with local changes. So it is a good idea to disable this on CI, and I think also a bad idea to do in general. SpotlessApply can be a destructive change, best if it is always deliberate imo
    Chris Serra
    @chris-serra
    ah I see, thanks. and since the CI doesn't commit the build to our repo, it doesn't make sense for it to run on the CI.
    so either remove it as a dependency for javaCompile, or find a way to bypass that for the CI server.
    Ned Twigg
    @nedtwigg
    Right
    Chris Serra
    @chris-serra
    is it at all common to configure spotless outside of your build script? something you'd run explicitly locally but I don't want it be loaded up on the CI server at all.
    Chris Serra
    @chris-serra
    hmm, even when I apply the spotless plugin within a task, it still seems like spotlessJava is occurring. any way to prevent that from happening on build?
    Ned Twigg
    @nedtwigg
    You can check for CI environment variable.
    spotlessJava calculates, it doesn't do anything. spotlessJavaApply and spotlessJavaCheck depend on it, and they are the tasks which actually do something. By default, check -> spotlessCheck -> spotlessJavaCheck -> spotlessJava
    Chris Serra
    @chris-serra
    but if using ratchetFrom, spotlessJava would still use that, correct? So even if it only calculates, it's still attempting to look up that Git reference (where it fails)
    Ned Twigg
    @nedtwigg
    Yes
    You can use enforceCheck false
    Chris Serra
    @chris-serra
    hmm, still fails because of the ratchet not being able to find that branch
    Chris Serra
    @chris-serra
    ok, so I am now bypassing ratchetFrom on the CI, since the plan is to not run spotlessApply as a dependency of javaCompile. I have enforceCheck false, but it still fails on the check when it finds validation failures. Here's my Gradle file:
    apply plugin: 'com.diffplug.spotless'
    
    spotless {
        java {
            enforceCheck false
    
            ratchetFromBranch()
    
            toggleOffOn()
            licenseHeaderFile("$rootProject.projectDir/spotless/license-header.java").updateYearWithLatest(false)
            importOrderFile("$rootProject.projectDir/spotless/import-order.txt")
            removeUnusedImports()
            trimTrailingWhitespace()
            eclipse().configFile("$rootProject.projectDir/spotless/eclipse-format.xml")
        }
    }
    
    private void ratchetFromBranch() {
        String releaseStage = rootProject.property('release.stage')
        if (!['JENKINS', 'final'].contains(releaseStage)) {
            ratchetFrom 'origin/master'
        } else {
            // CI, so it will only do a check, and with `enforceCheck` set to false, it shouldn't fail the build.
        }
    }
    5 replies
    Shon Feder
    @shonfeder
    Hi! I'm just trying to configure spotless for our scala project using maven, and I cannot get it to run scalafmt on our files for the life of me!
    14 replies
    Benjamin Marwell
    @bmarwell
    Hi everyone! I just tried to configure the spotless-maven-plugin for my xml files. Even though I had set a differnent indentation, all files validate just fine. The "apply" action does not do anything besides formatting the xml headers. But just the <?xml …> tag, really.
    This is my format config for xml:
              <format>
                      <!-- xml -->
                      <includes>
                        <include>pom.xml</include>
                        <include>src/**/*.xml</include>
                      </includes>
    
                      <trimTrailingWhitespace />
    
                      <endWithNewline />
    
                      <indent>
                        <spaces>true</spaces>
                        <spacesPerTab>2</spacesPerTab>
                      </indent>
    
                      <prettier>
                        <devDependencyProperties>
                          <property>
                            <name>prettier</name>
                            <value>2.0.5</value>
                          </property>
                          <property>
                            <!-- this could not be written in the simpler to write 'devDependencies' element. -->
                            <name>@prettier/plugin-xml</name>
                            <value>0.13.0</value>
                          </property>
                        </devDependencyProperties>
                        <!--suppress UnresolvedMavenProperty -->
                        <configFile>${maven.multiModuleProjectDirectory}/build/prettierrc.xml.yaml</configFile>
                      </prettier>
                    </format>
    Ned Twigg
    @nedtwigg
    Put the <indent> after the <prettier>. The <format> describes a sequence of function applications, because prettier is last, it is overwriting the result of the <indent> step.
    Benjamin Marwell
    @bmarwell
    it is not intended by either, but lets see
    Nope, files are still untouched.
    Benjamin Marwell
    @bmarwell
    @nedtwigg I pushed the changes to https://github.com/scms/scms/tree/72-spotless-xml. The config is in the main pom.xml. I would have expected spotless to fail on the pom.xml file
    Ned Twigg
    @nedtwigg
    Sorry, not gonna have time to dig in. My advice is to read the “how spotlesss works section” https://github.com/diffplug/spotless/blob/main/CONTRIBUTING.md#how-spotless-works
    Benjamin Marwell
    @bmarwell
    @nedtwigg sadly that is not helpful. It says how to add a formatter step, but the maven plugin is supposed to do that for you. And I followed the readme of the maven plugin.
    Benjamin Marwell
    @bmarwell
    @bmhm
    Can anyone help me with this please?
    diffplug/spotless#792
    I already tried mvn -X but couldn’t find anything useful. Seems the debug switch does not get promoted to spotless, and there is no debug option for spotless in the maven-plugin’s readme.
    Benjamin Marwell
    @bmarwell
    The best thing I get is the HEADING of XML files:
    [ERROR]     pom.xml
    [ERROR]         @@ -1,7 +1,9 @@
    [ERROR]         -<?xml·version="1.0"·encoding="UTF-8"?>
    [ERROR]         -<project·xmlns="http://maven.apache.org/POM/4.0.0"
    [ERROR]         -·········xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    [ERROR]         -·········xsi:schemaLocation="http://maven.apache.org/POM/4.0.0·http://maven.apache.org/xsd/maven-4.0.0.xsd">
    [ERROR]         +<?xml·version="1.0"·encoding="UTF-8"·?>
    [ERROR]         +<project
    [ERROR]         +··xmlns="http://maven.apache.org/POM/4.0.0"
    [ERROR]         +··xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    [ERROR]         +··xsi:schemaLocation="http://maven.apache.org/POM/4.0.0·http://maven.apache.org/xsd/maven-4.0.0.xsd"
    [ERROR]         +>
    [ERROR]          ··<modelVersion>4.0.0</modelVersion>
    Ned Twigg
    @nedtwigg
    That means the bug is probably inside the prettier-xml-formatter.
    Spotless is a switchboard for other formatters. You shot above indicates that it’s all wired up right, but the xml formatter isn’t doing very much.
    Benjamin Marwell
    @bmarwell
    How can I see which files it is touching? Any debug option I can enable in Maven which will make the node process more verbose?
    Ned Twigg
    @nedtwigg
    I don’t know how to make node more verbose
    But you can double-check which files are being touched with https://github.com/diffplug/spotless/blob/main/PADDEDCELL.md
    Benjamin Marwell
    @bmarwell
    That doc does not really help me
    Benjamin Marwell
    @bmarwell
    @nedtwigg I would like to push that issue forward. Anything else where to start looking? It would be really useful if we could make node.js more chatty…
    Scott Sue
    @scott.sue_gitlab

    Hi all, what is the general best practice for integrating spotless into a project? I currently see two scenarios:
    1) Perform a one time hit to format every file within the project across all branches. This will ensure that any subsequent commits won't have any major formatting changes bundled with 'real' code changes. This seems to be discouraged and hence the ratchetFrom was created? Activities like code reviews are then easier to perform as the reviewer can disregard any formatting changes
    2) Utilise ratchetFrom to only change the files that have been modified. This however seems to suggest that formatting changes are bundled in with 'real' code changes making code reviews more difficult.

    I would have thought 1) would have been the best practice, but it seems to be discouraged within the documentation.

    Can anyone share any experiences with how best to integrate spotless into a project?

    Ned Twigg
    @nedtwigg
    @bmarwell I've lost context. GitHub issue would be better, but the bottom line is that I think everything is working as intended, but you don't like what the formatter is doing. I linked you to CONTRIBUTING.md so that you could submit a PR to change what a formatter does if you want. I don't have time to help past that.
    1 reply
    @scott.sue_gitlab When it comes to first turning-on, Spotless has no opinion on "format-the-world" vs "incremental". I think "format-the-world" is better, but incremental is fine too.
    But there's also the issue of day-to-day updates. Languages add new features, and formatters change their defaults over time. Easy to say "the format should never change", but after maintaining this thing for years, every formatter has changed its settings over time. This means that just updating your build dependencies can lead to ){ becoming ) { all over the project, noise like that.
    So once you are using Spotless, I think ratchetFrom is helpful to limit that noise. It's also a lot faster, and if you want actually-correct copyright headers on every file, then it's the only option.
    Scott Sue
    @scott.sue_gitlab
    Thanks Ned for the insight. I was leaning towards "format the world" as well. The documentation that I was referring to where this seemed to be (or at least the way I understood it) was at https://github.com/diffplug/spotless/tree/main/plugin-gradle#ratchet. Maybe our conversation can be incorporated into this to avoid any further potential confusion?
    Ned Twigg
    @nedtwigg
    Happy to take any PRs! The general Spotless philosophy is that we are not opinionated, and just try to facilitate whatever opinions the user has. We appreciate new users contibuting back to the docs to reduce stick points!
    Isaac Vargas
    @I-Vargas
    Saw that ktfml had a new release last week adding a new style (facebookincubator/ktfmt@7fbc9d9)
    I was playing around a little bit and created a PR (diffplug/spotless#810), was just me playing a bit around
    Rob Oxspring
    @roxspring
    I'm starting to play with generating reviewdog json reports, and it's clearly gonna take more than SimpleJsonWriter can cope with. Do we want to expand the home grown code to cope with arrays and richer tree structures, or is it time to embrace a JSON library? (and any preference of JSON library?)
    Ned Twigg
    @nedtwigg
    Awesome! Feel free to pick a Json lib of your choice. I’ve been happy with Moshi, Gson, and Jsoniter, but happy to use something new that you like.
    Timur
    @timkabot
    Can you advice where the spotless or ktlint stores reports, cant find them(
    8 replies
    image.png
    Alexey Kotlyarov
    @koterpillar
    Does spotless (for Gradle) add jcenter repository to the build?
    Ned Twigg
    @nedtwigg
    Spotless uses, but does not modify, the buildscript repositories. In older versions of Gradle, I think the buildscript repository defaults includes jcenter
    Frank Vennemeyer
    @fvgh
    @nedtwigg , please have a look at the latest : eclipse-groovy:changelogPush . Looks like a ⭕ setup problem to me.
    Ned Twigg
    @nedtwigg
    @fvgh I think it's a deeper issue from the jcenter sunset. We have always published via jcenter -> mavencentral, but jcenter stopped accepting new uploads. I promise I'll have it resolved by end of the week, hopefully sooner.