Skip to content

Spotless doesn't work with ktlint 0.48.0 #1430

Closed

Description

@bcmedeiros

If you are submitting a bug, please include the following:

  • [ 6.12.0 ] spotless version

This is stack trace:

java.lang.NoSuchMethodError: 'com.pinterest.ktlint.core.api.UsesEditorConfigProperties$EditorConfigProperty com.pinterest.ktlint.core.api.DefaultEditorConfigProperties.getKtlintDisabledRulesProperty()'
        at com.diffplug.spotless.glue.ktlint.compat.KtLintCompat0Dot47Dot0Adapter.createEditorConfigOverride(KtLintCompat0Dot47Dot0Adapter.java:106)
        at com.diffplug.spotless.glue.ktlint.compat.KtLintCompat0Dot47Dot0Adapter.format(KtLintCompat0Dot47Dot0Adapter.java:73)
        at com.diffplug.spotless.glue.ktlint.KtlintFormatterFunc.applyWithFile(KtlintFormatterFunc.java:71)
        at com.diffplug.spotless.FormatterFunc$NeedsFile.apply(FormatterFunc.java:154)
        at com.diffplug.spotless.FormatterStepImpl$Standard.format(FormatterStepImpl.java:82)
        at com.diffplug.spotless.FormatterStep$Strict.format(FormatterStep.java:88)
        at com.diffplug.spotless.Formatter.compute(Formatter.java:230)
        at com.diffplug.spotless.PaddedCell.calculateDirtyState(PaddedCell.java:203)
        at com.diffplug.spotless.PaddedCell.calculateDirtyState(PaddedCell.java:190)
        at com.diffplug.gradle.spotless.SpotlessTaskImpl.processInputFile(SpotlessTaskImpl.java:102)
        at com.diffplug.gradle.spotless.SpotlessTaskImpl.performAction(SpotlessTaskImpl.java:88)

Activity

  1. added 2 commits that reference this issue on Dec 20, 2022
    2e00cfa
    f5af503
  2. bcmedeiros commented on Dec 28, 2022

    @bcmedeiros
    ContributorAuthor

    PR: #1432

  3. added a commit that references this issue on Jan 1, 2023
    918547f
  4. added a commit that references this issue on Jan 2, 2023
    4063e9f
  5. nedtwigg commented on Jan 2, 2023

    @nedtwigg
    Member

    Fixed in plugin-gradle 6.12.1 and plugin-maven 2.29.0 thanks to @davidburstrom with help from @bcmedeiros.

  6. eirnym commented on Jan 2, 2023

    @eirnym
    Contributor

    With these changes plugin doesn't work for ktlint 0.47.1 and works for ktlint 0.48.0

    I've tried plugin-gradle 6.12.1

  7. davidburstrom commented on Jan 2, 2023

    @davidburstrom
    Contributor

    Could you please elaborate on how it doesn't work?

  8. nedtwigg commented on Jan 2, 2023

    @nedtwigg
    Member

    Thanks for reporting. The version switch is here, this maybe has a bug for 0.47.1 that it doesn't have for 0.47.0.

    int minorVersion = Integer.parseInt(version.split("\\.")[1]);
    if (minorVersion >= 48) {
    // ExperimentalParams lost two constructor arguments, EditorConfigProperty moved to its own class
    this.adapter = new KtLintCompat0Dot48Dot0Adapter();
    } else if (minorVersion == 47) {
    // rename RuleSet to RuleProvider
    this.adapter = new KtLintCompat0Dot47Dot0Adapter();
    } else if (minorVersion >= 46) {

    We should probably extend BadSemver to handle the C in A.B.C and then use that

    class BadSemver {
    protected static int version(String input) {
    Matcher matcher = BAD_SEMVER.matcher(input);
    if (!matcher.find() || matcher.start() != 0) {
    throw new IllegalArgumentException("Version must start with " + BAD_SEMVER.pattern());
    }
    String major = matcher.group(1);
    String minor = matcher.group(2);
    return version(Integer.parseInt(major), Integer.parseInt(minor));
    }
    /** Ambiguous after 2147.483647.blah-blah */
    protected static int version(int major, int minor) {
    return major * 1_000_000 + minor;
    }

    example usage

    if (BadSemver.version(version) < BadSemver.version(0, 32)) {

    I'm also tempted for Spotless to just drop support for all versions of KtLint except for the most recent to have a breaking change in its API. The maintenance load for this one formatter is relatively high...

  9. eirnym commented on Jan 2, 2023

    @eirnym
    Contributor

    Gradle defines semver wokring as expected only for major version above 0 (breaking changes reflected in major version). When major is 0, minor version reflects breaking changes.

  10. bcmedeiros commented on Jan 3, 2023

    @bcmedeiros
    ContributorAuthor

    I was trying to upgrade my project and bumped into another issue:
    #1444

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions