-
Notifications
You must be signed in to change notification settings - Fork 461
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
Kotlin support in Maven plugin #223
Changes from all commits
d2e311f
0bcf53b
ca64af9
60ecd22
8085880
b761c4b
c058ed7
4d7536d
178ffad
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
/* | ||
* Copyright 2016 DiffPlug | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package com.diffplug.spotless.kotlin; | ||
|
||
public final class KotlinConstants { | ||
|
||
// '^' is prepended to the regex in LICENSE_HEADER_DELIMITER later in FormatExtension.licenseHeader(String, String) | ||
public static final String LICENSE_HEADER_DELIMITER = "(package |@file)"; | ||
|
||
private KotlinConstants() {} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -32,7 +32,7 @@ | |
import com.diffplug.spotless.Formatter; | ||
import com.diffplug.spotless.FormatterStep; | ||
import com.diffplug.spotless.LineEnding; | ||
import com.diffplug.spotless.maven.generic.LicenseHeader; | ||
import com.diffplug.spotless.maven.generic.*; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I admit that I was surprised that this change from a full import to a wildcard import was apparently accepted by Travis CI. @nedtwigg Do you think it would be a good idea if I open an issue to cover catching wildcard imports in the future? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The eclipse formatter that we use doesn't have any rules against wildcard imports. It might be worth a bullet-point in this issue, maybe a config option on importSorter if it ever gets updated: #167 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @nedtwigg I'm not sure that I understood your last message correctly. Did you mean that you'd like me to write a new message on #167 - a reminder of sorts - to add a convert-wildcard-imports-to-full-imports option to the new There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yup! You can make a new issue too if you'd like, but it seems like implementing the wildcard imports issue is so closely tied to the ImportSorter that it makes sense to bundle them. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Cool! I'll go act on that now, then. :) |
||
|
||
public abstract class FormatterFactory { | ||
@Parameter | ||
|
@@ -87,7 +87,27 @@ public final void addLicenseHeader(LicenseHeader licenseHeader) { | |
addStepFactory(licenseHeader); | ||
} | ||
|
||
protected void addStepFactory(FormatterStepFactory stepFactory) { | ||
public final void addEndWithNewline(EndWithNewline endWithNewline) { | ||
addStepFactory(endWithNewline); | ||
} | ||
|
||
public final void addIndent(Indent indent) { | ||
addStepFactory(indent); | ||
} | ||
|
||
public final void addTrimTrailingWhitespace(TrimTrailingWhitespace trimTrailingWhitespace) { | ||
addStepFactory(trimTrailingWhitespace); | ||
} | ||
|
||
public final void addReplace(Replace replace) { | ||
addStepFactory(replace); | ||
} | ||
|
||
public final void addReplaceRegex(ReplaceRegex replaceRegex) { | ||
addStepFactory(replaceRegex); | ||
} | ||
|
||
protected final void addStepFactory(FormatterStepFactory stepFactory) { | ||
Objects.requireNonNull(stepFactory); | ||
stepFactories.add(stepFactory); | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
/* | ||
* Copyright 2016 DiffPlug | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package com.diffplug.spotless.maven.kotlin; | ||
|
||
import static com.diffplug.spotless.kotlin.KotlinConstants.LICENSE_HEADER_DELIMITER; | ||
|
||
import java.util.Set; | ||
|
||
import com.diffplug.common.collect.ImmutableSet; | ||
import com.diffplug.spotless.maven.FormatterFactory; | ||
|
||
public class Kotlin extends FormatterFactory { | ||
|
||
private static final Set<String> DEFAULT_INCLUDES = ImmutableSet.of("src/main/kotlin/**/*.kt", "src/test/kotlin/**/*.kt"); | ||
|
||
@Override | ||
public Set<String> defaultIncludes() { | ||
return DEFAULT_INCLUDES; | ||
} | ||
|
||
@Override | ||
public String licenseHeaderDelimiter() { | ||
return LICENSE_HEADER_DELIMITER; | ||
} | ||
|
||
public void addKtlint(Ktlint ktlint) { | ||
addStepFactory(ktlint); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
/* | ||
* Copyright 2016 DiffPlug | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package com.diffplug.spotless.maven.kotlin; | ||
|
||
import org.apache.maven.plugins.annotations.Parameter; | ||
|
||
import com.diffplug.spotless.FormatterStep; | ||
import com.diffplug.spotless.kotlin.KtLintStep; | ||
import com.diffplug.spotless.maven.FormatterStepConfig; | ||
import com.diffplug.spotless.maven.FormatterStepFactory; | ||
|
||
public class Ktlint implements FormatterStepFactory { | ||
|
||
@Parameter | ||
private String version; | ||
|
||
@Override | ||
public FormatterStep newFormatterStep(FormatterStepConfig config) { | ||
String ktlintVersion = version != null ? version : KtLintStep.defaultVersion(); | ||
return KtLintStep.create(ktlintVersion, config.getProvisioner()); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