Skip to content

Conversation

@mitchspano
Copy link
Contributor

Describe the PR

This PR implements a new Apex rule AvoidBooleanMethodParametersRule that detects boolean parameters in public and global methods. The rule discourages the use of Boolean parameters in public APIs as they can lead to ambiguity (especially with null handling in Apex) and make method calls harder to understand. Instead, the rule encourages developers to use more expressive alternatives such as separate methods with descriptive names, enums, or configuration objects.

The rule specifically targets:

  • Public and global methods only (private and protected methods are excluded)
  • Parameters with boolean type
  • Encourages splitting methods or using more descriptive parameter types

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)

…in public/global methods

This commit introduces a new rule that flags boolean parameters in public and global Apex methods, encouraging the use of more descriptive alternatives. It includes the rule implementation, corresponding XML configuration, and test cases to validate its functionality.
@github-actions
Copy link

github-actions bot commented Jun 9, 2025

Documentation Preview

Compared to main:
This changeset changes 0 violations,
introduces 28 new violations, 0 new errors and 0 new configuration errors,
removes 0 violations, 0 errors and 0 configuration errors.

Regression Tester Report

(comment created at 2025-06-26 09:05:41+00:00 for 22fe512)

@mitchspano mitchspano changed the title Add AvoidBooleanMethodParameters rule [apex] New Rule: Avoid boolean method parameters Jun 10, 2025
@adangel adangel added the a:new-rule Proposal to add a new built-in rule label Jun 18, 2025
Copy link
Member

@adangel adangel left a comment

Choose a reason for hiding this comment

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

Thanks!

@adangel adangel added this to the 7.15.0 milestone Jun 18, 2025
adangel added a commit that referenced this pull request Jun 26, 2025
adangel added a commit that referenced this pull request Jun 26, 2025
Merge pull request #5821 from mitchspano:boolean_parameter
@adangel adangel merged commit 22fe512 into pmd:main Jun 26, 2025
12 checks passed
@mitchspano mitchspano deleted the boolean_parameter branch November 4, 2025 21:20
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.

[apex] New Rule: Avoid Boolean Method Parameters

2 participants