Initial commit

This commit is contained in:
Patrick Alvin Alcala 2025-06-26 16:53:43 +08:00
commit 209ba130c0
4852 changed files with 1517959 additions and 0 deletions

View file

@ -0,0 +1,28 @@
-- luacheck plugin for lint+
--- CONFIG ---
-- config.lint.luacheck_args: table[string]
-- passes the specified arguments to luacheck
--- IMPLEMENTATION ---
local lintplus = require "plugins.lintplus"
lintplus.add("luacheck") {
filename = "%.lua$",
procedure = {
command = lintplus.args_command(
{ "luacheck",
lintplus.args,
"--formatter",
"visual_studio",
lintplus.filename },
"luacheck_args"
),
interpreter = lintplus.interpreter {
warning = "(.-)%((%d+),(%d+)%) : warning .-: (.+)",
error = "(.-)%((%d+),(%d+)%) : error .-: (.+)",
}
},
}

View file

@ -0,0 +1,37 @@
-- Nelua plugin for lint+
--- CONFIG ---
-- config.lint.nelua_mode: "analyze" | "lint"
-- changes the linting mode, "analyze" (default) does a complete checking,
-- while "lint" only checks for syntax errors.
--- IMPLEMENTATION ---
local core = require 'core'
local lintplus = require 'plugins.lintplus'
local mode = lintplus.config.nelua_mode or "analyze"
if mode ~= "analyze" and mode ~= "lint" then
core.error("lint+/nelua: invalid nelua_mode '%s'. Available modes: 'analyze', 'lint'", mode)
mode = "lint"
end
local command = lintplus.command {
'nelua',
'--no-color',
'--'..mode,
lintplus.filename
}
lintplus.add 'nelua' {
filename = '%.nelua$',
procedure = {
command = command,
interpreter = lintplus.interpreter {
error = "(.-):(%d+):(%d+):.-error: (.+)"
},
},
}

View file

@ -0,0 +1,49 @@
-- Nim plugin for lint+
--- CONFIG ---
-- config.lint.use_nimc: bool
-- switches the linting backend from `nim check` to `nim c`. this can
-- eliminate certain kinds of errors but is less safe due to `nim c` allowing
-- staticExec
-- config.lint.nim_args: string
-- passes the specified arguments to the lint command.
-- extra arguments may also be passed via a nim.cfg or config.nims.
--- IMPLEMENTATION ---
local lintplus = require "plugins.lintplus"
local nullfile
if PLATFORM == "Windows" then
nullfile = "NUL"
elseif PLATFORM == "Linux" then
nullfile = "/dev/null"
end
local cmd = {
"nim",
"--listFullPaths",
"--stdout",
lintplus.args,
}
if nullfile == nil or not lintplus.config.use_nimc then
table.insert(cmd, "check")
else
table.insert(cmd, "-o:" .. nullfile)
table.insert(cmd, "c")
end
table.insert(cmd, lintplus.filename)
lintplus.add("nim") {
filename = "%.nim$",
procedure = {
command = lintplus.args_command(cmd, "nim_args"),
interpreter = lintplus.interpreter {
hint = "(.-)%((%d+), (%d+)%) Hint: (.+)",
warning = "(.-)%((%d+), (%d+)%) Warning: (.+)",
error = "(.-)%((%d+), (%d+)%) Error: (.+)",
strip = "%s%[%w+%]$",
},
},
}

View file

@ -0,0 +1,40 @@
-- PHP lint plugin for lint+
--- CONFIG ---
-- config.lint.php_args: {string}
-- passes the specified arguments to php
--- IMPLEMENTATION ---
local lintplus = require "plugins.lintplus"
lintplus.add("php") {
filename = "%.php$",
procedure = {
command = lintplus.args_command(
{
"php",
"-l",
lintplus.args,
lintplus.filename
},
"php_args"
),
interpreter = function (filename, line, context)
local line_processed = false
return function ()
if line_processed then
return nil
end
local message, file, line_num = line:match(
"[%a ]+:%s*(.*)%s+in%s+(%g+)%s+on%sline%s+(%d+)"
)
if line_num then
line_processed = true
return filename, tonumber(line_num), 1, "error", message
end
end
end
},
}

