-
Notifications
You must be signed in to change notification settings - Fork 39
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
Rule 6.1.7 implicit backing property(#443) #465
Rule 6.1.7 implicit backing property(#443) #465
Conversation
### What's done: * First logic * Added tests
### What's done: * Logic made * Added warn tests
### What's done: * Fixed bugs
#443) # Conflicts: # diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/DiktatRuleSetProvider.kt # info/available-rules.md
### What's done: * Fixed bugs
Codecov Report
@@ Coverage Diff @@
## master #465 +/- ##
============================================
+ Coverage 81.68% 81.86% +0.17%
- Complexity 1641 1696 +55
============================================
Files 79 85 +6
Lines 4139 4257 +118
Branches 1307 1325 +18
============================================
+ Hits 3381 3485 +104
- Misses 229 237 +8
- Partials 529 535 +6
Flags with carried forward coverage won't be shown. Click here to find out more. Continue to review full report at Codecov.
|
diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/constants/Warnings.kt
Outdated
Show resolved
Hide resolved
diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/ImplicitBackingPropertyRule.kt
Show resolved
Hide resolved
diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/ImplicitBackingPropertyRule.kt
Outdated
Show resolved
Hide resolved
...at-rules/src/test/kotlin/org/cqfn/diktat/ruleset/chapter6/ImplicitBackingPropertyWarnTest.kt
Outdated
Show resolved
Hide resolved
...at-rules/src/test/kotlin/org/cqfn/diktat/ruleset/chapter6/ImplicitBackingPropertyWarnTest.kt
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See comments above
### What's done: * Fixed bugs
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please take a look at snapshot check. Your rule triggers quite a lot in diktat-test-framework
with false-positives. Please add similar examples to tests, one idea how to fix algorithm is in comment below.
diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/ImplicitBackingPropertyRule.kt
Outdated
Show resolved
Hide resolved
### What's done: * Fixed bugs
### What's done: * Fixed bugs
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
False-positives are still there, please add more tests (like TestProcessingFactory.allTestsFromResources
in diktat-test-framework). We need to come up with better algorithm for identifying such backing properties. Maybe, check that a certain class property is used both in an assignment in setter and in the return statement in getter?
diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/ImplicitBackingPropertyRule.kt
Outdated
Show resolved
Hide resolved
diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/ImplicitBackingPropertyRule.kt
Outdated
Show resolved
Hide resolved
### What's done: * Fixed bugs
#443) # Conflicts: # diktat-analysis.yml # diktat-rules/src/main/kotlin/generated/WarningNames.kt # diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/constants/Warnings.kt # diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/DiktatRuleSetProvider.kt # diktat-rules/src/main/resources/diktat-analysis-huawei.yml # diktat-rules/src/main/resources/diktat-analysis.yml # info/available-rules.md
#443) # Conflicts: # diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/constants/Warnings.kt
### What's done: * Fixed bugs
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
https://github.com/cqfn/diKTat/pull/465/checks?check_run_id=1440909442
Warning is raised on declaredOptions
in TestArgumentsReader
, where local variable is returned from getter. We should trigger this warning only for class properties.
### What's done: * Fixed bugs
### What's done: * Fixed bugs
.findAllNodesWithSpecificType(PROPERTY) | ||
.map { (it.psi as KtProperty).name!! } | ||
|
||
if (refExprs.isNotEmpty()) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this mean that any reference to non-local property will cause warning? What if some other class property is read for some reason? I think, similar to getters, we should check only left-hand side references in assignments. For example, this code:
val foo
set(value) {
if (isDebugMode) log.debug(value)
field = value
}
shouldn't raise a warning beca use there is no backing property.
### What's done: * Fixed bugs
### What's done: * Fixed bugs
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
#443) # Conflicts: # diktat-analysis.yml # diktat-rules/src/main/kotlin/generated/WarningNames.kt # diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/constants/Warnings.kt # diktat-rules/src/main/resources/diktat-analysis-huawei.yml # diktat-rules/src/main/resources/diktat-analysis.yml
Which rule and warnings did you add?
In case of using "implicit backing property" scheme, the name of real and back property should be the same
This pull request closes #443
Actions checklist