Skip to content

Feature Request: Add an option to require type annotations #3447

Description

@ColinKennedy

Desire

I would like a way for lua-language-server to apply a "strict" mode to the functions and tables variables of lua files. e.g. if a function takes at least one parameter or has at least one return <foo> statement, it would error if that function doesn't also have a ---@param / ---@return statement to match it.

Issue

There seems to be some arguments that can make lua-language-server more strict, for example these:

.luarc.json

{
    "diagnostics": {
        "neededFileStatus": {
            "incomplete-signature-doc": "Any",
            "missing-global-doc": "Any",
            "missing-local-export-doc": "Any"
        },
        "severity": {
            "incomplete-signature-doc": "Error",
            "missing-global-doc": "Error",
            "missing-local-export-doc": "Error"
        }
    },
}

But they seem to activate only on inlined functions or functions that have incomplete documentation. So if a function has no docs at all, it gets skipped.

Suggestion

A new diagnostic that maybe can be a warning but can be escalated to an error. And it basically says

  • If it is a global variable table, it needs a ---@type
  • If it is a function
    • And it has at least one parameter
      • Each parameter must define ---@param with a name + type
    • And it has at least one non-bare-return `return
      • Each parameter must define ---@return with type
  • If the type annotation is a table
    • Require that the table is "filled out" with concrete types. e.g. ---@type table -> ---@type table<string, integer>

Something along these lines

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions