joereynolds / sql-lint

An SQL linter
MIT License
438 stars 40 forks source link

linter is parsing keywords within strings #233

Open LukeWakelingKT opened 2 years ago

LukeWakelingKT commented 2 years ago

The linter should ignore keywords inside properly quoted strings, here it's found the word limit inside a string which should not be invalid.

const sqlLint = require('sql-lint').default;

const main = async function (sqlQuery) {
    const SQLerrors = await sqlLint({ driver: "postgres", sql: sqlQuery });
    console.log(SQLerrors);
}

main("INSERT INTO my_table (notes) VALUES ('speed limit sign');")

returns:

[
  {
    source: '',
    error: "[sql-lint: invalid-limit-quantifier] Argument 'sign' is not a valid quantifier for LIMIT clause.",
    line: 1,
    additionalInformation: ''
  }
]
LukeWakelingKT commented 2 years ago

version:

"node_modules/sql-lint": {
      "version": "1.0.0",
      "resolved": "https://registry.npmjs.org/sql-lint/-/sql-lint-1.0.0.tgz",
      "integrity": "sha512-9o4Oww+IhFFLzPbmMSPNr+uDpk6xjrCYHSpRtqD+dPIu/pU2hdZhokfmgms9zq/3IKmnmoA5+KQdCgGFE2Uj8A==",
      "dependencies": {
        "@types/moo": "^0.5.3",
        "@types/nearley": "^2.11.1",
        "@types/node": "^14.0.14",
        "@types/pg": "^7.14.11",
        "@types/sprintf-js": "^1.1.2",
        "commander": "^5.1.0",
        "moo": "^0.5.1",
        "mysql2": "^2.2.5",
        "nearley": "^2.19.3",
        "param-case": "^3.0.3",
        "pg": "^8.6.0",
        "sprintf-js": "^1.1.2"
      },
      "bin": {
        "sql-lint": "dist/src/cli.js"
      }
    },