Skip to content

Lambda rule false positives caused by a function called "it" #1959

@JordanLongstaff

Description

@JordanLongstaff

Describe the bug

I use Kotest, a powerful unit testing framework that has many different test spec styles. One of them is based on Jest using functions called describe and it. Because all test specs are written in a lambda, calling the latter function can cause false positives because Diktat confuses it for a parameter called it, even though the lambda has no parameters.

Expected behavior

Diktat should ignore the use of the it function, since it's not a parameter of the lambda. This is provable by the fact that the lambda has no parameters.

Observed behavior

Diktat reports both TOO_MANY_LINES_IN_LAMBDA and PARAMETER_NAME_IN_OUTER_LAMBDA violations.

Steps to Reproduce

  1. Write a class that includes a function called it and another function that takes in a zero-parameter lambda as an argument.
  2. Call the latter function from someplace, and inside the lambda that is passed, call the it function.
  3. Inside the same lambda, call another function that uses a lambda (e.g. let, also, with...).
  4. Run Diktat. It will complain about the outer lambda's parameter being called it, even though said parameter does not exist.

Environment information

  • diktat version: 2.0.0
  • build tool (maven/gradle): Gradle
  • how is diktat run (CLI, plugin, etc.): Spotless
  • kotlin version: 2.2.10
  • operating system: Windows 11

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions