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.1 Primary constructor should be defined implicitly in the declaration of class #435

Merged
merged 20 commits into from
Nov 6, 2020

Conversation

petertrr
Copy link
Member

@petertrr petertrr commented Oct 20, 2020

Which rule and warnings did you add?

This pull request closes #429

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 cases for fixing
  • keep modifiers and annotations from secondary constructor

### What's done:
* Refactoring
@petertrr petertrr changed the title Rule 6.1.1 Rule 6.1.1 Primary constructor should be defined implicitly in the declaration of class Oct 20, 2020
@codecov
Copy link

codecov bot commented Oct 20, 2020

Codecov Report

Merging #435 into master will decrease coverage by 0.06%.
The diff coverage is 80.53%.

Impacted file tree graph

@@             Coverage Diff              @@
##             master     #435      +/-   ##
============================================
- Coverage     81.83%   81.76%   -0.07%     
- Complexity     1501     1528      +27     
============================================
  Files            71       72       +1     
  Lines          3765     3861      +96     
  Branches       1209     1234      +25     
============================================
+ Hits           3081     3157      +76     
  Misses          210      210              
- Partials        474      494      +20     
Flag Coverage Δ Complexity Δ
unittests 81.76% <80.53%> (-0.07%) 0.00 <27.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> (ø)
...qfn/diktat/ruleset/utils/search/VariablesSearch.kt 89.28% <ø> (ø) 19.00 <0.00> (ø)
...tat/ruleset/rules/classes/SingleConstructorRule.kt 78.02% <78.02%> (ø) 26.00 <26.00> (?)
...tlin/org/cqfn/diktat/ruleset/utils/KotlinParser.kt 86.00% <90.00%> (+0.89%) 19.00 <1.00> (+1.00)
...tlin/org/cqfn/diktat/ruleset/constants/Warnings.kt 98.21% <100.00%> (+0.01%) 10.00 <0.00> (ø)
...cqfn/diktat/ruleset/rules/DiktatRuleSetProvider.kt 97.01% <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 6f47a76...5f6ab69. Read the comment docs.

### What's done:
* Create init block for other statements
* Refactoring
### What's done:
* Use KotlinParser
### What's done:
* Code style
### What's done:
* Code style
@petertrr petertrr marked this pull request as ready for review October 21, 2020 10:56
@petertrr petertrr requested review from kentr0w and orchestr7 October 21, 2020 10:56
Copy link
Member

@orchestr7 orchestr7 left a comment

Choose a reason for hiding this comment

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

some things need clarification

node
.findChildByType(CLASS_BODY)
?.getAllChildrenWithType(SECONDARY_CONSTRUCTOR)
?.singleOrNull()
Copy link
Member

Choose a reason for hiding this comment

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

what will you do - if there are no secondaryConstructors?

Copy link
Member Author

Choose a reason for hiding this comment

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

Nothing, as there is nothing to convert,

diktat-analysis.yml Show resolved Hide resolved
val classInitializer = kotlinParser.createNode(
"""
|init {
| ${otherStatements.joinToString("\n") { it.text }}
Copy link
Member

Choose a reason for hiding this comment

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

I started thinking that there can be issues right now:

constructor(a: Int) {
    val f = F(a)
    this.a = f.foo()
}

how it should work?

Copy link
Member Author

Choose a reason for hiding this comment

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

I think we can't reliably automate complex cases. Your example will be converted to

class Foo(val a: Int) {
    init {
        f = F(a)
    }
}

and it will break the code. In my opinion, correct form of this code should be

class Foo(a: Int) {
    val a: Int by lazy {
        val f = F(a)
        f.foo()
    }
}

but there may be other valid cases for refactoring.

Copy link
Member

Choose a reason for hiding this comment

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

please add a Kdoc with a fixme for it

@petertrr petertrr requested a review from orchestr7 October 23, 2020 13:04
Copy link
Member

@orchestr7 orchestr7 left a comment

Choose a reason for hiding this comment

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

lgtm

### What's done:
* Added Fixme and disabled test
### What's done:
* Added more logic on init block creation
### What's done:
* Fixes & smoke test example
# Conflicts:
#	info/diktat-kotlin-coding-style-guide-en.md
### What's done:
* Code style edits applied
### What's done:
* Code style
### What's done:
* Code style
@petertrr petertrr merged commit ebe8ef9 into master Nov 6, 2020
@petertrr petertrr deleted the feature/rule-6.1.1#429 branch November 6, 2020 13:05
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.1: Primary constructor should be defined implicitly in the declaration of class
2 participants