Trivadis / plsql-cop-cli

db* CODECOP Command Line
Other
25 stars 1 forks source link

Invalid JSON format produced in tvdcc_report.json when message contains double quotes #24

Closed PhilippSalvisberg closed 8 months ago

PhilippSalvisberg commented 8 months ago

When running the CLI using the Hint validator for a SQL file with the following content:

select /*+ fast */ /*+ leading(emp dep) */ *
  from emp e
  join dept d on d.deptno = e.deptno;
select * from dbms_xplan.display_cursor(format => 'basic +hint_report');

when get the following JSON output (excerpt):

    {
      "engineId": "db* CODECOP",
      "ruleId": "G-9601",
      "severity": "CRITICAL",
      "type": "CODE_SMELL",
      "primaryLocation": {
        "message": "G-9601: Never use unknown hints. "fast" is unknown.",
        "filePath": "src/demo/demo9600.sql",
        "textRange": {
          "startLine": 7,
          "endLine": 7,
          "startColumn": 11,
          "endColumn": 15
        }
      },
      "effortMinutes": 5
    },

You see that "fast" should be escaped to \"fast\" to make the JSON document valid.

Even if this bug is caused by the Hint validator the code producing the JSON file is responsible to produce a valid JSON format. So it's a bug of the CLI.

PhilippSalvisberg commented 8 months ago

fixed with Azure DevOps commit