Customize Checkstyle Rules


ODM Customization

Software Prerequisites

Prerequisite

You have installed Rule Designer in your local environment and Checkstyle Rule Projects have been in your local workspace.

Workflow checkstyle rule projects overview

The Workflow checkstyle rule projects include CheckstyleBOM, CheckstyleRules, CheckstyleRulesCore and CheckstyleRulesCustomized. Their dependency relationships are as follows:

Workflow checkstyle rules customization

Override core checkstyle rules

To rewrite any core checkstyle rule, please do not update the core rule itself. Instead you should copy the rule into the checksOverride rule package of project CheckstyleRulesCustomized and then update the copy. Take overriding a core checkstyle rule check-app-with-too-many-bpd as an example:

  1. Review the content of the core rule check-app-with-too-many-bpd. if the process app has more than 5 bpds, then a checkstyle warning message will be generated.

  2. Run the Workflow checkstyle asset against an updated sample file sample-updated.twx and verify in the final checkstyle report, there is warning message Too many BPDs.

  3. In rule designer, copy the rule check-app-with-too-many-bpd from rule project CheckstyleRulesCore to rule package checksOverride in rule project CheckstyleRulesCustomized.

  4. Update the rule check-app-with-too-many-bpd in CheckstyleRulesCustomized, change number 5 to 10.

  5. In the properties window of the rule check-app-with-too-many-bpd, select the core rule (with the same name) to override.

  6. Redeploy the ruleset to your target server e.g. on IBM Cloud.

  7. Rerun Workflow checkstyle asset against an updated sample file sample-updated.twx and verify in the final checkstyle report, there is no warning message Too many BPDs.

Write custom checkstyle rules

To write customized checkstyle rules, put the new rules in rule package customized in rule project CheckstyleRulesCustomized. Create artifact-based rule package if necessary.

Take writing a customized checkstyle rule check-service-name-contain-test as an example:

  1. Add a new rule check-service-name-contain-test that will check if a Workflow service name contains test into in package customized in rule project CheckstyleRulesCustomized.

  2. Check that the asset provides the utility function does not match the naming convension in its CheckstyleRulesBOM project.

  3. Redeploy the ruleset to your target server e.g. on IBM Cloud.

  4. Rerun Workflow checkstyle asset against an updated sample file sample-updated.twx and verify in the final checkstyle report, there is a warning message The service with the word ‘Test’ (not case sensitive) in its name.

Embedded Rules Customization

Embedded rules overview

After decompressing the embedded-checkstyle-rules.zip, the embedded rules folders include init, checks and score.

Folder Description
init Including a thresholds initialization rule.
checks Specific rules for executing checkstyle, including folders like app, businessobject, casesolution, businessobject, casetype, coachview, migrate, process, service, variable, webservice.
score Including rules for calculating score and setting score bound.

Customization can be done by directly modifying the rule file. for example, modify some thresholds by modifying the values in init/init-thresholds.drl.

Modify the lower and upper bound by modifying the values in score/configure-score-health-bound.drl.

Override embedded rules

  1. After modifying the rules, repackage the customized rules into a ZIP.

  2. Click Administrator tab, then switch to Settings tab.

  3. Scroll to Checkstyle section, choose EMBEDDED as the Engine and switch on the Enable Custom Rules.

  4. Click Upload Custom Rules button to upload the custom rules ZIP.

  5. Click Save button in Settings to save the configuration and rerun Checkstyle.