Updated on 2024-11-28 GMT+08:00

Obtaining Rules

Function

This API is used to query the rules based on conditions such as language and issue severity.

Calling Method

For details, see Calling APIs.

URI

GET /v2/rules

Table 1 Query Parameters

Parameter

Mandatory

Type

Description

rule_languages

No

String

Language corresponding to a rule.

rule_severity

No

String

Issue severity. 0: critical; 1: major; 2: minor; 3: suggestion.

offset

No

Integer

Offset for pagination.

limit

No

Integer

Number of items on each page.

Request Parameters

Table 2 Request header parameters

Parameter

Mandatory

Type

Description

X-Auth-Token

Yes

String

User token.

It can be obtained by calling the IAM API used to obtain a user token. The value of X-Subject-Token in the response header is the user token.

Response Parameters

Status code: 200

Table 3 Response body parameters

Parameter

Type

Description

info

Array of RuleListItem objects

Rule information.

total

Integer

Total number.

Table 4 RuleListItem

Parameter

Type

Description

rule_set

String

Rule set classification.

rule_id

String

Rule ID.

rule_language

String

Language corresponding to the rule.

rule_name

String

Rule name.

rule_severity

String

Severity of issues corresponding to the rule.

rule_tages

String

Rule tag.

right_example

String

Compliant example.

error_example

String

Noncompliant example.

revise_opinion

String

Fix suggestion.

rule_desc

String

Rule description.

Status code: 400

Table 5 Response body parameters

Parameter

Type

Description

error_code

String

Error code.

error_msg

String

Error message.

Status code: 401

Table 6 Response body parameters

Parameter

Type

Description

error_code

String

Error code.

error_msg

String

Error message.

Example Requests

GET https://{endpoint}/v2/rules

Example Responses

Status code: 200

Request succeeded!

{
  "info" : [ {
    "rule_id" : "2561",
    "rule_language" : "Java",
    "rule_name" : "\"=+\" cannot be replaced by \"+=\".",
    "rule_severity" : "1",
    "rule_tages" : "bug",
    "rule_desc" : "<p>Use strict equality operator (<code>===</code>) to compare different types. The result is always <code>false</code>. </p>",
    "right_example" : "<pre>\nvar a = 8;\nvar b = \"8\";\n\nif (a == b) {\n  // ...\n}\n</pre>\n<p>or</p>\n<pre>\nvar a = 8;\nvar b = \"8\";\n\nif (a === Number(b)) {\n  // ...\n}\n</pre>",
    "error_example" : "<pre>\nvar a = 8;\nvar b = \"8\";\n\nif (a === b) {  //Noncompliant, always false\n  // ...\n}\n</pre>",
    "revise_opinion" : "None",
    "rule_set" : "HuaWeiJava"
  }, {
    "rule_id" : "8048",
    "rule_language" : "Java",
    "rule_name" : "\"Arrays.stream\" should be used for primitive arrays",
    "rule_severity" : "1",
    "rule_tages" : "performance",
    "rule_desc" : "<p>Use strict equality operator (<code>===</code>) to compare different types. The result is always <code>false</code>. </p>",
    "right_example" : "<pre>\nvar a = 8;\nvar b = \"8\";\n\nif (a == b) {\n  // ...\n}\n</pre>\n<p>or</p>\n<pre>\nvar a = 8;\nvar b = \"8\";\n\nif (a === Number(b)) {\n  // ...\n}\n</pre>",
    "error_example" : "<pre>\nvar a = 8;\nvar b = \"8\";\n\nif (a === b) {  //Noncompliant, always false\n  // ...\n}\n</pre>",
    "revise_opinion" : "None",
    "rule_set" : "HuaWeiJava"
  } ],
  "total" : 2
}

Status code: 400

Bad Request

{
  "error_code" : "CC.00000000",
  "error_msg" : "Network busy. Try again later."
}

Status code: 401

Unauthorized

{
  "error_code" : "CC.00000003",
  "error_msg" : "Authentication information expired."
}

Status Codes

Status Code

Description

200

Request succeeded!

400

Bad Request

401

Unauthorized

Error Codes

See Error Codes.