Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug in fix mode in rule AVOID_NULL_CHECK #1293

Closed
Arrgentum opened this issue May 11, 2022 · 2 comments · Fixed by #1535
Closed

Bug in fix mode in rule AVOID_NULL_CHECK #1293

Arrgentum opened this issue May 11, 2022 · 2 comments · Fixed by #1535
Assignees
Labels
bug Something isn't working

Comments

@Arrgentum
Copy link
Member

Arrgentum commented May 11, 2022

Describe the bug

Rule AVOID_NULL_CHECK in fix mode give result

splitOffset?.let {
   val listParentSearch = listOf(BINARY_EXPRESSION, PARENTHESIZED, FUN)
   if (parent.treeParent.elementType in listParentSearch || parent.treeParent.treeParent.elementType == FUNCTION_LITERAL) {
          parent = parent.treeParent
   } else {
            return checkBinaryExpression(parent, configuration)
   }
} ?: parent = parent.treeParent

But then an error is Variable Expected

Expected behavior

splitOffset?.let {
    val listParentSearch = listOf(BINARY_EXPRESSION, PARENTHESIZED, FUN)
    if (parent.treeParent.elementType in listParentSearch || parent.treeParent.treeParent.elementType == FUNCTION_LITERAL) {
           parent = parent.treeParent
    } else {
           return checkBinaryExpression(parent, configuration) 
   }
 } ?: run { parent = parent.treeParent }

Code should be like this

Environment information

  • diktat version: 1.1.0
@Arrgentum Arrgentum added the bug Something isn't working label May 11, 2022
@Arrgentum Arrgentum modified the milestones: 1.1.0, 1.1.1 May 11, 2022
@petertrr
Copy link
Member

minimal reproducible example, I believe the whole body of let is not important here.

Also, please provide original code when reporting autofixer issues.

But then an error is

Please specify more explicitly, whether fixed code has diktat errors or syntax errors, like here

@sanyavertolet
Copy link
Member

sanyavertolet commented May 16, 2022

In save-cloud we found out that construction

src = avatar?.let {
    "/api/$v1/avatar$it"
}
    ?: run {
        "img/company.svg"
    }

is not fixed into

src = avatar?.let {
    "/api/$v1/avatar$it"
} 
    ?: "img/company.svg"

Need to investigate.

@orchestr7 orchestr7 modified the milestones: 1.2.0, 1.2.1 Jun 22, 2022
@0x6675636b796f75676974687562 0x6675636b796f75676974687562 removed this from the 1.2.4 milestone Aug 10, 2022
sanyavertolet added a commit that referenced this issue Oct 26, 2022
### What's done:
 * Added isAssignment utility function to check if a line has assignment operator ('=') using simple regex
 * Added a check for assignment operator when deciding if to put run block or not
 * Added tests
(#1293)
sanyavertolet added a commit that referenced this issue Oct 26, 2022
### What's done:
 * Added isAssignment utility function to check if a line has assignment operator ('=') using simple regex
 * Added a check for assignment operator when deciding if to put run block or not
 * Added tests
(#1293)
sanyavertolet added a commit that referenced this issue Oct 26, 2022
### What's done:
 * Added isAssignment utility function to check if a line has assignment operator ('=') using simple regex
 * Added a check for assignment operator when deciding if to put run block or not
 * Added tests
(#1293)
sanyavertolet added a commit that referenced this issue Oct 27, 2022
### What's done:
 * Added a check for assignment operator when deciding if to put run block or not
 * Added tests
(#1293)
sanyavertolet added a commit that referenced this issue Oct 27, 2022
### What's done:
 * Added a check for assignment operator when deciding if to put run block or not
 * Added tests
(#1293)
sanyavertolet added a commit that referenced this issue Oct 27, 2022
* Bugfix for fix mode of AVOID_NULL_CHECK

### What's done:
 * Added a check for assignment operator when deciding if to put run block or not
 * Added tests
(#1293)
nulls pushed a commit that referenced this issue Oct 27, 2022
* Bugfix for fix mode of AVOID_NULL_CHECK

 * Added a check for assignment operator when deciding if to put run block or not
 * Added tests
(#1293)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants