diktat icon indicating copy to clipboard operation
diktat copied to clipboard

`IdentifierNaming` rule `VARIABLE_HAS_PREFIX` does not check for keywords

Open HaukeRa opened this issue 2 years ago • 1 comments

Describe the bug

This inspection removes a single letter prefix (e.g. mFunction --> function). It does not check if the resulting property/variable name is a keyword (e.g. kClass --> class) which generates invalid code which further inspections will trip over and fail with an exception.

Expected behavior

The inspection generates valid code (imho not renaming affected properties) if the renaming would result in a language keyword.

Observed behavior

com.pinterest.ktlint.core.ParseException: 17:8 Expecting property name or receiver type on a subsequent inspection because it fails to parse the code.

Steps to Reproduce

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 08:05 HaukeRa

Thank you for the report! That should be easy to fix :)

orchestr7 avatar May 03 '22 08:05 orchestr7