Skip to content

Commit

Permalink
Cleanup path routing
Browse files Browse the repository at this point in the history
  • Loading branch information
joshafeinberg committed May 27, 2020
1 parent 0c4dc33 commit b2a69a8
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 19 deletions.
4 changes: 2 additions & 2 deletions ktlint-baseline.xml
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<baseline version="1.0">
<file name="/ktlint/src/test/resources/TestBaselineExtraErrorFile.kt">
<file name="ktlint/src/test/resources/TestBaselineExtraErrorFile.kt">
<error line="1" column="34" source="no-empty-class-body" />
<error line="2" column="1" source="no-blank-line-before-rbrace" />
</file>
<file name="/ktlint/src/test/resources/TestBaselineFile.kt">
<file name="ktlint/src/test/resources/TestBaselineFile.kt">
<error line="1" column="24" source="no-empty-class-body" />
<error line="2" column="1" source="no-blank-line-before-rbrace" />
</file>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,11 @@ class BaselineReporter(val out: PrintStream) : Reporter {
out.println("""<baseline version="1.0">""")
for ((file, errList) in acc.entries.sortedBy { it.key }) {
val fileName = try {
Paths.get("").toAbsolutePath().relativize(File(file).toPath()).toString().replace('\\', '/')
val rootPath = Paths.get("").toAbsolutePath()
val filePath = Paths.get(file)
rootPath.relativize(filePath).toString().replace(File.separatorChar, '/')
} catch (e: IllegalArgumentException) {
file
}.let { name ->
if (name[0] != '/') {
"/$name"
} else {
name
}
}
out.println(""" <file name="${fileName.escapeXMLAttrValue()}">""")
for ((line, col, ruleId, _) in errList) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,10 @@ class BaselineReporterTest {
"""
<?xml version="1.0" encoding="utf-8"?>
<baseline version="1.0">
<file name="/one-fixed-and-one-not.kt">
<file name="one-fixed-and-one-not.kt">
<error line="1" column="1" source="rule-1" />
</file>
<file name="/two-not-fixed.kt">
<file name="two-not-fixed.kt">
<error line="1" column="10" source="rule-1" />
<error line="2" column="20" source="rule-2" />
</file>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,10 +113,8 @@ internal fun List<LintError>.containsLintError(error: LintError): Boolean {
* Also adjusts the slashes for uniformity between file systems
*/
internal val File.relativeRoute: String
get() = Paths.get("").toAbsolutePath().relativize(this.toPath()).toString().replace('\\', '/').let { name ->
if (name[0] != '/') {
"/$name"
} else {
name
}
get() {
val rootPath = Paths.get("").toAbsolutePath()
val filePath = this.toPath()
return rootPath.relativize(filePath).toString().replace(File.separatorChar, '/')
}
4 changes: 2 additions & 2 deletions ktlint/src/test/resources/test-baseline.xml
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<baseline version="1.0">
<file name="/src/test/resources/TestBaselineFile.kt">
<file name="src/test/resources/TestBaselineFile.kt">
<error line="1" column="24" source="no-empty-class-body" />
<error line="2" column="1" source="no-blank-line-before-rbrace" />
</file>
<file name="/src/test/resources/TestBaselineExtraErrorFile.kt">
<file name="src/test/resources/TestBaselineExtraErrorFile.kt">
<error line="1" column="24" source="no-empty-class-body" />
</file>
</baseline>

0 comments on commit b2a69a8

Please sign in to comment.