Skip to content

Commit

Permalink
feat(ts-standard): Add ts-standard linter
Browse files Browse the repository at this point in the history
  • Loading branch information
AbelAnaya committed Dec 4, 2024
1 parent 6b46370 commit 8d01d42
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 42 deletions.
73 changes: 31 additions & 42 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ results.

## Installation

- Requires Neovim >= 0.9.5
- `nvim-lint` is a regular plugin and can be installed via the `:h packages`
mechanism or via a plugin manager.
- Requires Neovim >= 0.9.5
- `nvim-lint` is a regular plugin and can be installed via the `:h packages`
mechanism or via a plugin manager.

For example:

Expand All @@ -30,9 +30,8 @@ git clone \
~/.config/nvim/pack/plugins/start/nvim-lint
```

- If using [vim-plug][3]: `Plug 'mfussenegger/nvim-lint'`
- If using [packer.nvim][4]: `use 'mfussenegger/nvim-lint'`

- If using [vim-plug][3]: `Plug 'mfussenegger/nvim-lint'`
- If using [packer.nvim][4]: `use 'mfussenegger/nvim-lint'`

## Usage

Expand Down Expand Up @@ -71,11 +70,9 @@ Some linters require a file to be saved to disk, others support linting `stdin`
input. For such linters you could also define a more aggressive autocmd, for
example on the `InsertLeave` or `TextChanged` events.


If you want to customize how the diagnostics are displayed, read `:help
vim.diagnostic.config`.


## Available Linters

There is a generic linter called `compiler` that uses the `makeprg` and
Expand Down Expand Up @@ -203,6 +200,7 @@ Other dedicated linters that are built-in are:
| [sphinx-lint][sphinx-lint] | `sphinx-lint` |
| [sqlfluff][sqlfluff] | `sqlfluff` |
| [standardjs][standardjs] | `standardjs` |
| [ts-standard][ts-standard] | `ts-standard` |
| [StandardRB][27] | `standardrb` |
| [statix check][33] | `statix` |
| [stylelint][29] | `stylelint` |
Expand Down Expand Up @@ -232,7 +230,6 @@ Other dedicated linters that are built-in are:
You can register custom linters by adding them to the `linters` table, but
please consider contributing a linter if it is missing.


```lua
require('lint').linters.your_linter_name = {
cmd = 'linter_cmd',
Expand All @@ -252,10 +249,9 @@ generate some of the properties.

`your_parse_function` can be a function which takes three arguments:

- `output`
- `bufnr`
- `linter_cwd`

- `output`
- `bufnr`
- `linter_cwd`

The `output` is the output generated by the linter command.
The function must return a list of diagnostics as specified in `:help
Expand Down Expand Up @@ -283,7 +279,6 @@ parser = require('lint.parser').from_errorformat(errorformat)

The function takes two arguments: `errorformat` and `skeleton` (optional).


### from_pattern

Creates a parser function from a pattern.
Expand All @@ -296,26 +291,25 @@ parser = require('lint.parser').from_pattern(pattern, groups, severity_map, defa

The function allows to parse the linter's output using a pattern which can be either:

- A Lua pattern. See `:help lua-patterns`.
- A LPEG pattern object. See `:help vim.lpeg`.
- A function (`fun(line: string):string[]`). It takes one parameter - a line
from the linter output and must return a string array with the matches. The
array should be empty if there was no match.

- A Lua pattern. See `:help lua-patterns`.
- A LPEG pattern object. See `:help vim.lpeg`.
- A function (`fun(line: string):string[]`). It takes one parameter - a line
from the linter output and must return a string array with the matches. The
array should be empty if there was no match.

### groups

The groups specify the result format of the pattern.
Available groups:

- `lnum`
- `end_lnum`
- `col`
- `end_col`
- `message`
- `file`
- `severity`
- `code`
- `lnum`
- `end_lnum`
- `col`
- `end_col`
- `message`
- `file`
- `severity`
- `code`

The order of the groups must match the order of the captures within the pattern.
An example:
Expand All @@ -331,7 +325,7 @@ The captures in the pattern correspond to the group at the same position.

A mapping from severity codes to diagnostic codes

``` lua
```lua
default_severity = {
['error'] = vim.diagnostic.severity.ERROR,
['warning'] = vim.diagnostic.severity.WARN,
Expand All @@ -352,11 +346,10 @@ defaults = {["source"] = "mylint-name"}

Additional options

- `lnum_offset`: Added to `lnum`. Defaults to 0
- `end_lnum_offset`: Added to `end_lnum`. Defaults to 0
- `end_col_offset`: offset added to `end_col`. Defaults to `-1`, assuming
that the end-column position is exclusive.

- `lnum_offset`: Added to `lnum`. Defaults to 0
- `end_lnum_offset`: Added to `end_lnum`. Defaults to 0
- `end_col_offset`: offset added to `end_col`. Defaults to `-1`, assuming
that the end-column position is exclusive.

## Customize built-in linters

Expand All @@ -383,7 +376,6 @@ lint.linters.cspell = require("lint.util").wrap(lint.linters.cspell, function(di
end)
```


## Display configuration

See `:help vim.diagnostic.config`.
Expand All @@ -396,7 +388,6 @@ local ns = require("lint").get_namespace("my_linter_name")
vim.diagnostic.config({ virtual_text = true }, ns)
```


## Get the current running linters for your buffer

You can see which linters are running with `require("lint").get_running()`.
Expand All @@ -412,17 +403,14 @@ local lint_progress = function()
end
```


## Alternatives

- [Ale][1]
- [efm-langserver][6]
- [diagnostic-languageserver][7]

- [Ale][1]
- [efm-langserver][6]
- [diagnostic-languageserver][7]

## Development ☢️


### Run tests

Running tests requires [busted][busted].
Expand Down Expand Up @@ -541,6 +529,7 @@ busted tests/
[ec]: https://github.com/editorconfig-checker/editorconfig-checker
[deno]: https://github.com/denoland/deno
[standardjs]: https://standardjs.com/
[ts-standard]: https://github.com/standard/ts-standard
[biomejs]: https://github.com/biomejs/biome
[commitlint]: https://commitlint.js.org
[alex]: https://alexjs.com/
Expand Down
18 changes: 18 additions & 0 deletions lua/lint/linters/ts-standard.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
local binary_name = "ts-standard"
local pattern = "[^:]+:(%d+):(%d+):([^%.]+%.?)%s%(([%a-]+)%)%s?%(?(%a*)%)?"
local groups = { "lnum", "col", "message", "code", "severity" }
local severities = {
[""] = vim.diagnostic.severity.ERROR,
["warning"] = vim.diagnostic.severity.WARN,
}

return {
cmd = function()
local local_binary = vim.fn.fnamemodify("./node_modules/.bin/" .. binary_name, ":p")
return vim.loop.fs_stat(local_binary) and local_binary or binary_name
end,
stdin = true,
args = { "--stdin" },
ignore_exitcode = true,
parser = require("lint.parser").from_pattern(pattern, groups, severities, { ["source"] = "ts-standard" }, {}),
}

0 comments on commit 8d01d42

Please sign in to comment.