View file

@ -0,0 +1,16 @@
local lintplus = require "plugins.lintplus"
lintplus.add("flake8") {
filename = "%.py$",
procedure = {
command = lintplus.command(
{ "flake8",
lintplus.filename },
"flake8_args"
),
interpreter = lintplus.interpreter {
warning = "(.-):(%d+):(%d+): [FCW]%d+ (.+)",
error = "(.-):(%d+):(%d+): E%d+ (.+)",
}
},
}

View file

@ -0,0 +1,181 @@
-- Rust plugin for lint+
--- IMPLEMENTATION ---
local common = require "core.common"
local core = require "core"
local lintplus = require "plugins.lintplus"
local json = require "plugins.lintplus.json"
-- common functions
local function no_op() end
local function parent_directories(filename)
return function ()
filename = lintplus.fs.parent_directory(filename)
return filename
end
end
-- message processing
local function message_spans_multiple_lines(message, line)
if #message.spans == 0 then return false end
for _, span in ipairs(message.spans) do
if span.line_start ~= line then
return true
end
end
for _, child in ipairs(message.children) do
local child_spans_multiple_lines = message_spans_multiple_lines(child, line)
if child_spans_multiple_lines then
return true
end
end
return false
end
local function process_message(
context,
message,
out_messages,
rail
)
local msg = message.message
local span = message.spans[1]
local kind do
local l = message.level
if l == "error" or l == "warning" then
kind = l
elseif l == "error: internal compiler error" then
kind = "error"
else
kind = "info"
end
end
local nonprimary_spans = 0
for _, sp in ipairs(message.spans) do
if not sp.is_primary then
nonprimary_spans = nonprimary_spans + 1
end
end
-- only assign a rail if there are children or multiple non-primary spans
if span ~= nil then
local filename = context.workspace_root .. '/' .. span.file_name
local line, column = span.line_start, span.column_start
if rail == nil then
if message_spans_multiple_lines(message, line) then
rail = context:create_gutter_rail()
end
end
for _, sp in ipairs(message.spans) do
if sp.label ~= nil and not sp.is_primary then
local s_filename = context.workspace_root .. '/' .. span.file_name
local s_line, s_column = sp.line_start, sp.column_start
table.insert(out_messages,
{ s_filename, s_line, s_column, "info", sp.label, rail })
end
end
if span.suggested_replacement ~= nil then
local suggestion = span.suggested_replacement:match("(.-)\r?\n")
if suggestion ~= nil then
msg = msg .. " `" .. suggestion .. '`'
end
end
table.insert(out_messages, { filename, line, column, kind, msg, rail })
end
for _, child in ipairs(message.children) do
process_message(context, child, out_messages, rail)
end
end
local function get_messages(context, event)
-- filename, line, column, kind, message
local messages = {}
process_message(context, event.message, messages)
return messages
end
-- linter
lintplus.add("rust") {
filename = "%.rs$",
procedure = {
init = function (filename, context)
local process = lintplus.ipc.start_process({
"cargo", "locate-project", "--workspace"
}, lintplus.fs.parent_directory(filename))
while true do
local exit, _ = process:poll(function (line)
local ok, process_result = pcall(json.decode, line)
if not ok then return end
context.workspace_root =
lintplus.fs.parent_directory(process_result.root)
end)
if exit ~= nil then break end
end
end,
command = lintplus.command {
set_cwd = true,
"cargo", "clippy",
"--message-format", "json",
"--color", "never",
-- "--tests",
},
interpreter = function (filename, line, context)
-- initial checks
if context.workspace_root == nil then
core.error(
"lint+/rust: "..filename.." is not situated in a cargo crate"
)
return no_op
end
if line:match("^ *Blocking") then
return "bail"
end
local ok, event = pcall(json.decode, line)
if not ok then return no_op end
if event.reason == "compiler-message" then
local messages = get_messages(context, event)
local i = 1
return function ()
local msg = messages[i]
if msg ~= nil then
i = i + 1
return table.unpack(msg)
else
return nil
end
end
else
return no_op
end
end,
},
}

View file

