JSON Run Output Schema Reference

This example shows how to create a JSON-formatted output file when using the --output-file flag of the code-analyzer run command.

1sf code-analyzer run --output-file results.json

Sample JSON Run Output 

This sample output shows 3 violations with different severities from different engines.

1{
2  "runDir": "/Users/lisa.simpson/sfdx/coral-cloud-afdx/",
3  "violationCounts": {
4    "total": 3,
5    "sev1": 0,
6    "sev2": 1,
7    "sev3": 1,
8    "sev4": 1,
9    "sev5": 0
10  },
11  "versions": {
12    "code-analyzer": "0.25.1",
13    "eslint": "0.20.1",
14    "retire-js": "0.18.1",
15    "regex": "0.18.1",
16    "flow": "0.18.1",
17    "pmd": "0.21.0"
18  },
19  "violations": [
20    {
21      "rule": "@lwc/lwc/no-inner-html",
22      "engine": "eslint",
23      "severity": 2,
24      "tags": ["Recommended", "LWC", "Security", "Javascript"],
25      "primaryLocationIndex": 0,
26      "locations": [
27        {
28          "file": "force-app/main/default/staticresources/highlight/highlight/prism.js",
29          "startLine": 571,
30          "startColumn": 17,
31          "endLine": 571,
32          "endColumn": 26
33        }
34      ],
35      "message": "Using 'innerHTML/outputHTML/insertAdjacentHTML' is not allowed",
36      "resources": [
37        "https://github.com/salesforce/eslint-plugin-lwc/blob/v2.1.0/docs/rules/no-inner-html.md"
38      ]
39    },
40    {
41      "rule": "PreventPassingUserDataIntoElementWithSharing",
42      "engine": "flow",
43      "severity": 4,
44      "tags": ["Recommended", "Security", "Xml"],
45      "primaryLocationIndex": 1,
46      "locations": [
47        {
48          "file": "force-app/main/default/flows/Get_Customer_Details.flow-meta.xml",
49          "startLine": 90,
50          "startColumn": 1,
51          "comment": "email.email: Initialization"
52        },
53        {
54          "file": "force-app/main/default/flows/Get_Customer_Details.flow-meta.xml",
55          "startLine": 41,
56          "startColumn": 1,
57          "comment": "email.email influences Get_Contact_by_Email_and_Member_Number.Email: flow into recordLookups via influence over Email in run mode SystemModeWithSharing"
58        }
59      ],
60      "message": "User controlled data flows into recordLookups element selector in run mode: SystemModeWithSharing",
61      "resources": []
62    },
63    {
64      "rule": "ApexSharingViolations",
65      "engine": "pmd",
66      "severity": 3,
67      "tags": ["Recommended", "Security", "Apex"],
68      "primaryLocationIndex": 0,
69      "locations": [
70        {
71          "file": "force-app/main/default/classes/ExperienceBookingHelper.cls",
72          "startLine": 1,
73          "startColumn": 1,
74          "endLine": 1,
75          "endColumn": 7
76        }
77      ],
78      "message": "Apex classes should declare a sharing model if DML or SOQL/SOSL is used",
79      "resources": [
80        "https://docs.pmd-code.org/pmd-doc-7.11.0/pmd_rules_apex_security.html#apexsharingviolations"
81      ]
82    }
83  ]
84}

Top-Level Properties and Objects 

Property NameData TypeDescription
runDirstringThe directory from which the Code Analyzer analysis ran.
violationCountsObjectObject that contains the total number of violations and the aggregate counts for each severity level. See violationCounts Object Properties for details.
versionsObjectObject that contains the versions of the core Code Analyzer module and each engine module that ran in the analysis. See versions Object Properties for details.
violationsObject[]An array of objects, where each object corresponds to a violation that was detected in the analysis. See violations Object Properties for details.

violationCounts Object Properties 

Property NameData TypeDescription
totalnumberTotal number of violations found in the analysis.
sev1numberNumber of severity 1 (Critical) violations found.
sev2numberNumber of severity 2 (High) violations found.
sev3numberNumber of severity 3 (Moderate) violations found.
sev4numberNumber of severity 4 (Low) violations found.
sev5numberNumber of severity 5 (Info) violations found.

versions Object Properties 

Property NameData TypeDescription
code-analyzerstringVersion of the core Code Analyzer module.
cpdstringVersion of the CPD module.
eslintstringVersion of the ESLint module.
flowstringVersion of the Flow Scanner module.
pmdstringVersion of the PMD module.
retire-jsstringVersion of the RetireJS module.
regexstringVersion of the Regex module.
sfgestringVersion of the Salesforce Graph module.

violations Object Properties 

Property NameData TypeDescription
rulestringThe name of the rule that’s associated with the violation.
enginestringThe engine that’s associated with the violation.
severitynumberThe severity level of the violation: 1 (Critical), 2 (High), 3 (Moderate), 4 (Low), 5 (Info)
tagsstring[]An array of tags that are associated with the rule that’s associated with the violation.
primaryLocationIndexnumberThe index of the primary code location within the code locations array.
locationsObject[]An array of objects, where each object corresponds to a location in your code that’s associated with the violation. See locations Object Properties for details.
messagestringThe violation message.
resourcesstring[]An array of URLs for additional resources and information about the violation.

locations Object Properties 

Some rules, such as those that have a PathBased tag, can produce multiple code locations. These code locations make up the code path associated with the violation.

Property NameData TypeDescription
filestringThe pathname of the file in which the violation occurred, relative to the runDir directory.
startLinenumberThe line where the violating code starts.
startColumnnumberThe column in the startLine where the violating code starts.
endLinenumberThe line where the violating code ends.
endColumnnumberThe column in the endLine where the violating code ends.
commentstringComment that provides additional context associated with this line or block of code.