diktat icon indicating copy to clipboard operation
diktat copied to clipboard

`String.toPascalCase()` unexpected renaming for consecutive uppercase letters

Open HaukeRa opened this issue 3 years ago • 2 comments

Describe the bug

The String.toPascalCase() function (used to normalize object and class names) produces unexpected renaming when applied to a string containing multiple consecutive uppercase letters.

https://github.com/analysis-dev/diktat/blob/759c26500de9c86c58af875f750017f14e3d2208/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/utils/StringCaseUtils.kt#L126

Example: IOSExtension gets automatically converted to Iosextension

Expected behavior

The human expected conversion would be IosExtension but since it is hard to determine automatically whether the E belongs to the group of upper-case letters or is the capitalization of the next word, the function should not apply any automatic correction and let any inspection using it emit a warning about the encountered string.

Environment information

  • diktat version: 1.1.0
  • build tool (gradle): 7.4.2
  • how is diktat run (CLI, plugin, etc.): spotless
  • kotlin version: 1.6.20
  • operating system: windows/ubuntu

HaukeRa avatar May 03 '22 10:05 HaukeRa

We can add workarounds for some pre-recorded words, like IOSExtension... But actually we already have Suppress mechanism. No chance to fix it otherwise.

orchestr7 avatar May 03 '22 12:05 orchestr7

Wouldn't it be beneficial if diktat would warn about these and not try to fix them automatically? Of course that is just my expectation if a resolution is ambiguous, but thats debatable for sure.

HaukeRa avatar May 03 '22 14:05 HaukeRa