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

Fix indentation of the closing quotes of a multiline string literal #1262

Merged
merged 7 commits into from
Jan 22, 2022
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ This project adheres to [Semantic Versioning](https://semver.org/).
- Fix indentation of secondary constructor (`indent`) ([#1222](https://github.com/pinterest/ktlint/issues/1222))
- Fix alignment of arrow when trailing comma is missing in when entry (`trailing-comma`) ([#1312](https://github.com/pinterest/ktlint/issues/1312))
- Fix indent of delegated super type entry (`indent`) ([#1210](https://github.com/pinterest/ktlint/issues/1210))
- Improve indentation of closing quotes of a multiline raw string literal (`indent`) ([#1262](https://github.com/pinterest/ktlint/pull/1262))

### Changed
- Update Kotlin version to `1.6.0` release
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,13 @@ class BaselineReporter(val out: PrintStream) : Reporter {
} catch (e: IllegalArgumentException) {
file
}
out.println(""" <file name="${fileName.escapeXMLAttrValue()}">""")
out.println(""" <file name="${fileName.escapeXMLAttrValue()}">""")
for ((line, col, ruleId, _) in errList) {
out.println(
""" <error line="$line" column="$col" source="$ruleId" />"""
""" <error line="$line" column="$col" source="$ruleId" />"""
)
}
out.println(""" </file>""")
out.println(""" </file>""")
}
out.println("""</baseline>""")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,17 +44,18 @@ class BaselineReporterTest {
reporter.afterAll()
assertThat(String(out.toByteArray())).isEqualTo(
"""
<?xml version="1.0" encoding="utf-8"?>
<baseline version="1.0">
<file name="one-fixed-and-one-not.kt">
<error line="1" column="1" source="rule-1" />
</file>
<file name="two-not-fixed.kt">
<error line="1" column="10" source="rule-1" />
<error line="2" column="20" source="rule-2" />
</file>
</baseline>
""".trimStart().replace("\n", System.lineSeparator())
<?xml version="1.0" encoding="utf-8"?>
<baseline version="1.0">
<file name="one-fixed-and-one-not.kt">
<error line="1" column="1" source="rule-1" />
</file>
<file name="two-not-fixed.kt">
<error line="1" column="10" source="rule-1" />
<error line="2" column="20" source="rule-2" />
</file>
</baseline>

""".trimIndent().replace("\n", System.lineSeparator())
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,15 @@ class CheckStyleReporter(val out: PrintStream) : Reporter {
out.println("""<?xml version="1.0" encoding="utf-8"?>""")
out.println("""<checkstyle version="8.0">""")
for ((file, errList) in acc.entries.sortedBy { it.key }) {
out.println(""" <file name="${file.escapeXMLAttrValue()}">""")
out.println(""" <file name="${file.escapeXMLAttrValue()}">""")
for ((line, col, ruleId, detail) in errList) {
out.println(
""" <error line="$line" column="$col" severity="error" message="${
""" <error line="$line" column="$col" severity="error" message="${
detail.escapeXMLAttrValue()
}" source="$ruleId" />"""
)
}
out.println(""" </file>""")
out.println(""" </file>""")
}
out.println("""</checkstyle>""")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,17 +67,19 @@ class CheckStyleReporterTest {
reporter.afterAll()
assertThat(String(out.toByteArray())).isEqualTo(
"""
<?xml version="1.0" encoding="utf-8"?>
<checkstyle version="8.0">
<file name="/one-fixed-and-one-not.kt">
<error line="1" column="1" severity="error" message="&lt;&quot;&amp;&apos;&gt;" source="rule-1" />
</file>
<file name="/two-not-fixed.kt">
<error line="1" column="10" severity="error" message="I thought I would again" source="rule-1" />
<error line="2" column="20" severity="error" message="A single thin straight line" source="rule-2" />
</file>
</checkstyle>
""".trimStart().replace("\n", System.lineSeparator())
<?xml version="1.0" encoding="utf-8"?>
<checkstyle version="8.0">
<file name="/one-fixed-and-one-not.kt">
<error line="1" column="1" severity="error" message="&lt;&quot;&amp;&apos;&gt;" source="rule-1" />
</file>
<file name="/two-not-fixed.kt">
<error line="1" column="10" severity="error" message="I thought I would again" source="rule-1" />
<error line="2" column="20" severity="error" message="A single thin straight line" source="rule-2" />
</file>
</checkstyle>

""".trimIndent()
.replace("\n", System.lineSeparator())
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,23 +40,24 @@ class HtmlReporterTest {

val actual =
"""
<html>
<head>
<link href="https://fonts.googleapis.com/css?family=Source+Code+Pro" rel="stylesheet" />
<meta http-equiv="Content-Type" Content="text/html; Charset=UTF-8">
<style>
body {
font-family: 'Source Code Pro', monospace;
}
h3 {
font-size: 12pt;
}</style>
</head>
<body>
<p>Congratulations, no issues found!</p>
</body>
</html>
""".trimStart().replace("\n", System.lineSeparator())
<html>
<head>
<link href="https://fonts.googleapis.com/css?family=Source+Code+Pro" rel="stylesheet" />
<meta http-equiv="Content-Type" Content="text/html; Charset=UTF-8">
<style>
body {
font-family: 'Source Code Pro', monospace;
}
h3 {
font-size: 12pt;
}</style>
</head>
<body>
<p>Congratulations, no issues found!</p>
</body>
</html>

""".trimIndent().replace("\n", System.lineSeparator())

val expected = String(out.toByteArray())
assertEquals(actual, expected)
Expand All @@ -76,29 +77,31 @@ h3 {
reporter.afterAll()

val actual =
"""<html>
<head>
<link href="https://fonts.googleapis.com/css?family=Source+Code+Pro" rel="stylesheet" />
<meta http-equiv="Content-Type" Content="text/html; Charset=UTF-8">
<style>
body {
font-family: 'Source Code Pro', monospace;
}
h3 {
font-size: 12pt;
}</style>
</head>
<body>
<h1>Overview</h1>
<p>Issues found: 1</p>
<p>Issues corrected: 0</p>
<h3>/file1.kt</h3>
<ul>
<li>(1, 1): rule-1 broken (rule-1)</li>
</ul>
</body>
</html>
""".trimStart().replace("\n", System.lineSeparator())
"""
<html>
<head>
<link href="https://fonts.googleapis.com/css?family=Source+Code+Pro" rel="stylesheet" />
<meta http-equiv="Content-Type" Content="text/html; Charset=UTF-8">
<style>
body {
font-family: 'Source Code Pro', monospace;
}
h3 {
font-size: 12pt;
}</style>
</head>
<body>
<h1>Overview</h1>
<p>Issues found: 1</p>
<p>Issues corrected: 0</p>
<h3>/file1.kt</h3>
<ul>
<li>(1, 1): rule-1 broken (rule-1)</li>
</ul>
</body>
</html>

""".trimIndent().replace("\n", System.lineSeparator())

val expected = String(out.toByteArray())
assertEquals(actual, expected)
Expand All @@ -124,29 +127,31 @@ h3 {
reporter.afterAll()

val actual =
"""<html>
<head>
<link href="https://fonts.googleapis.com/css?family=Source+Code+Pro" rel="stylesheet" />
<meta http-equiv="Content-Type" Content="text/html; Charset=UTF-8">
<style>
body {
font-family: 'Source Code Pro', monospace;
}
h3 {
font-size: 12pt;
}</style>
</head>
<body>
<h1>Overview</h1>
<p>Issues found: 1</p>
<p>Issues corrected: 1</p>
<h3>/file1.kt</h3>
<ul>
<li>(1, 1): rule-1 broken (rule-1)</li>
</ul>
</body>
</html>
""".trimStart().replace("\n", System.lineSeparator())
"""
<html>
<head>
<link href="https://fonts.googleapis.com/css?family=Source+Code+Pro" rel="stylesheet" />
<meta http-equiv="Content-Type" Content="text/html; Charset=UTF-8">
<style>
body {
font-family: 'Source Code Pro', monospace;
}
h3 {
font-size: 12pt;
}</style>
</head>
<body>
<h1>Overview</h1>
<p>Issues found: 1</p>
<p>Issues corrected: 1</p>
<h3>/file1.kt</h3>
<ul>
<li>(1, 1): rule-1 broken (rule-1)</li>
</ul>
</body>
</html>

""".trimIndent().replace("\n", System.lineSeparator())

val expected = String(out.toByteArray())
assertEquals(actual, expected)
Expand All @@ -172,30 +177,32 @@ h3 {
reporter.afterAll()

val actual =
"""<html>
<head>
<link href="https://fonts.googleapis.com/css?family=Source+Code+Pro" rel="stylesheet" />
<meta http-equiv="Content-Type" Content="text/html; Charset=UTF-8">
<style>
body {
font-family: 'Source Code Pro', monospace;
}
h3 {
font-size: 12pt;
}</style>
</head>
<body>
<h1>Overview</h1>
<p>Issues found: 2</p>
<p>Issues corrected: 0</p>
<h3>/file1.kt</h3>
<ul>
<li>(1, 1): Error message contains a generic type like List&lt;Int&gt; (cannot be auto-corrected) (rule-1)</li>
<li>(2, 1): Error message contains special html symbols like a&lt;b&gt;c&quot;d&apos;e&amp;f (cannot be auto-corrected) (rule-2)</li>
</ul>
</body>
</html>
""".trimStart().replace("\n", System.lineSeparator())
"""
<html>
<head>
<link href="https://fonts.googleapis.com/css?family=Source+Code+Pro" rel="stylesheet" />
<meta http-equiv="Content-Type" Content="text/html; Charset=UTF-8">
<style>
body {
font-family: 'Source Code Pro', monospace;
}
h3 {
font-size: 12pt;
}</style>
</head>
<body>
<h1>Overview</h1>
<p>Issues found: 2</p>
<p>Issues corrected: 0</p>
<h3>/file1.kt</h3>
<ul>
<li>(1, 1): Error message contains a generic type like List&lt;Int&gt; (cannot be auto-corrected) (rule-1)</li>
<li>(2, 1): Error message contains special html symbols like a&lt;b&gt;c&quot;d&apos;e&amp;f (cannot be auto-corrected) (rule-2)</li>
</ul>
</body>
</html>

""".trimIndent().replace("\n", System.lineSeparator())

val expected = String(out.toByteArray())
assertEquals(actual, expected)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,21 +21,21 @@ class JsonReporter(val out: PrintStream) : Reporter {
val indexLast = acc.size - 1
for ((index, entry) in acc.entries.sortedBy { it.key }.withIndex()) {
val (file, errList) = entry
out.println(""" {""")
out.println(""" "file": "${file.escapeJsonValue()}",""")
out.println(""" "errors": [""")
out.println(""" {""")
out.println(""" "file": "${file.escapeJsonValue()}",""")
out.println(""" "errors": [""")
val errIndexLast = errList.size - 1
for ((errIndex, err) in errList.withIndex()) {
val (line, col, ruleId, detail) = err
out.println(""" {""")
out.println(""" "line": $line,""")
out.println(""" "column": $col,""")
out.println(""" "message": "${detail.escapeJsonValue()}",""")
out.println(""" "rule": "$ruleId"""")
out.println(""" }${if (errIndex != errIndexLast) "," else ""}""")
out.println(""" {""")
out.println(""" "line": $line,""")
out.println(""" "column": $col,""")
out.println(""" "message": "${detail.escapeJsonValue()}",""")
out.println(""" "rule": "$ruleId"""")
out.println(""" }${if (errIndex != errIndexLast) "," else ""}""")
}
out.println(""" ]""")
out.println(""" }${if (index != indexLast) "," else ""}""")
out.println(""" ]""")
out.println(""" }${if (index != indexLast) "," else ""}""")
}
out.println("]")
}
Expand Down
Loading