rules:
  - id: avoid-operations-with-limits-in-loops
    min-version: 1.44.0
    severity: ERROR
    languages:
      - generic
    metadata:
      category: performance
      references:
      - https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_gov_limits.htm
      technology:
      - salesforce
    message: >-
      Database class methods, DML operations, SOQL queries, SOSL queries,
      Approval class methods, Email sending, async scheduling or queueing
      within loops can cause governor limit exceptions. Instead, try to
      batch up the data into a list and invoke the operation once on that
      list of data outside the loop.
    patterns:
      - pattern-either:
          - pattern-inside: |
              for (...) {
                ...
              }
          - pattern-inside: |
              while (...) {
                ...
              }
          - pattern-inside: |
              do {
                ...
              } while (...);
      - pattern-either:
        - pattern: |
            Messaging.sendEmail(...);
        - pattern: |
            Approval.ProcessSubmitRequest $REQUEST = new Approval.ProcessSubmitRequest();
        - pattern: |
            System.enqueueJob(...);
        - pattern: |
            System.schedule(...);
        - pattern: |
            System.scheduleBatch(...);
