#Mule Linter Tool A linter is a tool that analyzes source code looking for patterns that don’t follow convention. Linting helps prevent errors and improve the overall quality of the code by following best practices. Lint tools are a form of static code analyzers. Some common code analyzers for Java are Checkstyle, FindBugs, and PMD.
The Mule Linter will enforce that all Mule projects are developed with a baseline set of rules. Some basic examples of rules that will be enforced, are the proper usage of property and pom files, useful logging messages, and standard project structure.
The mule-linter can be run as a jar with the following command:
~/code/avio/mule-linter$ java -jar mule-linter-1.0-SNAPSHOT.jar --dir=SampleMuleApp --rules='AVIOCustomRuleConfiguration.groovy'
--dir
is the root directory of the Mule project. --rules
is the path to the rule configuration file.
Create a Groovy class that implements a static method called getRules
and returns a RuleSet object.
static RuleSet getRules() { }
Initialize the Rules you would like to use, and add them to the RuleSet with the .addRule(Rule)
method.
Make sure to import the rules and helper classes you intend to use.
Sample configuration:
import com.avioconsulting.mule.linter.model.rule.RuleSet
import com.avioconsulting.mule.linter.model.CaseNaming
import com.avioconsulting.mule.linter.rule.cicd.*
import com.avioconsulting.mule.linter.rule.configuration.*
import com.avioconsulting.mule.linter.rule.git.*
import com.avioconsulting.mule.linter.rule.muleartifact.*
import com.avioconsulting.mule.linter.rule.pom.*
import com.avioconsulting.mule.linter.rule.property.*
class AVIOCustomRuleConfiguration {
static final List<String> ENVIRONMENTS = ['dev','test','prod']
static final String GLOBALS_FILENAME = 'globals.xml'
static RuleSet getRules() {
RuleSet rules = new RuleSet()
//cicd
rules.addRule(new JenkinsFileExistsRule())
//configuration
rules.addRule(new ConfigFileNamingRule(CaseNaming.CaseFormat.KEBAB_CASE))
rules.addRule(new FlowSubflowNamingRule(CaseNaming.CaseFormat.KEBAB_CASE))
rules.addRule(new GlobalConfigNoFlowsRule(GLOBALS_FILENAME))
rules.addRule(new GlobalConfigRule(GLOBALS_FILENAME))
rules.addRule(new LoggerCategoryExistsRule())
rules.addRule(new LoggerMessageExistsRule())
rules.addRule(new OnErrorLogExceptionRule())
rules.addRule(new UnusedFlowRule())
//git
rules.addRule(new GitIgnoreRule())
//muleArtifact
rules.addRule(new MuleArtifactHasSecurePropertiesRule())
rules.addRule(new MuleArtifactMinMuleVersionRule())
//pom
rules.addRule(new MuleMavenPluginVersionRule('3.3.5'))
rules.addRule(new MuleRuntimeVersionRule('4.2.1'))
rules.addRule(new MunitMavenPluginAttributesRule())
rules.addRule(new MunitVersionRule('2.2.1'))
rules.addRule(new PomExistsRule())
//property
rules.addRule(new EncryptedPasswordRule())
rules.addRule(new PropertyExistsRule('db.user', ENVIRONMENTS))
rules.addRule(new PropertyFileNamingRule(ENVIRONMENTS))
rules.addRule(new PropertyFilePropertyCountRule(ENVIRONMENTS))
return rules
}
}
For a full breakdown on the available rules, check here.
See Readme in mule-linter-maven-plugin
module.
When cloning add the 'recurse-submodules' flag
git clone --recurse-submodules
After cloning, update the submodules
git submodule update --remote
- Update code in mule-application-design.mmd and paste into live editor
- Click 'Download PNG' and save file into config/mermaid directory
CodeNarc is used to ensure quality in groovy code. The configuration file is located here. To execute run gradle check
, and an output report will be generated.