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

Do you have to call super in custom rules? #2283

Closed
sschuberth opened this issue Jan 22, 2020 · 3 comments · Fixed by #2284
Closed

Do you have to call super in custom rules? #2283

sschuberth opened this issue Jan 22, 2020 · 3 comments · Fixed by #2284
Milestone

Comments

@sschuberth
Copy link
Contributor

The docs at https://github.com/arturbosch/detekt/blob/10f97d2/docs/pages/extensions.md are inconsistent WRT the fact whether visit functions need to call super or not: It's done for visitKtFile but not for visitNamedFunction. Could you please elaborate?

@cortinico
Copy link
Member

Ideally you should always call the super method when writing your custom rule and using the visit methods. This will make sure you don't break any behaviour the superclasses might introduce. The doc should probably be updated.

@sschuberth
Copy link
Contributor Author

Thanks for the PR @cortinico!

@arturbosch
Copy link
Member

You can think of calling the superl.vistXXX as "I need to visit the children first before I can compute the violation":

fun visitKtNamedFunction(function: ...) {
    // setup code or reseting something when seeing a function
    super.visitKtNamedFunction(); // visit's of children - calculate something
    // based on the calculation, verify if this function violates something
}

arturbosch pushed a commit that referenced this issue Jan 28, 2020
This makes sure that the rule doesn't break any behaviour which the
superclasses might introduce in the future.

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

Successfully merging a pull request may close this issue.

4 participants