Skip to content

Commit ea47f32

Browse files
committed
refactor: normalize line endings when exporting the bundled tokens file
1 parent 1d6f4cb commit ea47f32

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

src/main/kotlin/com/github/lppedd/cc/configuration/component/DefaultTokensFileExportPanel.kt

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import com.intellij.openapi.application.WriteAction
99
import com.intellij.openapi.extensions.PluginId
1010
import com.intellij.openapi.fileChooser.FileChooserFactory
1111
import com.intellij.openapi.fileChooser.FileSaverDescriptor
12+
import com.intellij.openapi.util.text.StringUtil
1213
import com.intellij.openapi.vfs.VirtualFile
1314
import com.intellij.openapi.vfs.VirtualFileWrapper
1415
import com.intellij.ui.JBColor
@@ -70,13 +71,17 @@ internal class DefaultTokensFileExportPanel
7071
return
7172
}
7273

73-
// When exporting to a file, we also need to add the JSON schema reference
74-
val jsonStr = getResourceAsStream("/defaults/${CC.File.Defaults}").bufferedReader().use(Reader::readText)
74+
// When exporting to a file, we also need to add the JSON schema reference.
75+
// Better normalize line endings to \n.
76+
val jsonStr = StringUtil.convertLineSeparators(
77+
getResourceAsStream("/defaults/${CC.File.Defaults}").bufferedReader().use(Reader::readText)
78+
)
79+
7580
val pluginVersion = getPluginVersion()
7681
val schemaPath = "src/main/resources/defaults/conventionalcommit.schema.json"
7782
val schemaUrl = "https://github.com/lppedd/idea-conventional-commit/raw/$pluginVersion/$schemaPath"
7883
val sb = StringBuilder(jsonStr)
79-
sb.insert(4, $$"\"$schema\": \"$$schemaUrl\",\n")
84+
sb.insert(4, $$"\"$schema\": \"$$schemaUrl\",\n ")
8085

8186
WriteAction.runAndWait<Throwable> {
8287
virtualFile.setBinaryContent("$sb".toByteArray())

0 commit comments

Comments
 (0)