@ -0,0 +1,42 @@
-- shellcheck plugin for lint+
--- INSTALLATION ---
-- In order to use this linter, please ensure you have the shellcheck binary
-- in your path. For installation notes please see
-- https://github.com/koalaman/shellcheck#user-content-installing
--- CONFIG ---
-- config.lint.shellcheck_args: table[string]
-- passes the given arguments to shellcheck.
--- IMPLEMENTATION ---
local lintplus = require "plugins.lintplus"
lintplus.add("shellcheck") {
filename = "%.sh$",
syntax = {
"Shell script",
"shellscript",
"bashscript",
"Bash script",
"Bash",
"bash",
},
procedure = {
command = lintplus.args_command(
{ "shellcheck",
"--format=gcc",
lintplus.args,
lintplus.filename
},
"shellcheck_args"
),
interpreter = lintplus.interpreter {
info = "(.*):(%d+):(%d+): note: (.+)",
error = "(.*):(%d+):(%d+): error: (.+)",
warning = "(.*):(%d+):(%d+): warning: (.+)",
}
},
}

View file

@ -0,0 +1,68 @@
-- v plugin for lint+
--- INSTALLATION ---
-- In order to use this linter, please ensure you have the v binary
-- in your $PATH. For installation notes please see
-- https://github.com/vlang/v/blob/master/doc/docs.md#installing-v-from-source
--- CONFIG ---
-- config.lint.v_mode: "check" | "check-syntax"
-- changes the linting mode. check scans, parses, and checks the files
-- without compiling the program (default),
-- check-syntax only scan and parse the files, but then stops.
-- Useful for very quick syntax checks.
-- config.lint.v_args: table[string]
-- passes the given arguments to v.
--- IMPLEMENTATION ---
local core = require "core"
local lintplus = require "plugins.lintplus"
local mode = lintplus.config.v_mode or "check"
if mode ~= "check" and mode ~= "check-syntax" then
core.error("lint+/v: invalid v_mode '%s'. "..
"available modes: 'check', 'check-syntax'")
return
end
local command
if mode == "check" then
command = lintplus.command {
"v",
"-check",
"-nocolor",
"-shared",
"-message-limit", "-1",
lintplus.args,
lintplus.filename
}
elseif mode == "check-syntax" then
command = lintplus.args_command({
"v",
"-check-syntax",
"-nocolor",
"-shared",
"-message-limit", "-1",
lintplus.args,
lintplus.filename
}, "v_args")
end
lintplus.add("v") {
filename = "%.v$",
syntax = {
"V",
"v",
"Vlang",
"vlang",
},
procedure = {
command = command,
interpreter = lintplus.interpreter {
error = "(.*):(%d+):(%d+): error: (.+)",
warning = "(.*):(%d+):(%d+): warning: (.+)",
},
},
}

View file

@ -0,0 +1,54 @@
-- Zig plugin for lint+
--- CONFIG ---
-- config.lint.zig_mode: "ast-check" | "build"
-- changes the linting mode. ast-check is a quick'n'dirty check (default),
-- build compiles the tests in a file (but does not run them).
-- config.lint.zig_args: table[string]
-- passes the given table of arguments to zig test. this does not have any
-- effect in "ast-check" mode.
--- IMPLEMENTATION ---
local core = require "core"
local lintplus = require "plugins.lintplus"
local mode = lintplus.config.zig_mode or "ast-check"
if mode ~= "ast-check" and mode ~= "build" then
core.error("lint+/zig: invalid zig_mode '%s'. "..
"available modes: 'ast-check', 'build'")
return
end
local command
if mode == "ast-check" then
command = lintplus.command {
"zig",
"ast-check",
"--color", "off",
lintplus.filename
}
elseif mode == "build" then
command = lintplus.args_command({
"zig",
"test",
"--color", "off",
"-fno-emit-bin",
lintplus.args,
lintplus.filename
}, "zig_args")
end
lintplus.add("zig") {
filename = "%.zig$",
procedure = {
command = command,
interpreter = lintplus.interpreter {
hint = "(.-):(%d+):(%d+): note: (.+)",
error = "(.-):(%d+):(%d+): error: (.+)",
warning = "(.-):(%d+):(%d+): warning: (.+)",
}
},
}