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

[java] New Rule: Use Explicit Types #4561

Merged
merged 8 commits into from Oct 6, 2023

Conversation

adangel
Copy link
Member

@adangel adangel commented May 14, 2023

Describe the PR

Most basic implementation of #2847.

Please review description and properties...

I've not added it to the quickstart.xml ruleset, as I think, this rule is a bit controversial and depends on the project.

I've chosen "Best Practices" "Code Style" as category and not error prone, as using var doesn't break the code, it's "just harder to read".

Related issues

Ready?

  • Added unit tests for fixed bug/feature
  • Passing all unit tests
  • Complete build ./mvnw clean verify passes (checked automatically by github actions)
  • Added (in-code) documentation (if needed)

@adangel adangel added the a:new-rule Proposal to add a new built-in rule label May 14, 2023
@pmd-test
Copy link

pmd-test commented May 14, 2023

1 Message
📖 Compared to master:
This changeset changes 0 violations,
introduces 35 new violations, 0 new errors and 0 new configuration errors,
removes 0 violations, 0 errors and 0 configuration errors.
Download full report as build artifact
Compared to master:
This changeset changes 0 violations,
introduces 35 new violations, 0 new errors and 0 new configuration errors,
removes 0 violations, 0 errors and 0 configuration errors.
Download full report as build artifact
Compared to master:
This changeset changes 5 violations,
introduces 35 new violations, 0 new errors and 0 new configuration errors,
removes 0 violations, 0 errors and 0 configuration errors.
Full report

Generated by 🚫 Danger

@oowekyala
Copy link
Member

Thanks!
I think this rule is a better fit for the codestyle category though.
As the java devs put it, explicit types are a trade-off. Sometimes type Inference makes code more readable, and sometimes it's the other way around. Disallowing var is a pretty extreme stance on the issue and I don't think it's a widely accepted one, so I would not classify this rule as a best practice. It might be useful as a coding convention, which is developer- or codebase-specific.

@adangel adangel added this to the 7.0.0 milestone Oct 6, 2023
@adangel adangel merged commit 2bbb193 into pmd:master Oct 6, 2023
3 checks passed
@adangel adangel deleted the issue-2847-new-rule-explicit-types branch October 6, 2023 18:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
a:new-rule Proposal to add a new built-in rule
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[java] New Rule: Use Explicit Types
4 participants