Skip to content
This repository has been archived by the owner on Jan 30, 2023. It is now read-only.

Search rule by key #148

Merged
merged 3 commits into from
Jan 27, 2019
Merged

Search rule by key #148

merged 3 commits into from
Jan 27, 2019

Conversation

satabin
Copy link
Contributor

@satabin satabin commented Jan 23, 2019

For custom rules created from a template rule, the internalKey is set
to the internal key of the template rule by Sonar and not the custom
rule key. When looking up the rule by internal key and providing the
custom rule key, nothing is found as they do not match.

Here is the rule created in sonarqube
rule-screen

and the API returns the following object:

{
      "key": "sonar-scala-scalastyle:test_test",
      "repo": "sonar-scala-scalastyle",
      "name": "test",
      "createdAt": "2019-01-23T16:23:58+0000",
      "severity": "MINOR",
      "internalKey": "org.scalastyle.file.RegexChecker-template",
      "templateKey": "sonar-scala-scalastyle:org.scalastyle.file.RegexChecker-template",
      "lang": "scala",
      "params": [
        {
          "key": "line",
          "htmlDesc": "Line: Boolean whether to process line by line",
          "type": "BOOLEAN"
        },
        {
          "key": "regex",
          "htmlDesc": "Regular expression: Standard Scala regular expression syntax including multiline",
          "defaultValue": "\\*>",
          "type": "STRING"
        },
        {
          "key": "ruleClass",
          "htmlDesc": "Scalastyle's rule (checker) class name.",
          "type": "STRING"
        }
      ],
      "type": "CODE_SMELL"
}

Using the rule key with repository to lookup fo rules ensures that even custom rules are found.

@BalmungSan
Copy link
Contributor

@satabin Good catch and Thanks! for the contribution.
Could you please also add an unit test case that should fail before the fix and pass now?

@satabin
Copy link
Contributor Author

satabin commented Jan 24, 2019

Yes, I will do that.

For custom rules created from a template rule, the `internalKey` is set
to the internal key of the template rule by Sonar and not the custom
rule key. When looking up the rule by internal key and providing the
custom rule key, nothing is found as they do not match.
@satabin
Copy link
Contributor Author

satabin commented Jan 24, 2019

I added a test and took the occasion to fix another one that was not checking anything.

Copy link
Contributor

@BalmungSan BalmungSan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great, Thanks! 👍

Copy link
Member

@mwz mwz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice one - thanks for contributing and implementing the tests which @BalmungSan asked for. I've made a minor inline comment about your testing style and I'll be happy to merge and release as soon you've addressed it. Thanks again 👍

The `===` must be used in combination with `assert` or `should` to
actually test equality, otherwise, it simply behaves as a type safe
equality returning `false` in case of inequality.
@mwz
Copy link
Member

mwz commented Jan 27, 2019

Thanks for the fix @satabin.

@mwz mwz merged commit c04474e into sonar-scala:master Jan 27, 2019
@satabin satabin deleted the fix/find-rule-by-key branch January 27, 2019 16:19
@mwz
Copy link
Member

mwz commented Jan 27, 2019

Released as 7.3.1.

@satabin
Copy link
Contributor Author

satabin commented Jan 27, 2019

Awesome, thanks!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants