Skip to content

[Feedback] Custom Regex Rule: Location result seems off #1880

@Szandor72

Description

@Szandor72

Feedback

Hello,

I have created a custom regex rule as per documentation. I am using the "No Todo" Rule which is also offered as an example in the code-analyzer file.

When looking at results, I noticed that the location is always indicated as 1:someColumn - 1:someLaterColumn, that is: violations are reported as being located at line 1.

I want to create annotations in GitHub PRs at the exact location but the current results won't help.

Context

Class with comment (snippet), class name: ContentDocumentTriggerHandler

Image

Rule configuration:

      "NoTodoComments":
        regex: /\/\/[ \t]*TODO/gi
        file_extensions: [".apex", ".cls", ".trigger"]
        description: "Prevents TODO comments from being in apex code."
        violation_message: "A comment with a TODO statement was found. Please remove TODO statements from your apex code."
        severity: "Info"
        tags: ["TechDebt"]

Results:

 {
      "rule": "NoTodoComments",
      "engine": "regex",
      "severity": 5,
      "tags": [
        "TechDebt"
      ],
      "primaryLocationIndex": 0,
      "locations": [
        {
          "file": "temp\\classes\\ContentDocumentTriggerHandler.cls",
          "startLine": 1,
          "startColumn": 2198,
          "endLine": 1,
          "endColumn": 2205
        }
      ],
      "message": "A comment with a TODO statement was found. Please remove TODO statements from your apex code.",
      "resources": []
    },

Suggestions

I would love to have location info that matches the class I see.

Additional Information

I also checked the default regex rules - I can see the same behavior / location information there. All results are indicated at line 1.

Are you interested in contributing to this project?

Yes, I'd like to contribute.

Metadata

Metadata

Assignees

No one assigned

    Labels

    BUG P3Rarely Malfunction

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions