Trivadis / plsql-cop-cli

db* CODECOP Command Line

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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

PhilippSalvisberg opened this issue · comments

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.