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

Detect classes that do not use inheritance or inner classes that should be static #560

Open
Luro02 opened this issue Jul 3, 2024 · 0 comments
Labels
enhancement New feature or request low-priority new-lint A new lint. unresolved Some decisions have not been made yet or it is not obvious what should be detected.

Comments

@Luro02
Copy link
Collaborator

Luro02 commented Jul 3, 2024

What it does

One can nest a class in another class like this:

class A {
    class B {
    }
}

If the class is not static, it will extend the outer class, making the non-static fields and methods accessible.

In most submissions this behaviour is not intentional and therefore it makes sense to detect these cases.

Problems with this check:

  • Time spent implementing this, might not be worth the effort
  • Might be difficult to detect if a class uses its inheritance

After implementing this, it should be easy to find classes that inherit from another class, but do not need to inherit from it. Note: I do not think that this happens very often, that is why this issue is marked as low-priority

Things to be careful about with the inheritance thing:

  • It should look if the class accesses any constructors/methods/fields of the parent
  • How the context looks: Parent parent = new Child()

Lint Name

INNER_CLASS_SHOULD_BE_STATIC,CLASS_SHOULD_NOT_INHERIT

Category

oop

Example

<code>

Could be written as:

<code>
@Luro02 Luro02 added enhancement New feature or request new-lint A new lint. low-priority unresolved Some decisions have not been made yet or it is not obvious what should be detected. labels Jul 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request low-priority new-lint A new lint. unresolved Some decisions have not been made yet or it is not obvious what should be detected.
Projects
None yet
Development

No branches or pull requests

1 participant