luau-lang / luau

A fast, small, safe, gradually typed embeddable scripting language derived from Lua
https://luau.org
MIT License
3.96k stars 372 forks source link

feat: support to ignore some checks using comments #1427

Open RodrigoDornelles opened 1 day ago

RodrigoDornelles commented 1 day ago

I'm working on a project that uses embed lua puc-rio, but I'm interested in luau-analyzer to check for inconsistent types and other lints.

The issue is that I have globals externally, and I wanted to somehow notify the linter that they exist.

-- @global bar_z
-- @global bar_y

local foo = {}
foo.z = bar_z
foo.y = bar_y

If there is already support for this, it could be a documentation issue, Otherwise, I think it would be interesting to be able to disable some rules for specific or global lines. instead of the entire linter disabled.


I know that there is --!nolint NAME at the beginning of the file, but it is very generic, unknown globals are TypeError but typing errors are also, in addition to the fact that I want to explicitly say variable or line to ignore some check.

JohnnyMorganz commented 9 hours ago

You can use a .luaurc file to specify globals. Does that fit your usecase? https://rfcs.luau-lang.org/config-luaurc

RodrigoDornelles commented 6 hours ago

You can use a .luaurc file to specify globals. Does that fit your usecase? https://rfcs.luau-lang.org/config-luaurc

@JohnnyMorganz

The issue of globals makes my case solved! but I would like to do this through comments because it would be part of the documentation.

--! @li
--! @lint global native_draw_line
--! [see](https://rodrigodornelles.github.io/core-native-sdl/a00020.html#gab7df3f76d238de241fe713fe91724d40)
std.draw.line = native_draw_line

but other cases, such as I would like to ignore the lint for just one line, as depending on the platform my buildsystem remove the line.

--! @lint ignore-next TypeError UnknownRequire
local math = require('math')

I would also like to say to linter that some globals are being used.

--! @lint ignore-next FunctionUnused
function native_callback_keyboard(key, value)
    std.key.press[key] = value
end

I'm not good with names, so it's just a functionality suggestion, many linters work like this, it's interesting to work with local configurations in order not to leave the entire project with weaker checking.