Skip to content

Commit a3fa14c

Browse files
committed
update detekt and Ktlint versions
1 parent 9a76014 commit a3fa14c

File tree

7 files changed

+35
-17
lines changed

7 files changed

+35
-17
lines changed

code-assert/pom.xml

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@
1616
<findbugs.version>3.1.12</findbugs.version>
1717
<findsecbugs.version>1.9.0</findsecbugs.version>
1818
<pmd.version>5.8.1</pmd.version>
19-
<kotlin.version>1.3.41</kotlin.version>
20-
<detekt.version>1.0.0-RC14</detekt.version>
21-
<ktlint.version>0.31.0</ktlint.version>
19+
<kotlin.version>1.3.71</kotlin.version>
20+
<detekt.version>1.9.1</detekt.version>
21+
<ktlint.version>0.36.0</ktlint.version>
2222
</properties>
2323

2424
<build>
@@ -87,7 +87,7 @@
8787
<dependency>
8888
<groupId>guru.nidi</groupId>
8989
<artifactId>graphviz-java</artifactId>
90-
<version>0.15.1</version>
90+
<version>0.16.1</version>
9191
</dependency>
9292
<dependency>
9393
<groupId>org.hamcrest</groupId>
@@ -137,6 +137,11 @@
137137
<version>${kotlin.version}</version>
138138
<scope>provided</scope>
139139
</dependency>
140+
<dependency>
141+
<groupId>org.jetbrains.kotlin</groupId>
142+
<artifactId>kotlin-compiler-embeddable</artifactId>
143+
<version>${kotlin.version}</version>
144+
</dependency>
140145

141146
<dependency>
142147
<groupId>io.gitlab.arturbosch.detekt</groupId>
@@ -150,12 +155,12 @@
150155
</dependency>
151156

152157
<dependency>
153-
<groupId>com.github.shyiko.ktlint</groupId>
158+
<groupId>com.pinterest.ktlint</groupId>
154159
<artifactId>ktlint-core</artifactId>
155160
<version>${ktlint.version}</version>
156161
</dependency>
157162
<dependency>
158-
<groupId>com.github.shyiko.ktlint</groupId>
163+
<groupId>com.pinterest.ktlint</groupId>
159164
<artifactId>ktlint-ruleset-standard</artifactId>
160165
<version>${ktlint.version}</version>
161166
</dependency>

code-assert/src/main/java/guru/nidi/codeassert/detekt/DetektAnalyzer.java

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,10 @@
1919
import guru.nidi.codeassert.config.AnalyzerConfig;
2020
import guru.nidi.codeassert.config.UsageCounter;
2121
import io.gitlab.arturbosch.detekt.api.*;
22+
import io.gitlab.arturbosch.detekt.api.internal.YamlConfig;
2223
import io.gitlab.arturbosch.detekt.core.*;
24+
import org.jetbrains.kotlin.config.JvmTarget;
25+
import org.jetbrains.kotlin.config.LanguageVersion;
2326
import org.slf4j.Logger;
2427
import org.slf4j.LoggerFactory;
2528

@@ -33,6 +36,7 @@
3336
import static io.gitlab.arturbosch.detekt.api.Severity.*;
3437
import static java.util.Arrays.asList;
3538
import static java.util.Collections.emptyList;
39+
import static java.util.Collections.singletonList;
3640
import static java.util.stream.Collectors.toList;
3741

