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

Rule 6.1.4 several init blocks are redundant and generally should not be used in your class #459

Merged
merged 8 commits into from
Oct 29, 2020

Conversation

petertrr
Copy link
Member

@petertrr petertrr commented Oct 26, 2020

What's done:

  • Initial implementation

This pull request closes #440

Actions checklist

  • Implemented Rule, added Warnings
  • Added tests on checks
  • Added tests on fixers
  • Updated diktat-analysis.yml
  • Updated available-rules.md

Fixme

  • More complicated fixing logic when class properties are assigned inside init blocks

### What's done:
* Initial implementation
* Fixed typos in code style
# 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
#	info/available-rules.md
### What's done:
* paragraph6 -> chapter6
### What's done:
* Fixes
@codecov
Copy link

codecov bot commented Oct 26, 2020

Codecov Report

Merging #459 into master will decrease coverage by 0.06%.
The diff coverage is 78.78%.

Impacted file tree graph

@@             Coverage Diff              @@
##             master     #459      +/-   ##
============================================
- Coverage     81.98%   81.91%   -0.07%     
- Complexity     1451     1461      +10     
============================================
  Files            70       71       +1     
  Lines          3624     3689      +65     
  Branches       1159     1178      +19     
============================================
+ Hits           2971     3022      +51     
  Misses          202      202              
- Partials        451      465      +14     
Flag Coverage Δ Complexity Δ
#unittests 81.91% <78.78%> (-0.07%) 1461.00 <10.00> (+10.00) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ Complexity Δ
...at-rules/src/main/kotlin/generated/WarningNames.kt 0.00% <ø> (ø) 0.00 <0.00> (ø)
.../cqfn/diktat/ruleset/rules/files/WhiteSpaceRule.kt 78.16% <ø> (ø) 125.00 <0.00> (?)
...qfn/diktat/ruleset/rules/classes/SingleInitRule.kt 77.77% <77.77%> (ø) 10.00 <10.00> (?)
...tlin/org/cqfn/diktat/ruleset/constants/Warnings.kt 97.29% <100.00%> (+0.02%) 9.00 <0.00> (ø)
...cqfn/diktat/ruleset/rules/DiktatRuleSetProvider.kt 96.96% <100.00%> (+0.04%) 8.00 <0.00> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 6852628...41badb5. Read the comment docs.

### What's done:
* More logic
### What's done:
* More logic
### What's done:
* More logic
@petertrr petertrr requested a review from aktsay6 October 27, 2020 09:54
Copy link
Collaborator

@aktsay6 aktsay6 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@petertrr petertrr merged commit fa9a4fc into master Oct 29, 2020
@petertrr petertrr deleted the feature/rule-6.1.4#440 branch October 29, 2020 19:23
package test.chapter6.init_blocks

class Example {
init { println("Lorem ipsum") }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@petertrr I have started thinking right now that there is a possibility to break the code here.
If someone will do the following:

init { println(1) }
    val a = "".also {
        println(3)
    } 
init { println(2) }

We will break expected print chain

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Rule 6.1.4: several init blocks are redundant and generally should not be used in your class
3 participants