Skip to content

Commit

Permalink
fix: luacheck
Browse files Browse the repository at this point in the history
  • Loading branch information
yeshan333 committed Dec 18, 2024
1 parent 525ffc8 commit 8c5cef1
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 1 deletion.
1 change: 1 addition & 0 deletions spec/cli_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -981,6 +981,7 @@ not ok 8 spec/samples/python_code.lua:1:6: (E011) expected '=' near '__future__'
end)

it("has built-in Sarif formatter", function()
-- luacheck: ignore 631
local expect = [[
{"runs":[{"tool":{"driver":{"version":"1.0.0","name":"luacheck","informationUri":"https://github.com/lunarmodules/luacheck"}},"results":[{"locations":[{"physicalLocation":{"artifactLocation":{"uri":"bad_file"}}}],"ruleId":"I/O error","level":"error","message":{"text":"luacheck : fatal error F1: couldn't check bad_file: couldn't read: No such file or directory"}},{"locations":[{"physicalLocation":{"region":{"startLine":3,"startColumn":16},"artifactLocation":{"uri":"spec/samples/bad_code.lua"}}}],"ruleId":"W211","level":"warning","message":{"text":"spec/samples/bad_code.lua:3:16: unused function 'helper'"}},{"locations":[{"physicalLocation":{"region":{"startLine":3,"startColumn":23},"artifactLocation":{"uri":"spec/samples/bad_code.lua"}}}],"ruleId":"W212","level":"warning","message":{"text":"spec/samples/bad_code.lua:3:23: unused variable length argument"}},{"locations":[{"physicalLocation":{"region":{"startLine":7,"startColumn":10},"artifactLocation":{"uri":"spec/samples/bad_code.lua"}}}],"ruleId":"W111","level":"warning","message":{"text":"spec/samples/bad_code.lua:7:10: setting non-standard global variable 'embrace'"}},{"locations":[{"physicalLocation":{"region":{"startLine":8,"startColumn":10},"artifactLocation":{"uri":"spec/samples/bad_code.lua"}}}],"ruleId":"W412","level":"warning","message":{"text":"spec/samples/bad_code.lua:8:10: variable 'opt' was previously defined as an argument on line 7"}},{"locations":[{"physicalLocation":{"region":{"startLine":9,"startColumn":11},"artifactLocation":{"uri":"spec/samples/bad_code.lua"}}}],"ruleId":"W113","level":"warning","message":{"text":"spec/samples/bad_code.lua:9:11: accessing undefined variable 'hepler'"}},{"locations":[{"physicalLocation":{"region":{"startLine":1,"startColumn":6},"artifactLocation":{"uri":"spec/samples/python_code.lua"}}}],"ruleId":"E011","level":"error","message":{"text":"spec/samples/python_code.lua:1:6: expected '=' near '__future__'"}}]}],"version":"2.1.0","$schema":"https://json.schemastore.org/sarif-2.1.0.json"}
]]
Expand Down
3 changes: 2 additions & 1 deletion src/luacheck/format.lua
Original file line number Diff line number Diff line change
Expand Up @@ -318,13 +318,14 @@ function format.builtin_formatters.plain(report, file_names, opts)
return table.concat(buf, "\n")
end

-- https://docs.github.com/en/code-security/code-scanning/integrating-with-code-scanning/sarif-support-for-code-scanning
function format.builtin_formatters.Sarif(report, file_names, opts)
opts.color = false
local get_level = function(event)
return event.code:sub(1, 1) == "0" and "error" or "warning"
end

-- SARIF support for code scanning: https://docs.github.com/en/code-security/code-scanning/integrating-with-code-scanning/sarif-support-for-code-scanning
-- SARIF support for GitHub code scanning
local sarif_output = {
["$schema"] = "https://json.schemastore.org/sarif-2.1.0.json",
version = "2.1.0",
Expand Down

0 comments on commit 8c5cef1

Please sign in to comment.