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

IndentationRule: Do not enforce raw strings opening quote to be on a separate line #849

Merged
merged 1 commit into from
Aug 24, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
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