From d8a8c7ae0d0ccb63fc7c6e955dea7713392f8fbe Mon Sep 17 00:00:00 2001 From: Stanley Shyiko Date: Tue, 6 Jun 2017 10:57:30 -0700 Subject: [PATCH 01/13] Fixed #54 - if `getValue` is declared as an extension method ktlint thinks its unused --- .../shyiko/ktlint/ruleset/standard/NoUnusedImportsRule.kt | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/ktlint-ruleset-standard/src/main/kotlin/com/github/shyiko/ktlint/ruleset/standard/NoUnusedImportsRule.kt b/ktlint-ruleset-standard/src/main/kotlin/com/github/shyiko/ktlint/ruleset/standard/NoUnusedImportsRule.kt index 063177d306..747c63d49a 100644 --- a/ktlint-ruleset-standard/src/main/kotlin/com/github/shyiko/ktlint/ruleset/standard/NoUnusedImportsRule.kt +++ b/ktlint-ruleset-standard/src/main/kotlin/com/github/shyiko/ktlint/ruleset/standard/NoUnusedImportsRule.kt @@ -32,7 +32,9 @@ class NoUnusedImportsRule : Rule("no-unused-imports") { // comparison "compareTo", // iteration (https://github.com/shyiko/ktlint/issues/40) - "iterator" + "iterator", + // by (https://github.com/shyiko/ktlint/issues/54) + "getValue" ) private val ref = mutableSetOf("*") private var packageName = "" From 9e11dcecc8e0481e3fa2f8291c8c0440911a9a7e Mon Sep 17 00:00:00 2001 From: Stanley Shyiko Date: Tue, 6 Jun 2017 10:57:49 -0700 Subject: [PATCH 02/13] Added 0.8.2 release note --- CHANGELOG.md | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index e2a37730d9..6cf622b996 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,12 @@ All notable changes to this project will be documented in this file. This project adheres to [Semantic Versioning](http://semver.org/). +## [0.8.2] - 2017-06-06 + +### Fixed + +- "Unused import" false positive (`getValue`) ([#54](https://github.com/shyiko/ktlint/issues/54)). + ## [0.8.1] - 2017-05-30 ### Fixed @@ -121,6 +127,7 @@ set in `[*{kt,kts}]` section). ## 0.1.0 - 2016-07-27 +[0.8.2]: https://github.com/shyiko/ktlint/compare/0.8.1...0.8.2 [0.8.1]: https://github.com/shyiko/ktlint/compare/0.8.0...0.8.1 [0.8.0]: https://github.com/shyiko/ktlint/compare/0.7.1...0.8.0 [0.7.1]: https://github.com/shyiko/ktlint/compare/0.7.0...0.7.1 From 0a3468936f655e56b86284e94d8631c73a31abcb Mon Sep 17 00:00:00 2001 From: abosch Date: Wed, 7 Jun 2017 15:35:55 +0200 Subject: [PATCH 03/13] Add test cases for spacing after setter and getter --- .../standard/SpacingAroundKeywordRuleTest.kt | 44 ++++++++++++++++++- 1 file changed, 43 insertions(+), 1 deletion(-) diff --git a/ktlint-ruleset-standard/src/test/kotlin/com/github/shyiko/ktlint/ruleset/standard/SpacingAroundKeywordRuleTest.kt b/ktlint-ruleset-standard/src/test/kotlin/com/github/shyiko/ktlint/ruleset/standard/SpacingAroundKeywordRuleTest.kt index 073df23c88..e41d365b02 100644 --- a/ktlint-ruleset-standard/src/test/kotlin/com/github/shyiko/ktlint/ruleset/standard/SpacingAroundKeywordRuleTest.kt +++ b/ktlint-ruleset-standard/src/test/kotlin/com/github/shyiko/ktlint/ruleset/standard/SpacingAroundKeywordRuleTest.kt @@ -1,8 +1,8 @@ package com.github.shyiko.ktlint.ruleset.standard import com.github.shyiko.ktlint.core.LintError -import com.github.shyiko.ktlint.test.lint import com.github.shyiko.ktlint.test.format +import com.github.shyiko.ktlint.test.lint import org.assertj.core.api.Assertions.assertThat import org.testng.annotations.Test @@ -94,5 +94,47 @@ class SpacingAroundKeywordRuleTest { ) } + @Test + fun noSpaceAfterGetterAndSetterFunction() { + assertThat(SpacingAroundKeywordRule().format( + """ + var x: String + get () { + return "" + } + private set (value) { + x = value + } + """.trimIndent() + )).isEqualTo( + """ + var x: String + get() { + return "" + } + private set(value) { + x = value + } + """.trimIndent() + ) + } + + @Test + fun visibilityOrInjectProperty() { + assertThat(SpacingAroundKeywordRule().lint( + """ + var setterVisibility: String = "abc" + private set + var setterWithAnnotation: Any? = null + @Inject set + var setterOnNextLine: String + private set + (value) { setterOnNextLine = value} + """ + )).isEqualTo(listOf( + LintError(6, 11, "keyword-spacing", "Missing spacing after \"set\"") + )) + } + } From 468dcd4c4cd6fe465ab3fe33abcaaaa7699ec5ca Mon Sep 17 00:00:00 2001 From: abosch Date: Wed, 7 Jun 2017 16:01:46 +0200 Subject: [PATCH 04/13] Implement spacing after setter and getter --- .../standard/SpacingAroundKeywordRule.kt | 45 ++++++++++++------- .../standard/SpacingAroundKeywordRuleTest.kt | 4 +- 2 files changed, 31 insertions(+), 18 deletions(-) diff --git a/ktlint-ruleset-standard/src/main/kotlin/com/github/shyiko/ktlint/ruleset/standard/SpacingAroundKeywordRule.kt b/ktlint-ruleset-standard/src/main/kotlin/com/github/shyiko/ktlint/ruleset/standard/SpacingAroundKeywordRule.kt index de579f225e..dd0c575374 100644 --- a/ktlint-ruleset-standard/src/main/kotlin/com/github/shyiko/ktlint/ruleset/standard/SpacingAroundKeywordRule.kt +++ b/ktlint-ruleset-standard/src/main/kotlin/com/github/shyiko/ktlint/ruleset/standard/SpacingAroundKeywordRule.kt @@ -7,6 +7,7 @@ import org.jetbrains.kotlin.com.intellij.psi.impl.source.tree.LeafPsiElement import org.jetbrains.kotlin.com.intellij.psi.impl.source.tree.PsiWhiteSpaceImpl import org.jetbrains.kotlin.com.intellij.psi.tree.TokenSet import org.jetbrains.kotlin.com.intellij.psi.util.PsiTreeUtil +import org.jetbrains.kotlin.lexer.KtTokens import org.jetbrains.kotlin.lexer.KtTokens.CATCH_KEYWORD import org.jetbrains.kotlin.lexer.KtTokens.DO_KEYWORD import org.jetbrains.kotlin.lexer.KtTokens.ELSE_KEYWORD @@ -16,32 +17,44 @@ import org.jetbrains.kotlin.lexer.KtTokens.IF_KEYWORD import org.jetbrains.kotlin.lexer.KtTokens.TRY_KEYWORD import org.jetbrains.kotlin.lexer.KtTokens.WHEN_KEYWORD import org.jetbrains.kotlin.lexer.KtTokens.WHILE_KEYWORD +import org.jetbrains.kotlin.psi.KtPropertyAccessor import org.jetbrains.kotlin.psi.KtWhenEntry +import org.jetbrains.kotlin.psi.psiUtil.nextLeaf class SpacingAroundKeywordRule : Rule("keyword-spacing") { private val noLFBeforeSet = TokenSet.create(ELSE_KEYWORD, CATCH_KEYWORD, FINALLY_KEYWORD) private val tokenSet = TokenSet.create(FOR_KEYWORD, IF_KEYWORD, ELSE_KEYWORD, WHILE_KEYWORD, DO_KEYWORD, TRY_KEYWORD, CATCH_KEYWORD, FINALLY_KEYWORD, WHEN_KEYWORD) - // todo: but not after fun(, get(, set( + + private val keywordsWithoutSpaces = TokenSet.create(KtTokens.GET_KEYWORD, KtTokens.SET_KEYWORD) override fun visit(node: ASTNode, autoCorrect: Boolean, - emit: (offset: Int, errorMessage: String, canBeAutoCorrected: Boolean) -> Unit) { - if (tokenSet.contains(node.elementType) && node is LeafPsiElement && - PsiTreeUtil.nextLeaf(node) !is PsiWhiteSpace) { - emit(node.startOffset + node.text.length, "Missing spacing after \"${node.text}\"", true) - if (autoCorrect) { - node.rawInsertAfterMe(PsiWhiteSpaceImpl(" ")) - } - } - if (noLFBeforeSet.contains(node.elementType) && node is LeafPsiElement) { - val prevLeaf = PsiTreeUtil.prevLeaf(node) - if (prevLeaf is PsiWhiteSpaceImpl && prevLeaf.textContains('\n') && - (node.elementType != ELSE_KEYWORD || node.parent !is KtWhenEntry) && - (PsiTreeUtil.prevLeaf(prevLeaf)?.textMatches("}") ?: false)) { - emit(node.startOffset, "Unexpected newline before \"${node.text}\"", true) + emit: (offset: Int, errorMessage: String, canBeAutoCorrected: Boolean) -> Unit) { + + if (node is LeafPsiElement) { + if (tokenSet.contains(node.elementType) && node.nextLeaf() !is PsiWhiteSpace) { + emit(node.startOffset + node.text.length, "Missing spacing after \"${node.text}\"", true) if (autoCorrect) { - prevLeaf.rawReplaceWithText(" ") + node.rawInsertAfterMe(PsiWhiteSpaceImpl(" ")) + } + } else if (keywordsWithoutSpaces.contains(node.elementType) && node.nextLeaf() is PsiWhiteSpace) { + val parent = node.parent + if (parent is KtPropertyAccessor && parent.hasBody()) { + emit(node.startOffset, "Unexpected spacing after \"${node.text}\"", true) + if (autoCorrect) { + node.nextLeaf()?.delete() + } + } + } else if (noLFBeforeSet.contains(node.elementType)) { + val prevLeaf = PsiTreeUtil.prevLeaf(node) + if (prevLeaf is PsiWhiteSpaceImpl && prevLeaf.textContains('\n') && + (node.elementType != ELSE_KEYWORD || node.parent !is KtWhenEntry) && + (PsiTreeUtil.prevLeaf(prevLeaf)?.textMatches("}") ?: false)) { + emit(node.startOffset, "Unexpected newline before \"${node.text}\"", true) + if (autoCorrect) { + prevLeaf.rawReplaceWithText(" ") + } } } } diff --git a/ktlint-ruleset-standard/src/test/kotlin/com/github/shyiko/ktlint/ruleset/standard/SpacingAroundKeywordRuleTest.kt b/ktlint-ruleset-standard/src/test/kotlin/com/github/shyiko/ktlint/ruleset/standard/SpacingAroundKeywordRuleTest.kt index e41d365b02..232eeb3145 100644 --- a/ktlint-ruleset-standard/src/test/kotlin/com/github/shyiko/ktlint/ruleset/standard/SpacingAroundKeywordRuleTest.kt +++ b/ktlint-ruleset-standard/src/test/kotlin/com/github/shyiko/ktlint/ruleset/standard/SpacingAroundKeywordRuleTest.kt @@ -95,7 +95,7 @@ class SpacingAroundKeywordRuleTest { } @Test - fun noSpaceAfterGetterAndSetterFunction() { + fun getterAndSetterFunction() { assertThat(SpacingAroundKeywordRule().format( """ var x: String @@ -132,7 +132,7 @@ class SpacingAroundKeywordRuleTest { (value) { setterOnNextLine = value} """ )).isEqualTo(listOf( - LintError(6, 11, "keyword-spacing", "Missing spacing after \"set\"") + LintError(7, 21, "keyword-spacing", "Unexpected spacing after \"set\"") )) } From adbbc3d60dad9cb18faa88d97e1f0a747dce65d1 Mon Sep 17 00:00:00 2001 From: abosch Date: Wed, 7 Jun 2017 20:46:50 +0200 Subject: [PATCH 05/13] Fix regression for spacing around else keyword --- .../shyiko/ktlint/ruleset/standard/SpacingAroundKeywordRule.kt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/ktlint-ruleset-standard/src/main/kotlin/com/github/shyiko/ktlint/ruleset/standard/SpacingAroundKeywordRule.kt b/ktlint-ruleset-standard/src/main/kotlin/com/github/shyiko/ktlint/ruleset/standard/SpacingAroundKeywordRule.kt index dd0c575374..560e50d7c0 100644 --- a/ktlint-ruleset-standard/src/main/kotlin/com/github/shyiko/ktlint/ruleset/standard/SpacingAroundKeywordRule.kt +++ b/ktlint-ruleset-standard/src/main/kotlin/com/github/shyiko/ktlint/ruleset/standard/SpacingAroundKeywordRule.kt @@ -46,7 +46,8 @@ class SpacingAroundKeywordRule : Rule("keyword-spacing") { node.nextLeaf()?.delete() } } - } else if (noLFBeforeSet.contains(node.elementType)) { + } + if (noLFBeforeSet.contains(node.elementType)) { val prevLeaf = PsiTreeUtil.prevLeaf(node) if (prevLeaf is PsiWhiteSpaceImpl && prevLeaf.textContains('\n') && (node.elementType != ELSE_KEYWORD || node.parent !is KtWhenEntry) && From 29effae81a2f6d90fee4c529129ac1be72d2aa16 Mon Sep 17 00:00:00 2001 From: Stanley Shyiko Date: Mon, 19 Jun 2017 13:25:40 -0700 Subject: [PATCH 06/13] Fixed #59 - Semicolon at end of package declaration not reported, different error instead --- .../shyiko/ktlint/ruleset/standard/NoSemicolonsRule.kt | 4 ++-- .../ktlint/ruleset/standard/SpacingAroundCommaRule.kt | 2 +- .../shyiko/ktlint/ruleset/standard/NoSemicolonsRuleTest.kt | 7 +++++-- 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/ktlint-ruleset-standard/src/main/kotlin/com/github/shyiko/ktlint/ruleset/standard/NoSemicolonsRule.kt b/ktlint-ruleset-standard/src/main/kotlin/com/github/shyiko/ktlint/ruleset/standard/NoSemicolonsRule.kt index f08d500f13..804b37ce2c 100644 --- a/ktlint-ruleset-standard/src/main/kotlin/com/github/shyiko/ktlint/ruleset/standard/NoSemicolonsRule.kt +++ b/ktlint-ruleset-standard/src/main/kotlin/com/github/shyiko/ktlint/ruleset/standard/NoSemicolonsRule.kt @@ -14,10 +14,10 @@ class NoSemicolonsRule : Rule("no-semi") { emit: (offset: Int, errorMessage: String, canBeAutoCorrected: Boolean) -> Unit) { if (node is LeafPsiElement && node.textMatches(";") && !node.isPartOfString() && !node.isPartOf(KtEnumEntry::class)) { - val nextLeaf = PsiTreeUtil.nextLeaf(node) + val nextLeaf = PsiTreeUtil.nextLeaf(node, true) if (nextLeaf == null /* eof */ || (nextLeaf is PsiWhiteSpace && (nextLeaf.text.contains("\n") || - PsiTreeUtil.nextLeaf(nextLeaf) == null /* \s+ and then eof */)) + PsiTreeUtil.nextLeaf(nextLeaf, true) == null /* \s+ and then eof */)) ) { emit(node.startOffset, "Unnecessary semicolon", true) if (autoCorrect) { diff --git a/ktlint-ruleset-standard/src/main/kotlin/com/github/shyiko/ktlint/ruleset/standard/SpacingAroundCommaRule.kt b/ktlint-ruleset-standard/src/main/kotlin/com/github/shyiko/ktlint/ruleset/standard/SpacingAroundCommaRule.kt index f2a867c445..fa0f2f361c 100644 --- a/ktlint-ruleset-standard/src/main/kotlin/com/github/shyiko/ktlint/ruleset/standard/SpacingAroundCommaRule.kt +++ b/ktlint-ruleset-standard/src/main/kotlin/com/github/shyiko/ktlint/ruleset/standard/SpacingAroundCommaRule.kt @@ -11,7 +11,7 @@ class SpacingAroundCommaRule : Rule("comma-spacing") { override fun visit(node: ASTNode, autoCorrect: Boolean, emit: (offset: Int, errorMessage: String, canBeAutoCorrected: Boolean) -> Unit) { - if (node is LeafPsiElement && (node.textMatches(",") || node.textMatches(";")) && !node.isPartOfString() && + if (node is LeafPsiElement && node.textMatches(",") && !node.isPartOfString() && PsiTreeUtil.nextLeaf(node) !is PsiWhiteSpace) { emit(node.startOffset + 1, "Missing spacing after \"${node.text}\"", true) if (autoCorrect) { diff --git a/ktlint-ruleset-standard/src/test/kotlin/com/github/shyiko/ktlint/ruleset/standard/NoSemicolonsRuleTest.kt b/ktlint-ruleset-standard/src/test/kotlin/com/github/shyiko/ktlint/ruleset/standard/NoSemicolonsRuleTest.kt index 4d4ab29ea6..923320e926 100644 --- a/ktlint-ruleset-standard/src/test/kotlin/com/github/shyiko/ktlint/ruleset/standard/NoSemicolonsRuleTest.kt +++ b/ktlint-ruleset-standard/src/test/kotlin/com/github/shyiko/ktlint/ruleset/standard/NoSemicolonsRuleTest.kt @@ -1,8 +1,8 @@ package com.github.shyiko.ktlint.ruleset.standard import com.github.shyiko.ktlint.core.LintError -import com.github.shyiko.ktlint.test.lint import com.github.shyiko.ktlint.test.format +import com.github.shyiko.ktlint.test.lint import org.assertj.core.api.Assertions.assertThat import org.testng.annotations.Test @@ -12,6 +12,8 @@ class NoSemicolonsRuleTest { fun testLint() { assertThat(NoSemicolonsRule().lint( """ + package a.b.c; + fun main() { fun name() { a(); return b } println(";") @@ -19,7 +21,8 @@ class NoSemicolonsRuleTest { } """.trimIndent() )).isEqualTo(listOf( - LintError(4, 14, "no-semi", "Unnecessary semicolon") + LintError(1, 14, "no-semi", "Unnecessary semicolon"), + LintError(6, 14, "no-semi", "Unnecessary semicolon") )) } From 9322a1f4dc4f5043a9425796d02938ffea1d956d Mon Sep 17 00:00:00 2001 From: Stanley Shyiko Date: Mon, 19 Jun 2017 13:26:08 -0700 Subject: [PATCH 07/13] Fixed #55 - If `setValue` is declared as an extension method ktlint thinks its unused --- .../shyiko/ktlint/ruleset/standard/NoUnusedImportsRule.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ktlint-ruleset-standard/src/main/kotlin/com/github/shyiko/ktlint/ruleset/standard/NoUnusedImportsRule.kt b/ktlint-ruleset-standard/src/main/kotlin/com/github/shyiko/ktlint/ruleset/standard/NoUnusedImportsRule.kt index 747c63d49a..8c5dd8b76d 100644 --- a/ktlint-ruleset-standard/src/main/kotlin/com/github/shyiko/ktlint/ruleset/standard/NoUnusedImportsRule.kt +++ b/ktlint-ruleset-standard/src/main/kotlin/com/github/shyiko/ktlint/ruleset/standard/NoUnusedImportsRule.kt @@ -34,7 +34,7 @@ class NoUnusedImportsRule : Rule("no-unused-imports") { // iteration (https://github.com/shyiko/ktlint/issues/40) "iterator", // by (https://github.com/shyiko/ktlint/issues/54) - "getValue" + "getValue", "setValue" ) private val ref = mutableSetOf("*") private var packageName = "" From 170f494591f62164922dce62cea43bc3375da5d8 Mon Sep 17 00:00:00 2001 From: Stanley Shyiko Date: Mon, 19 Jun 2017 13:33:15 -0700 Subject: [PATCH 08/13] Added 0.8.3 release note(s) --- CHANGELOG.md | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6cf622b996..55665c7084 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,14 @@ All notable changes to this project will be documented in this file. This project adheres to [Semantic Versioning](http://semver.org/). +## [0.8.3] - 2017-06-19 + +### Fixed + +- "Missing spacing after ";"" at the end of package declaration ([#59](https://github.com/shyiko/ktlint/issues/59)). +- "Unused import" false positive (`setValue`) ([#55](https://github.com/shyiko/ktlint/issues/55)). +- `get`/`set`ter spacing ([#56](https://github.com/shyiko/ktlint/pull/56)). + ## [0.8.2] - 2017-06-06 ### Fixed @@ -127,6 +135,7 @@ set in `[*{kt,kts}]` section). ## 0.1.0 - 2016-07-27 +[0.8.3]: https://github.com/shyiko/ktlint/compare/0.8.2...0.8.3 [0.8.2]: https://github.com/shyiko/ktlint/compare/0.8.1...0.8.2 [0.8.1]: https://github.com/shyiko/ktlint/compare/0.8.0...0.8.1 [0.8.0]: https://github.com/shyiko/ktlint/compare/0.7.1...0.8.0 From f1d38e9ae808b67938070d8b6f8c98f0f3ab6c15 Mon Sep 17 00:00:00 2001 From: Jeremy Mailen Date: Thu, 22 Jun 2017 22:59:59 -0700 Subject: [PATCH 09/13] Fix misleading indent lint error message **Why** The error message was hardcoded to 4 so read incorrectly when a custom indent size was used. --- .../ktlint/ruleset/standard/IndentationRule.kt | 4 ++-- .../ktlint/ruleset/standard/IndentationRuleTest.kt | 14 ++++++++++++++ 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/ktlint-ruleset-standard/src/main/kotlin/com/github/shyiko/ktlint/ruleset/standard/IndentationRule.kt b/ktlint-ruleset-standard/src/main/kotlin/com/github/shyiko/ktlint/ruleset/standard/IndentationRule.kt index a385dc2275..47a85aa4e4 100644 --- a/ktlint-ruleset-standard/src/main/kotlin/com/github/shyiko/ktlint/ruleset/standard/IndentationRule.kt +++ b/ktlint-ruleset-standard/src/main/kotlin/com/github/shyiko/ktlint/ruleset/standard/IndentationRule.kt @@ -50,11 +50,11 @@ class IndentationRule : Rule("indent") { if (node.isPartOf(KtParameterList::class) && firstParameterColumn.value != 0) { if (firstParameterColumn.value - 1 != it.length) { emit(offset, "Unexpected indentation (${it.length}) (" + - "parameters should be either vertically aligned or indented by the multiple of 4" + + "parameters should be either vertically aligned or indented by the multiple of $indent" + ")", false) } } else { - emit(offset, "Unexpected indentation (${it.length}) (it should be multiple of 4)", false) + emit(offset, "Unexpected indentation (${it.length}) (it should be multiple of $indent)", false) } } offset += it.length + 1 diff --git a/ktlint-ruleset-standard/src/test/kotlin/com/github/shyiko/ktlint/ruleset/standard/IndentationRuleTest.kt b/ktlint-ruleset-standard/src/test/kotlin/com/github/shyiko/ktlint/ruleset/standard/IndentationRuleTest.kt index 06cad0c4c2..b3c80a636a 100644 --- a/ktlint-ruleset-standard/src/test/kotlin/com/github/shyiko/ktlint/ruleset/standard/IndentationRuleTest.kt +++ b/ktlint-ruleset-standard/src/test/kotlin/com/github/shyiko/ktlint/ruleset/standard/IndentationRuleTest.kt @@ -99,4 +99,18 @@ class IndentationRuleTest { )).isEmpty() } + @Test + fun testErrorWithCustomIndentSize() { + assertThat(IndentationRule().lint( + """ + fun main() { + val v = "" + println(v) + } + """.trimIndent(), + mapOf("indent_size" to "3") + )).isEqualTo(listOf( + LintError(3, 1, "indent", "Unexpected indentation (4) (it should be multiple of 3)") + )) + } } From 5d2febe89607d47d13b3ccabd3ef47a58e280d4c Mon Sep 17 00:00:00 2001 From: Adam Markon Date: Fri, 30 Jun 2017 10:11:48 -0400 Subject: [PATCH 10/13] allow for named lambdas --- .../shyiko/ktlint/ruleset/standard/SpacingAroundCurlyRule.kt | 2 +- .../ktlint/ruleset/standard/SpacingAroundCurlyRuleTest.kt | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/ktlint-ruleset-standard/src/main/kotlin/com/github/shyiko/ktlint/ruleset/standard/SpacingAroundCurlyRule.kt b/ktlint-ruleset-standard/src/main/kotlin/com/github/shyiko/ktlint/ruleset/standard/SpacingAroundCurlyRule.kt index 3a1998e89c..7a524f8a51 100644 --- a/ktlint-ruleset-standard/src/main/kotlin/com/github/shyiko/ktlint/ruleset/standard/SpacingAroundCurlyRule.kt +++ b/ktlint-ruleset-standard/src/main/kotlin/com/github/shyiko/ktlint/ruleset/standard/SpacingAroundCurlyRule.kt @@ -20,7 +20,7 @@ class SpacingAroundCurlyRule : Rule("curly-spacing") { val spacingBefore: Boolean val spacingAfter: Boolean if (node.textMatches("{")) { - spacingBefore = prevLeaf is PsiWhiteSpace || (prevLeaf?.node?.elementType == KtTokens.LPAR && + spacingBefore = prevLeaf is PsiWhiteSpace || prevLeaf is KtTokens.AT || (prevLeaf?.node?.elementType == KtTokens.LPAR && (node.parent is KtLambdaExpression || node.parent.parent is KtLambdaExpression)) spacingAfter = nextLeaf is PsiWhiteSpace || nextLeaf?.node?.elementType == KtTokens.RBRACE } else diff --git a/ktlint-ruleset-standard/src/test/kotlin/com/github/shyiko/ktlint/ruleset/standard/SpacingAroundCurlyRuleTest.kt b/ktlint-ruleset-standard/src/test/kotlin/com/github/shyiko/ktlint/ruleset/standard/SpacingAroundCurlyRuleTest.kt index bc7f6b405f..2dc3c6b56c 100644 --- a/ktlint-ruleset-standard/src/test/kotlin/com/github/shyiko/ktlint/ruleset/standard/SpacingAroundCurlyRuleTest.kt +++ b/ktlint-ruleset-standard/src/test/kotlin/com/github/shyiko/ktlint/ruleset/standard/SpacingAroundCurlyRuleTest.kt @@ -1,8 +1,8 @@ package com.github.shyiko.ktlint.ruleset.standard import com.github.shyiko.ktlint.core.LintError -import com.github.shyiko.ktlint.test.lint import com.github.shyiko.ktlint.test.format +import com.github.shyiko.ktlint.test.lint import org.assertj.core.api.Assertions.assertThat import org.testng.annotations.Test @@ -11,6 +11,7 @@ class SpacingAroundCurlyRuleTest { @Test fun testLint() { assertThat(SpacingAroundCurlyRule().lint("fun emit() { }")).isEmpty() + assertThat(SpacingAroundCurlyRule().lint("fun emit() { val a = a@{ } }")).isEmpty() assertThat(SpacingAroundCurlyRule().lint("fun emit() {}")).isEmpty() assertThat(SpacingAroundCurlyRule().lint("fun main() { val v = if (true){return 0} }")) .isEqualTo(listOf( From ef3f436951508aaed61871d6f6922e8c707fdda7 Mon Sep 17 00:00:00 2001 From: Adam Markon Date: Fri, 30 Jun 2017 11:35:53 -0400 Subject: [PATCH 11/13] :facepalm: --- .../shyiko/ktlint/ruleset/standard/SpacingAroundCurlyRule.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ktlint-ruleset-standard/src/main/kotlin/com/github/shyiko/ktlint/ruleset/standard/SpacingAroundCurlyRule.kt b/ktlint-ruleset-standard/src/main/kotlin/com/github/shyiko/ktlint/ruleset/standard/SpacingAroundCurlyRule.kt index 7a524f8a51..ca7e8cd6f6 100644 --- a/ktlint-ruleset-standard/src/main/kotlin/com/github/shyiko/ktlint/ruleset/standard/SpacingAroundCurlyRule.kt +++ b/ktlint-ruleset-standard/src/main/kotlin/com/github/shyiko/ktlint/ruleset/standard/SpacingAroundCurlyRule.kt @@ -20,7 +20,7 @@ class SpacingAroundCurlyRule : Rule("curly-spacing") { val spacingBefore: Boolean val spacingAfter: Boolean if (node.textMatches("{")) { - spacingBefore = prevLeaf is PsiWhiteSpace || prevLeaf is KtTokens.AT || (prevLeaf?.node?.elementType == KtTokens.LPAR && + spacingBefore = prevLeaf is PsiWhiteSpace || prevLeaf?.node?.elementType == KtTokens.AT || (prevLeaf?.node?.elementType == KtTokens.LPAR && (node.parent is KtLambdaExpression || node.parent.parent is KtLambdaExpression)) spacingAfter = nextLeaf is PsiWhiteSpace || nextLeaf?.node?.elementType == KtTokens.RBRACE } else From e1df15cefd031082a78f80c6b57af2d688a087bd Mon Sep 17 00:00:00 2001 From: Jeremy Mailen Date: Wed, 5 Jul 2017 22:36:18 -0700 Subject: [PATCH 12/13] Upgrade to kotlin 1.1.3-2 --- .../src/main/kotlin/com/github/shyiko/ktlint/core/KtLint.kt | 3 ++- pom.xml | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/ktlint-core/src/main/kotlin/com/github/shyiko/ktlint/core/KtLint.kt b/ktlint-core/src/main/kotlin/com/github/shyiko/ktlint/core/KtLint.kt index edf62569df..c8d15ea3dc 100644 --- a/ktlint-core/src/main/kotlin/com/github/shyiko/ktlint/core/KtLint.kt +++ b/ktlint-core/src/main/kotlin/com/github/shyiko/ktlint/core/KtLint.kt @@ -1,5 +1,6 @@ package com.github.shyiko.ktlint.core +import org.jetbrains.kotlin.cli.jvm.compiler.EnvironmentConfigFiles import org.jetbrains.kotlin.cli.jvm.compiler.KotlinCoreEnvironment import org.jetbrains.kotlin.com.intellij.lang.ASTNode import org.jetbrains.kotlin.com.intellij.mock.MockProject @@ -37,7 +38,7 @@ object KtLint { init { val project = KotlinCoreEnvironment.createForProduction(Disposable {}, - CompilerConfiguration(), emptyList()).project + CompilerConfiguration(), EnvironmentConfigFiles.EMPTY).project // everything below (up to PsiFileFactory.getInstance(...)) is to get AST mutations (`ktlint -F ...`) working // otherwise it's not needed val pomModel: PomModel = object : UserDataHolderBase(), PomModel { diff --git a/pom.xml b/pom.xml index 26af458aca..46c5d80afe 100644 --- a/pom.xml +++ b/pom.xml @@ -40,7 +40,7 @@ UTF-8 - 1.1.0 + 1.1.3-2 1.1.0 3.2.5 2.33 From 19ab11d365b6a0a49a3aa15c6d4cdb4f28b8acf3 Mon Sep 17 00:00:00 2001 From: Jeremy Mailen Date: Wed, 5 Jul 2017 22:54:10 -0700 Subject: [PATCH 13/13] CI with JDK 8 --- .travis.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.travis.yml b/.travis.yml index f176e570d7..108bf07b24 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,2 +1,4 @@ language: java +jdk: + - oraclejdk8 script: ./mvnw clean verify