3842
public class DetektAnalyzer implements Analyzer<List<TypedDetektFinding>> {
@@ -75,8 +79,9 @@ public DetektResult analyze() {
7579
try {
7680
final PrintStream printStream = new PrintStream(new LoggingOutputStream(), true, "utf-8");
7781
final ProcessingSettings settings = new ProcessingSettings(
78-
baseDir.toPath(), calcDetektConfig(), emptyList(), false, false, emptyList(),
79-
Executors.newSingleThreadExecutor(), printStream, printStream);
82+
singletonList(baseDir.toPath()), calcDetektConfig(), null, false, false, emptyList(), emptyList(),
83+
LanguageVersion.KOTLIN_1_3, JvmTarget.JVM_1_8, Executors.newSingleThreadExecutor(),
84+
printStream, printStream, false, false, emptyList());
8085
final DetektFacade df = DetektFacade.Companion.create(settings, ruleSetProviders(settings), emptyList());
8186
return createResult(baseDir, df.run());
8287
} catch (UnsupportedEncodingException e) {
@@ -130,6 +135,11 @@ public <T> T valueOrDefault(String s, T t) {
130135
public <T> T valueOrNull(String s) {
131136
return "autoCorrect".equals(s) ? (T) Boolean.FALSE : delegate.valueOrNull(s);
132137
}
138+
139+
@Override
140+
public String getParentPath() {
141+
return delegate.getParentPath();
142+
}
133143
}
134144

135145
private static class LoggingOutputStream extends OutputStream {

code-assert/src/main/java/guru/nidi/codeassert/ktlint/KtlintAnalyzer.java

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,12 @@
1515
*/
1616
package guru.nidi.codeassert.ktlint;
1717

18-
import com.github.shyiko.ktlint.core.*;
18+
import com.pinterest.ktlint.core.*;
1919
import guru.nidi.codeassert.Analyzer;
2020
import guru.nidi.codeassert.config.AnalyzerConfig;
2121
import guru.nidi.codeassert.config.UsageCounter;
2222
import kotlin.Unit;
23-
import kotlin.jvm.functions.Function1;
23+
import kotlin.jvm.functions.Function2;
2424
import org.slf4j.Logger;
2525
import org.slf4j.LoggerFactory;
2626

@@ -31,6 +31,7 @@
3131
import static java.nio.charset.StandardCharsets.UTF_8;
3232
import static java.util.Arrays.asList;
3333
import static java.util.Collections.emptyList;
34+
import static java.util.Collections.emptyMap;
3435
import static java.util.stream.Collectors.toList;
3536

3637
public class KtlintAnalyzer implements Analyzer<List<LocatedLintError>> {
@@ -61,7 +62,9 @@ public KtlintResult analyze() {
6162
for (final File src : config.getSources(KOTLIN)) {
6263
try {
6364
listener.currentFile = src;
64-
KtLint.INSTANCE.lint(readFile(src), findRuleSets(), listener);
65+
KtLint.INSTANCE.lint(new KtLint.Params(
66+
src.getAbsolutePath(), readFile(src), findRuleSets(),
67+
emptyMap(), listener, false, null, false));
6568
} catch (IOException e) {
6669
LOG.error("Could not read file {}", src, e);
6770
}
@@ -106,12 +109,12 @@ private KtlintResult createResult(ErrorListener listener) {
106109
return new KtlintResult(this, errors, collector.unusedActions(counter));
107110
}
108111

109-
private static class ErrorListener implements Function1<LintError, Unit> {
112+
private static class ErrorListener implements Function2<LintError, Boolean, Unit> {
110113
final List<LocatedLintError> errors = new ArrayList<>();
111114
File currentFile;
112115

113116
@Override
114-
public Unit invoke(LintError e) {
117+
public Unit invoke(LintError e, Boolean corrected) {
115118
errors.add(new LocatedLintError(currentFile, e.getLine(), e.getRuleId(), e.getDetail()));
116119
return null;
117120
}

code-assert/src/test/java/guru/nidi/codeassert/EatYourOwnDogfoodTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ class GuruNidiCodeassert extends DependencyRuler {
6161
DependencyRule checkstyleLib = denyRule("com.puppycrawl.tools.checkstyle").andAllSub();
6262
DependencyRule detektLib = denyRule("io.gitlab.arturbosch.detekt").andAllSub();
6363
DependencyRule findBugsLib = denyRule("edu.umd.cs.findbugs").andAllSub();
64-
DependencyRule ktlintLib = denyRule("com.github.shyiko.ktlint").andAllSub();
64+
DependencyRule ktlintLib = denyRule("com.pinterest.ktlint").andAllSub();
6565
DependencyRule pmdLib = denyRule("net.sourceforge.pmd").andAllSub();
6666
DependencyRule graphvizLib = denyRule("guru.nidi.graphviz").andAllSub();
6767
DependencyRule config, dependency, findbugs, checkstyle, detekt, io, model, pmd, ktlint, util, junit, junitKotlin, jacoco;

code-assert/src/test/java/guru/nidi/codeassert/detekt/DetektAnalyzerTest.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,7 @@ void analyze() {
3939
.just(In.classes("Linker").ignore("MaxLineLength")))
4040
.analyze();
4141
assertMatcher(""
42-
+ line(Style, "style", "NewLineAtEndOfFile", "Linker", 59, "Checks whether files end with a line separator.")
43-
+ line(Style, "style", "WildcardImport", "Linker", 19, "Wildcard imports should be replaced with imports using fully qualified class names. Wildcard imports can lead to naming conflicts. A library update can introduce naming clashes with your classes which results in compilation errors."),
42+
+ line(Style, "style", "NewLineAtEndOfFile", "Linker", 59, "Checks whether files end with a line separator."),
4443
result, hasNoDetektIssues());
4544
}
4645

code-assert/src/test/java/guru/nidi/codeassert/ktlint/KtlintAnalyzerTest.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ void analyze() {
3636
final KtlintResult result = new KtlintAnalyzer(AnalyzerConfig.maven(KOTLIN).test(), new KtlintCollector()
3737
.just(In.classes("Linker").ignore("no-semi"))).analyze();
3838
assertMatcher(""
39+
+ line("import-ordering", "Linker", 18, "Imports must be ordered in lexicographic order without any empty lines in-between")
3940
+ line("no-consecutive-blank-lines", "Linker", 34, "Needless blank line(s)")
4041
+ line("no-unused-imports", "Linker", 18, "Unused import")
4142
+ line("no-wildcard-imports", "Linker", 19, "Wildcard import"),

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<parent>
77
<groupId>guru.nidi</groupId>
88
<artifactId>guru-nidi-parent-pom</artifactId>
9-
<version>1.1.28</version>
9+
<version>1.1.30</version>
1010
<relativePath />
1111
</parent>
1212

0 commit comments

Comments
 (0)