Skip to content

Commit

Permalink
Do not enforce raw strings opening quote to be on a separate line
Browse files Browse the repository at this point in the history
  • Loading branch information
romtsn committed Aug 22, 2020
1 parent 56e0ce2 commit 12e079f
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 24 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ This project adheres to [Semantic Versioning](http://semver.org/).

## Unreleased

-
### Fixed
- Do not enforce raw strings opening quote to be on a separate line ([#711](https://github.com/pinterest/ktlint/issues/711))

## [0.38.0] - 2020-08-21

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,6 @@ class IndentationRule : Rule("indent"), Rule.Modifier.RestrictToRootLast {
LPAR, LBRACE, LBRACKET -> rearrangeBlock(n, autoCorrect, emit) // TODO: LT
SUPER_TYPE_LIST -> rearrangeSuperTypeList(n, autoCorrect, emit)
VALUE_PARAMETER_LIST, VALUE_ARGUMENT_LIST -> rearrangeValueList(n, autoCorrect, emit)
EQ -> rearrangeEq(n, autoCorrect, emit)
ARROW -> rearrangeArrow(n, autoCorrect, emit)
WHITE_SPACE -> line += n.text.count { it == '\n' }
}
Expand Down Expand Up @@ -328,25 +327,6 @@ class IndentationRule : Rule("indent"), Rule.Modifier.RestrictToRootLast {
}
}

private fun rearrangeEq(
node: ASTNode,
autoCorrect: Boolean,
emit: (offset: Int, errorMessage: String, canBeAutoCorrected: Boolean) -> Unit
) {
// force """ to be on a separate line
if (!node.nextCodeLeaf().isRawString()) {
return
}
val nextCodeLeaf = node.nextCodeLeaf()!!
if (!nextCodeLeaf.prevLeaf().isWhiteSpaceWithNewline()) {
requireNewlineAfterLeaf(node, autoCorrect, emit)
}
}

private fun ASTNode?.isRawString(): Boolean {
return this?.elementType == OPEN_QUOTE && this.text == "\"\"\""
}

private fun mustBeFollowedByNewline(node: ASTNode): Boolean {
// find EOL token (last token before \n)
// if token is in lTokenSet
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,11 +92,10 @@ _
}

class C {
val CONFIG_COMPACT =
"""
val CONFIG_COMPACT = """
{
}
""".trimIndent()
""".trimIndent()
val CONFIG_COMPACT = // comment
"""
{
Expand Down

0 comments on commit 12e079f

Please sign in to comment.