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

Ignore tokens between backticks in rule max line length (#1007) #1008

Merged
Merged
Changes from 1 commit
Commits
Show all changes
54 commits
Select commit Hold shift + click to select a range
5234fbd
Ignore tokens between backticks in rule max line length (#1007)
Dec 12, 2020
80e62a6
Add option to ignore tokens between backticks in rule max line length…
Dec 19, 2020
a7fa11a
Fix snapshot publishing (#1009)
romtsn Dec 13, 2020
afd522d
Fix import-ordering editorconifg generation
romtsn Dec 14, 2020
2279d69
Revert to using list of PatternEntry
romtsn Dec 15, 2020
9c49a30
Introduce new writeEditorConfigProperty method and use it for import-…
romtsn Dec 16, 2020
8ed0710
Always pass file path via user data properties.
Tapchicoma Dec 16, 2020
316e407
Add clarification for IDEA setup in README (#1017)
Dec 17, 2020
b7cb8f8
ArgumentListWrappingRule: fix false positive when max_line_length in …
t-kameyama Dec 17, 2020
3f5b558
Add kotlinlang slack #ktlint channel badge.
Tapchicoma Dec 17, 2020
90021a9
Update changelog.
Tapchicoma Dec 17, 2020
dfe2dba
Deprecate shorcuts for import-ordering (#1018)
romtsn Dec 18, 2020
7f17da8
Add test for #877 (#1021)
romtsn Dec 18, 2020
81481f1
Retain the UTF8 BOM (Byte Order Mark) in case present in original cod…
paul-dingemans Dec 20, 2020
ff49b9b
Fix string-template for dot-expression from which the toString() is …
paul-dingemans Dec 21, 2020
7312732
Fix false positive when argument list is after multiline dot-qualifie…
romtsn Dec 22, 2020
477c64c
Fix indentation for function types after a newline (#1022)
romtsn Dec 23, 2020
a6c6d01
Fix indentation for lines at expected indentation level but with wron…
paul-dingemans Dec 25, 2020
d03a86a
Add Github pull request template.
Tapchicoma Dec 23, 2020
8f0542e
Add new "enhancement" issue type.
Tapchicoma Dec 23, 2020
2625576
Move to comment statement that bug may already be reported.
Tapchicoma Dec 23, 2020
80135eb
Add "New rule" issue template.
Tapchicoma Dec 23, 2020
da6305d
Update Kotlin dev version to 1.4.30-M1.
Tapchicoma Dec 27, 2020
60b1e6d
Fix new issue templates has wrong file extension.
Tapchicoma Dec 27, 2020
9f4dd89
Add to README section about IDEA .editorconfig autoformat issue.
Tapchicoma Dec 27, 2020
b1d7b8a
Add CI & Mega-Linter link in README (#1028)
nvuillam Dec 29, 2020
e1e0326
Don't remove the equals sign for a default argument (`no-line-break-b…
t-kameyama Dec 29, 2020
fa38d75
Fix internal error in `no-unused-imports` (#1044)
t-kameyama Dec 30, 2020
05c513f
Upgrade ec4j to latest version (#1042)
goodhoko Jan 10, 2021
634a8a2
Fix false positives when declaration has tail comments (`spacing-betw…
t-kameyama Jan 12, 2021
4e0a762
Fix formatting with comments (`colon-spacing`)
t-kameyama Jan 15, 2021
0022b7f
Place type on the same line with declaration name
t-kameyama Jan 16, 2021
83c3547
Fix false positive after `else` keyword (`argument-list-wrapping`)
t-kameyama Jan 15, 2021
0a3a1a6
Run CI checks addintionally on Windows OS.
Tapchicoma Jan 17, 2021
34461a2
Upload depedency verification report on build error.
Tapchicoma Jan 17, 2021
e94424e
Update Kotlin dev version to 1.4.30-RC.
Tapchicoma Jan 20, 2021
4773646
Update Gradle to 6.8.1 version.
Tapchicoma Jan 25, 2021
0bfe7e6
Mention MacPorts in readme (#1069)
amake Feb 11, 2021
22ff1a3
Fix IndexOutOfBoundsException in `argument-list-wrapping-rule` format…
t-kameyama Feb 14, 2021
53fe9ab
Fix formatting in arguments (`multiline-if-else`) (#1082)
t-kameyama Feb 15, 2021
61a5a38
Fix Kotlin compiler fails to initialize.
Tapchicoma Feb 21, 2021
545857d
Update Kotlin to 1.4.30 version.
Tapchicoma Feb 21, 2021
5d7f430
Update Kotlin dev version to 1.5.0-M2-187.
Tapchicoma Feb 21, 2021
250a3e4
Annotation spacing fix (#1087)
shashachu Feb 23, 2021
d90ef21
Fix Kotlin compiler may not in all cases be released.
Tapchicoma Feb 25, 2021
649abe3
Remove usages of jcenter().
Tapchicoma Mar 1, 2021
daa2229
Replace Klob dependency with 'walkFileTree' and 'PathMatcher'.
Tapchicoma Jan 16, 2021
57dc8bd
Update Kotlin to 1.4.31 version.
Tapchicoma Mar 7, 2021
e30be4b
Update Gradle to '6.8.3' version.
Tapchicoma Mar 7, 2021
187ca66
Use new editorconfig API for ignore_back_ticked property and make it …
romtsn Mar 7, 2021
c25fd5a
Add changelog entry
romtsn Mar 7, 2021
1015527
Merge branch 'master' into 1007-ignore-tokens-between-back-ticks
romtsn Mar 7, 2021
b07b121
Fix violations
romtsn Mar 7, 2021
72de0b0
Remove unnecessary comment
romtsn Mar 7, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Fix formatting with comments (colon-spacing)
t-kameyama authored and romtsn committed Mar 7, 2021

Unverified

This commit is not signed, but one or more authors requires that any commit attributed to them is signed.
commit 4e0a7624e6e097262e26a8bbba673bffe475b489
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -17,6 +17,7 @@ This project adheres to [Semantic Versioning](http://semver.org/).
- Don't remove the equals sign for a default argument (`no-line-break-before-assignment`) ([#1039](https://github.com/pinterest/ktlint/issues/1039))
- Fix internal error in `no-unused-imports` ([#1040](https://github.com/pinterest/ktlint/issues/1040))
- Fix false positives when declaration has tail comments (`spacing-between-declarations-with-comments`) ([#1053](https://github.com/pinterest/ktlint/issues/1053))
- Fix formatting with comments (`colon-spacing`) ([#1057](https://github.com/pinterest/ktlint/issues/1057))

### Changed
- Update Gradle shadow plugin to `6.1.0` version
Original file line number Diff line number Diff line change
@@ -6,7 +6,9 @@ import com.pinterest.ktlint.core.ast.ElementType.ANNOTATION_ENTRY
import com.pinterest.ktlint.core.ast.isPartOf
import com.pinterest.ktlint.core.ast.isPartOfComment
import com.pinterest.ktlint.core.ast.isPartOfString
import com.pinterest.ktlint.core.ast.isWhiteSpace
import com.pinterest.ktlint.core.ast.isWhiteSpaceWithNewline
import com.pinterest.ktlint.core.ast.nextLeaf
import com.pinterest.ktlint.core.ast.prevLeaf
import com.pinterest.ktlint.core.ast.upsertWhitespaceAfterMe
import com.pinterest.ktlint.core.ast.upsertWhitespaceBeforeMe
@@ -17,6 +19,7 @@ import org.jetbrains.kotlin.psi.KtClassOrObject
import org.jetbrains.kotlin.psi.KtConstructor
import org.jetbrains.kotlin.psi.KtTypeConstraint
import org.jetbrains.kotlin.psi.KtTypeParameterList
import org.jetbrains.kotlin.psi.psiUtil.prevLeafs

class SpacingAroundColonRule : Rule("colon-spacing") {

@@ -36,24 +39,31 @@ class SpacingAroundColonRule : Rule("colon-spacing") {
node.parent !is KtTypeConstraint && // where T : S
node.parent?.parent !is KtTypeParameterList
val prevLeaf = node.prevLeaf()
if (prevLeaf != null &&
prevLeaf.isWhiteSpaceWithNewline() &&
// FIXME: relocate : so that it would be in front of comment
// (see SpacingAroundColonRuleTest.testFormatEOF & ChainWrappingRule)
prevLeaf.prevLeaf()?.isPartOfComment() != true
) {
if (prevLeaf != null && prevLeaf.isWhiteSpaceWithNewline()) {
emit(prevLeaf.startOffset, "Unexpected newline before \":\"", true)
val text = prevLeaf.text
if (autoCorrect) {
if (removeSpacingBefore) {
prevLeaf.treeParent.removeChild(prevLeaf)
if (prevLeaf.prevLeaf()?.isPartOfComment() == true) {
val nextLeaf = node.nextLeaf()
val prevNonCodeLeaves =
node.prevLeafs.takeWhile { it.node.isWhiteSpace() || it.node.isPartOfComment() }.toList()
prevNonCodeLeaves.reversed().forEach {
node.treeParent.addChild(it.node, nextLeaf)
}
if (nextLeaf != null && nextLeaf.isWhiteSpace()) {
node.treeParent.removeChild(nextLeaf)
}
} else {
(prevLeaf as LeafPsiElement).rawReplaceWithText(" ")
val text = prevLeaf.text
if (removeSpacingBefore) {
prevLeaf.treeParent.removeChild(prevLeaf)
} else {
(prevLeaf as LeafPsiElement).rawReplaceWithText(" ")
}
node.upsertWhitespaceAfterMe(text)
}
node.upsertWhitespaceAfterMe(text)
}
}
if (node.prevSibling is PsiWhiteSpace && removeSpacingBefore) {
if (node.prevSibling is PsiWhiteSpace && removeSpacingBefore && !prevLeaf.isWhiteSpaceWithNewline()) {
emit(node.startOffset, "Unexpected spacing before \":\"", true)
if (autoCorrect) {
node.prevSibling.node.treeParent.removeChild(node.prevSibling.node)
Original file line number Diff line number Diff line change
@@ -248,15 +248,49 @@ class SpacingAroundColonRuleTest {
class X :
Y,
Z
class A // comment
: B
class A /*
class A : // comment
B
class A : /*

*/
: B
B
val xmlFormatter:
String = ""
""".trimIndent()
)
}

// https://github.com/pinterest/ktlint/issues/1057
@Test
fun testLintWithEolComment() {
assertThat(
SpacingAroundColonRule().lint(
"""
val x // comment
: Int = 1
""".trimIndent()
)
).isEqualTo(
listOf(
LintError(1, 17, "colon-spacing", "Unexpected newline before \":\""),
)
)
}

@Test
fun testFormatWithEolComment() {
assertThat(
SpacingAroundColonRule().format(
"""
val x // comment
: Int = 1
""".trimIndent()
)
).isEqualTo(
"""
val x: // comment
Int = 1
""".trimIndent()
)
}
}