Regex Rules Reference

The Regex rules help you search for specific string patterns in your code. To select these rules, use --rule-selector regex. For example, to run all the Regex rules:

1sf code-analyzer run --rule-selector regex

AvoidGetHeapSizeInLoop 

Description: Detects usage of the Limits.getHeapSize() Apex method in for, while, and do-while loops.

Default Severity: 2 (High)

Default Tags: Recommended, Performance, Apex

Example(s):

  • [Bad] Code that causes a violation:
1public static void someMethodWithForLoop() {
2        for (Integer i = 0, j = 0; i < 10; i++) {
3            Limits.getHeapSize();
4        }
5    }

AvoidOldSalesforceApiVersions 

Description: Detects usage of Salesforce API versions that are 3 or more years old.

Default Severity: 2 (High)

Default Tags: Recommended, Security, Xml

AvoidTermsWithImplicitBias 

Description: Detects usage of terms that reinforce implicit bias.

Default Severity: 5 (Info)

Default Tags: Recommended, BestPractices

More Information: Salesforce Updates Technical Language in Ongoing Effort to Address Implicit Bias.

MinVersionForAbstractVirtualClassesWithPrivateMethod 

Description: Detects private methods within abstract or virtual Apex classes when the corresponding API version of the class is less than 61.0.

Default Severity: 2 (High)

Default Tags: Recommended, BestPractices, Apex

Example(s):

  • [Bad] Code that causes a violation:
1public abstract class SomeAbstractClass {
2    public void somePublicMethod() {
3        somePrivateMethod();
4    }
5    private void somePrivateMethod() {
6        // ...
7    }
8}

With this metadata XML file:

1<?xml version="1.0" encoding="UTF-8"?>
2<ApexClass xmlns="http://soap.sforce.com/2006/04/metadata">
3    <!-- Here's a comment -->
4    <apiVersion>60.0</apiVersion>
5</ApexClass>

NoTrailingWhitespace 

Description: Detects trailing whitespace (tabs or spaces) at the end of lines of code and lines that are only whitespace.

Default Severity: 5 (Info)

Default Tags: Recommended, CodeStyle, Apex

NoMixedIndentation 

Description: Detect if tabs and spaces are mixed together. Mixing tabs and spaces can cause unexpected formatting issues, especially in the Developer Console.

Default Severity: Moderate (3)

Default Tags: Recommended

Example(s):

  • [Bad] Code that causes a violation:
1public class MyClass {
2⇥   String msg = '''    // Tab + spaces
3        Hello World
4    ''';
5}
  • [Clean] Code:
1public class MyClass {
2    String msg = '''    // Only spaces
3        Hello World
4    ''';
5}
1public class MyClass {
2⇥String msg = '''      // Only tabs
3⇥⇥Hello World
4⇥''';
5}