-
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
Adds ktlint linting for Gradle Kotlin DSL files #129
Merged
nedtwigg
merged 6 commits into
diffplug:master
from
JLLeitschuh:task/JLL/115_lint_gradle_kotlin_dsl_files
Aug 2, 2017
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
707faab
Adds ktlint linting for Gradle Kotlin DSL files
JLLeitschuh 438bdf8
Add `out` to gitignore as IntelliJ is creating this file now
JLLeitschuh 4195813
Simplify kotlin gradle extension after review comments
JLLeitschuh a73e75c
Rename KotlinGradleExtension and add documentation of changes
JLLeitschuh e6606ad
Merge branch 'master' into task/JLL/115_lint_gradle_kotlin_dsl_files
JLLeitschuh d66ac18
Merged the kotlinGradle docs into the kotlin docs, since they're clos…
nedtwigg File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 48 additions & 0 deletions
48
plugin-gradle/src/main/java/com/diffplug/gradle/spotless/KotlinGradleExtension.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
/* | ||
* 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.gradle.spotless; | ||
|
||
import java.util.Objects; | ||
|
||
import com.diffplug.spotless.kotlin.KtLintStep; | ||
|
||
public class KotlinGradleExtension extends FormatExtension { | ||
private static final String GRADLE_KOTLIN_DSL_FILE_EXTENSION = "*.gradle.kts"; | ||
|
||
static final String NAME = "kotlinGradle"; | ||
|
||
public KotlinGradleExtension(SpotlessExtension rootExtension) { | ||
super(rootExtension); | ||
} | ||
|
||
/** Adds the specified version of [ktlint](https://github.com/shyiko/ktlint). */ | ||
public void ktlint(String version) { | ||
Objects.requireNonNull(version, "version"); | ||
addStep(KtLintStep.create(version, GradleProvisioner.fromProject(getProject()))); | ||
} | ||
|
||
public void ktlint() { | ||
ktlint(KtLintStep.defaultVersion()); | ||
} | ||
|
||
@Override | ||
protected void setupTask(SpotlessTask task) { | ||
if (target == null) { | ||
target = parseTarget(GRADLE_KOTLIN_DSL_FILE_EXTENSION); | ||
} | ||
super.setupTask(task); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
79 changes: 79 additions & 0 deletions
79
plugin-gradle/src/test/java/com/diffplug/gradle/spotless/KotlinGradleExtensionTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
/* | ||
* 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.gradle.spotless; | ||
|
||
import java.io.IOException; | ||
|
||
import org.junit.Assert; | ||
import org.junit.Test; | ||
|
||
public class KotlinGradleExtensionTest extends GradleIntegrationTest { | ||
@Test | ||
public void integration() throws IOException { | ||
testInDirectory(null); | ||
} | ||
|
||
@Test | ||
public void integration_script_in_subdir() throws IOException { | ||
testInDirectory("companionScripts"); | ||
} | ||
|
||
private void testInDirectory(final String directory) throws IOException { | ||
write("build.gradle", | ||
"plugins {", | ||
" id 'nebula.kotlin' version '1.0.6'", | ||
" id 'com.diffplug.gradle.spotless'", | ||
"}", | ||
"repositories { mavenCentral() }", | ||
"spotless {", | ||
" kotlinGradle {", | ||
" ktlint()", | ||
" target '**/*.gradle.kts'", | ||
" }", | ||
"}"); | ||
String filePath = "configuration.gradle.kts"; | ||
if (directory != null) { | ||
filePath = directory + "/" + filePath; | ||
} | ||
write(filePath, | ||
getTestResource("kotlin/ktlint/basic.dirty")); | ||
gradleRunner().withArguments("spotlessApply").build(); | ||
String result = read(filePath); | ||
String formatted = getTestResource("kotlin/ktlint/basic.clean"); | ||
Assert.assertEquals(formatted, result); | ||
} | ||
|
||
@Test | ||
public void integration_default() throws IOException { | ||
write("build.gradle", | ||
"plugins {", | ||
" id 'nebula.kotlin' version '1.0.6'", | ||
" id 'com.diffplug.gradle.spotless'", | ||
"}", | ||
"repositories { mavenCentral() }", | ||
"spotless {", | ||
" kotlinGradle {", | ||
" ktlint()", | ||
" }", | ||
"}"); | ||
write("configuration.gradle.kts", | ||
getTestResource("kotlin/ktlint/basic.dirty")); | ||
gradleRunner().withArguments("spotlessApply").build(); | ||
String result = read("configuration.gradle.kts"); | ||
String formatted = getTestResource("kotlin/ktlint/basic.clean"); | ||
Assert.assertEquals(formatted, result); | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
I had files showing up that should be ignored because of intellij. I can move this to a different PR if you really want but I figured it wasn't worth the overhead. (It's in its own commit).