Rule entry point

An entry point is a syntax rule. A syntax rule operates on the AST (abstract syntax tree) of source files.

rule MyRule on ApexPage, ApexComponent {

    on element(x) {
			 // executed when a node of type "element" is found in the AST
    }

		on content(x) {
			// executed when a node of type "content" is found in the AST
		}

		autofix(detection) {
			// This is executed for every detection captured
		}

}

This syntax rule specifies:

Source file types

Variables

Variables can be declared with the keyword var then assigning an expression to it.

var st = "Lorem Ipsum" // string variable
var num = 23 // numeric variable
var bool = true // boolean

If statements

If statements allow to execute a block of statements only when certain conditions are verified.

if (st == "abc") {
	// if true do this
} 

Optionally, if statements can have an else block

if (st == "abc") {
	// if true do this
} else {
	// otherwise do this
}

Trying and catching

To stay safe from errors, you can use try statements

try {
	doSomethingDangerous()
}