Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Info
iconfalse
titleTable of Contents

Table of Contents
maxLevel1

Get the Details of a Rule

DescriptionGet the details of a rule

URL

/api/rules/show

HTTP MethodGET
Response Formatsjson

Security

None

Examples

Use CaseExample Request
Get the details of rule "squid:S1219"

GET http://nemo.sonarsource.org/api/rules/show?key=squid:S1219

Response Format

Code Block
titleJSON
languagejavascript
{
    "rule":
        {
            "key":"squid:S1219",
            "name":"\"switch\" statements should not contain non-case labels","description":"<p>Even if it is...
            "createdAt":"2013-10-18T18:10:15+0200",
            "fCreatedAt":"Oct 18, 2013 6:10 PM",
            "updatedAt":"2014-02-26T13:05:07+0100",
            "fUpdatedAt":"Feb 26, 2014 1:05 PM",
            "tags":["mytag"],
            "sysTags":[]
        }
}

Parameters

Parameter

Description

Required

Default Value

Example Value

key

Rule key

Yes

None
squid:S1219

Get a List of Rules (New)

DescriptionGet a list of rules

URL

/api/rules/list

HTTP MethodGET
Response Formatsjson

Security

None

Available SinceVersion 4.3

Examples

Use CaseExample Request
Get all JavaScript rules whose characteristic is RELIABILITY

GET http://localhost:9000/api/rules/list?languages=js&debtCharacteristics=RELIABILITY

Response Format

Code Block
titleJSON
languagejavascript
{
  "results":
    [
      {
        "key":"javascript:S1442",
        "repository":"javascript",
        "name":"\"alert(...)\" should not be used",
        "language":"JavaScript",
        "status":"READY"
      },
      {
        "key":"javascript:EqEqEq",
        "repository":"javascript",
        "name":"\"===\" and \"!==\" should be used instead of \"==\" and \"!=\"",
        "language":"JavaScript",
        "status":"READY",
        "debtCharacteristic":"RELIABILITY",
        "debtSubCharacteristic":"INSTRUCTION_RELIABILITY",
        "debtRemediationFunction":"LINEAR",
        "debtRemediationCoefficient":"30min"
      }
    ],
    "more":false,
    "total":2
}

Parameters

Parameter

Description

Required

Default Value

Example Value

k

Key of the rule

No

None
findbugs:DMI_USELESS_SUBSTRING

debtCharacteristics

Comma-separated list of characteristics / sub-characteristics

No

None

MAINTAINABILITY,CHANGEABILITY

hasDebtCharacteristic

Determine if returned rules should be linked to a debt characteristic or not.

Possible values: true | false

No

true

true

languages

Comma-separated list of language keys

No

None

java,js

severities

Comma-separated list of severities

Possible values: INFO | MINOR | MAJOR | CRITICAL | BLOCKER

No

None

BLOCKER,CRITICAL

repositories

Comma-separated list of repositories

No

None

squid,findbugs

statuses

Comma-separated list of statuses

Possible values: READY | BETA | DEPRECATED

No

None

READY,BETA

tags

Comma-separated list of tags. The rule is returned if it matches at least of one these tags.

No

None

error-handling,java8

s

To return rules whose title contains this string

No

None

Correctness

p

Page number

No

0

1

ps

Page size

No

25

1

Get a List of Rules

DescriptionGet a list of rules

URL

/api/rules

HTTP MethodGET
Response Formatsjson | xml | csv

Security

None

Examples

Use CaseExample Request
Get all the java rules

GET http://nemo.sonarsource.org/api/rules?language=java

Get all the java rules from pmd and findbugs

GET http://nemo.sonarsource.org/api/rules?language=java&plugin=pmd,findbugs

Response Format

Code Block
titleJSON
languagejavascript
[
  {
    "title":"@deprecated Tag",
    "key":"checkstyle:com.puppycrawl.tools.checkstyle.checks.TodoCommentCheck_1296413307",
    "plugin":"checkstyle",
    "config_key":"Checker/TreeWalker/TodoComment",
    "description":"",
    "priority":"INFO",
    "params":[
      {
        "name":"format",
        "description":"Regular expression pattern to check. Default is TODO:"
      }
    ]
  },
  ...
]

Parameters

Parameter

Description

Required

Default Value

Example Value

language

Key of the language

No

Nonejava

plugin

Comma-separated list of rules plugins

No

None

findbugs,pmd

searchtext

To filter on rules containing a specified text in their name, key or title

No

None

braces

profile

When this parameter is defined, a node 'status' is added for each 'rule' node with values 'INACTIVE' or 'ACTIVE'.
It is recommended to use the /api/profiles web service instead. 

No

None

Sonar%20way

priorities

List of INACTIVE, ACTIVE, BLOCKER, CRITICAL, MAJOR, MINOR, INFO.
It is recommended to use the /api/profiles web service instead of ACTIVE and INACTIVE.

No

None

BLOCKER,CRITICAL

format

Response formats.
Possible valuesformat can be set through:

  • Parameter format: xml | json | csv
  • Or the 'Accept' property in the HTTP header:
    • Accept:text/xml
    • Accept:application/json
If nothing is set, json is used.
NoNonejson

Add Tags to a Rule

DescriptionAdd tags to a rule

URL

/api/rule_tags/add

HTTP MethodPOST

Security

Requires Administer Quality Profiles permission

Available sinceVersion 4.2

Examples

Use CaseExample Request
Add tags "mytag" and "yourtag" to rule "squid:S1219" 

curl -X POST -v -u admin:admin "http://localhost:9000/api/rules/add_tags?key=squid:S1219&tags=mytag,yourtag"

Parameters

Parameter

Description

Required

Default Value

Example Value

key

Rule keyYes

None

squid:S1219

tagsComma-separated list of tagsYesNonemytag,yourtag

Remove Tags From a Rule

DescriptionRemove tags from a rule

URL

/api/rule_tags/remove

HTTP MethodPOST

Security

Requires Administer Quality Profiles permission

Available sinceVersion 4.2

Examples

Use CaseExample Request
Remove tags "mytag" and "yourtag" from rule "squid:S1219" 

curl -X POST -v -u admin:admin "http://localhost:9000/api/rules/remove_tags?key=squid:S1219&tags=mytag,yourtag"

Parameters

Parameter

Description

Required

Default Value

Example Value

key

Rule keyYes

None

squid:S1219

tagsComma-separated list of tagsYesNonemytag,yourtag