Skip to content

Latest commit

 

History

History
105 lines (78 loc) · 10.3 KB

README.md

File metadata and controls

105 lines (78 loc) · 10.3 KB

#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.

Execution

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.

Rule Configuration

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.

Maven Plugin

See Readme in mule-linter-maven-plugin module.

Code Checkout

When cloning add the 'recurse-submodules' flag

git clone --recurse-submodules

After cloning, update the submodules

git submodule update --remote

Mule Application Design

Mermaid Design

Updating Mermaid Diagram

Mermaid Live Editor

Code Coverage

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.