You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Diktat uses path to file in some rules. We take it from org.jetbrains.kotlin.com.intellij.openapi.util.UserDataHolder#getUserData in root node using com.pinterest.ktlint.core.KtLint#getFILE_PATH_USER_DATA_KEY.
It's going to be removed in version 0.49.x:
@Deprecated(
""" Marked for removal in KtLint 0.49.0. Use: if (node.isRoot()) { val fileName = (node.psi as? KtFile)?.name ... }""",
)
publicvalFILE_PATH_USER_DATA_KEY:Key<String> =Key<String>("FILE_PATH")
The kdoc suggests to use org.jetbrains.kotlin.psi.KtFile#name, but unfortunately it contains only file name, not a path: com.pinterest.ktlint.core.internal.RuleExecutionContext.Companion#createRuleExecutionContext$ktlint_core:
val psiFileName =
code.fileName // <-- fileName, not filePath?:if (code.script) {
"File.kts"
} else {
"File.kt"
}
val psiFile = psiFileFactory.createFileFromText(
psiFileName,
Is it any way to keep logic to set FILE_PATH in UserDataHolder?
P.S. As I got #1434, the user data was removed in favor of .editorconfig. But FILE_PATH is dynamic property, when .editorconfig is more about static properties
Additional information
Current version of ktlint: 0.48.2
The text was updated successfully, but these errors were encountered:
FILE_PATH_USER_DATA_KEY has already been removed. But the problem was easily resolved by passing the path instead of the filename to he PsiFileFactory. Now the path instead of the filename can be retrieved in the rule with:
if (node.isRoot()) {
node as FileASTNode? ?: error("node is not ${FileASTNode::class} but ${node::class}")
val filePath = (node.psi as? KtFile)?.virtualFilePath
...
}
Current Behavior
Diktat uses path to file in some rules. We take it from
org.jetbrains.kotlin.com.intellij.openapi.util.UserDataHolder#getUserData
in root node usingcom.pinterest.ktlint.core.KtLint#getFILE_PATH_USER_DATA_KEY
.It's going to be removed in version 0.49.x:
The kdoc suggests to use
org.jetbrains.kotlin.psi.KtFile#name
, but unfortunately it contains only file name, not a path:com.pinterest.ktlint.core.internal.RuleExecutionContext.Companion#createRuleExecutionContext$ktlint_core
:Is it any way to keep logic to set
FILE_PATH
inUserDataHolder
?P.S. As I got #1434, the
user data
was removed in favor of.editorconfig
. ButFILE_PATH
is dynamic property, when.editorconfig
is more about static propertiesAdditional information
The text was updated successfully, but these errors were encountered: