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

Spotless doesn't work with ktlint 0.48.0 #1430

Closed
bcmedeiros opened this issue Dec 16, 2022 · 7 comments
Closed

Spotless doesn't work with ktlint 0.48.0 #1430

bcmedeiros opened this issue Dec 16, 2022 · 7 comments
Labels

Comments

@bcmedeiros
Copy link
Contributor

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)
@bcmedeiros
Copy link
Contributor Author

PR: #1432

@nedtwigg
Copy link
Member

nedtwigg commented Jan 2, 2023

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

@eirnym
Copy link
Contributor

eirnym commented Jan 2, 2023

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

@davidburstrom
Copy link
Contributor

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

@nedtwigg
Copy link
Member

nedtwigg commented Jan 2, 2023

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...

@eirnym
Copy link
Contributor

eirnym commented Jan 2, 2023

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.

@bcmedeiros
Copy link
Contributor Author

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
Labels
Projects
None yet
Development

No branches or pull requests

4 participants