Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Custom rule - check only once #5873

Open
salvatoreboemia opened this issue Nov 29, 2024 · 1 comment
Open

Custom rule - check only once #5873

salvatoreboemia opened this issue Nov 29, 2024 · 1 comment
Labels
help Questions or user problems that require more explanation rather than code changes. resolved Issues that are resolved from a maintainer's point of view. They can be just closed after a while.

Comments

@salvatoreboemia
Copy link

Hi

I'm trying to add custom rules to send to Sonarqube. but first I tried locally with a brew in this way

custom_rules:
   my_custom_rule: 
     included:
     - ".*.swift"
     name: "My Custom Rule"
     regex: "// my_custom_rule:.*"
     message: "This is a custom rule for testing"
     severity: error

After that I ran in the terminal swift lint

swiftlint lint --config myRoot/.swiftlint.yml --reporter json > swiftlint_report.json 

File Swift


// my_custom_rule: Test 1234
import Foundation
import UIKit
// my_custom_rule: Test 12
final class MyClass: NSObject {
    // my_custom_rule: Test 1234
    ......
    // my_custom_rule: Test 1234
    private let .......
    ......
    // my_custom_rule: Test 1234
    var .....
    // my_custom_rule: Test 
  .....

JSON

{
    "character" : 1,
    "file" : "/myFile.swift",
    "line" : 9,
    "reason" : "This is a custom rule for testing",
    "rule_id" : "my_custom_rule",
    "severity" : "Error",
    "type" : "My Custom Rule"
  },

Why only in the line 9? I added a lot of comment, Do you know somethings?

thanks

@SimplyDanny
Copy link
Collaborator

That's described in the README. First, you may want to add the comment match kind to only match in comments, that is:

match_kinds:
  - comment

This probably already helps in your example.

Yet even more relevant is:

It is important to note that the regular expression pattern is used with the flags s and m enabled, that is . matches newlines and ^/$ match the start and end of lines, respectively. If you do not want to have . match newlines, for example, the regex can be prepended by (?-s).

@SimplyDanny SimplyDanny added help Questions or user problems that require more explanation rather than code changes. resolved Issues that are resolved from a maintainer's point of view. They can be just closed after a while. labels Nov 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help Questions or user problems that require more explanation rather than code changes. resolved Issues that are resolved from a maintainer's point of view. They can be just closed after a while.
Projects
None yet
Development

No branches or pull requests

2 participants