What format is json expected for from_json #780
-
Hello all, I have spent three hours looking through the code trying to find out how File Contents of a SQL Fileselect *,,
from whatever.table p
where p.id = 1 SQLFluff Output➜ sqlfluff lint --dialect postgres -f github-annotation test.sql
[{"file": "test.sql", "line": 1, "start_column": 1, "end_column": 1, "title": "SQLFluff", "message": "PRS: Line 1, Position 1: Found unparsable section: 'select *,,'", "annotation_level": "notice"}, {"file": "test.sql", "line": 1, "start_column": 10, "end_column": 10, "title": "SQLFluff", "message": "L008: Commas should be followed by a single whitespace unless followed by a comment.", "annotation_level": "notice"}, {"file": "test.sql", "line": 2, "start_column": 21, "end_column": 21, "title": "SQLFluff", "message": "L011: Implicit/explicit aliasing of table.", "annotation_level": "notice"}, {"file": "test.sql", "line": 2, "start_column": 21, "end_column": 21, "title": "SQLFluff", "message": "L031: Avoid aliases in from clauses and join conditions.", "annotation_level": "notice"}] Null-LS Custom Diagnostic Helperlocal null_ls = require("null-ls")
local helpers = require("null-ls.helpers")
local sqlfluff = {
name = "SQL Fluff",
method = null_ls.methods.DIAGNOSTICS,
filetypes = { "sql" },
-- null_ls.generator creates an async source
-- that spawns the command with the given arguments and options
generator = null_ls.generator({
command = "sqlfluff",
args = { "lint", "-f", "github-annotation", "$FILENAME"},
-- choose an output format (raw, json, or line)
format = "json",
check_exit_code = function(code, stderr)
local success = code <= 1
if not success then
-- can be noisy for things that run often (e.g. diagnostics), but can
-- be useful for things that run on demand (e.g. formatting)
print(stderr)
end
return success
end,
-- use helpers to parse the output from string matchers,
-- or parse it manually with a function
on_output = helpers.diagnostics.from_json({
attributes = {
row = "line",
col = "start_column",
end_col = "end_column",
severity = "annotation_level",
message = "message",
},
severities = {
helpers.diagnostics.severities["information"],
helpers.diagnostics.severities["warning"],
helpers.diagnostics.severities["error"],
helpers.diagnostics.severities["hint"],
},
}),
}),
}
return {sqlfluff = sqlfluff} I have tried printing the parsed.output in a custom function but that The diagnostic message given by [null-ls] [WARN 19:19:46] ...ack/packer/start/null-ls.nvim/lua/null-ls/generators.lua:78: failed to run generator: ...t/null-ls.nvim/lua/null-ls/helpers/generator_factory.lua:232: error in generator output
: [{"file": "/home/mike/projects/testsql/test.sql", "line": 1, "start_column": 1, "end_column": 1, "title": "SQLFluff", "message": "PRS: Line 1, Position 1: Found unparsable section: 'select *,,'", "annotat
ion_level": "notice"}, {"file": "/home/mike/projects/testsql/test.sql", "line": 1, "start_column": 10, "end_column": 10, "title": "SQLFluff", "message": "L008: Commas should be followed by a single whitespa
ce unless followed by a comment.", "annotation_level": "notice"}, {"file": "/home/mike/projects/testsql/test.sql", "line": 2, "start_column": 21, "end_column": 21, "title": "SQLFluff", "message": "L011: Imp
licit/explicit aliasing of table.", "annotation_level": "notice"}, {"file": "/home/mike/projects/testsql/test.sql", "line": 2, "start_column": 21, "end_column": 21, "title": "SQLFluff", "message": "L031: Av
oid aliases in from clauses and join conditions.", "annotation_level": "notice"}] So something is getting parsed but it doesn't seem to know how to iterate it. Any help |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
Looks like the issue is that the linter is outputting its JSON to |
Beta Was this translation helpful? Give feedback.
Looks like the issue is that the linter is outputting its JSON to
stderr
. Try settingfrom_stderr = true
in the generator options.