[Feat] `selene` linter support
评估
调研方向
Start by reviewing the Makefile, existing workflow files, and lua/plenary/busted.lua, then run the provided selene command against lua/plenary. Add the requested lint target and CI job, and confirm the command exits successfully with the documented warnings allowed.
由索引模型根据 Issue 内容生成。
描述
Motivation
I have been using selene in my projects lately and I think is a more strict linter in some cases, showing more errors or warnings to catch what luacheck do not.
Example config
In the root project.
selene.toml
std="neovim"
exclude = [
"lua/plenary/profile/lua_profiler.lua",
"lua/plenary/profile/memory_profiler.lua",
"lua/plenary/profile/p.lua", # token `goto` detected as `parse_error`
"lua/plenary/async_lib/*.lua",
]
[rules]
global_usage = "warn"
deprecated = "warn" # If change for `allow` it will rely in `lua_ls` diagnostics alone
multiple_statements = "warn"
incorrect_standard_library_use = "allow" # This is for cases like `string.format`, `package.config`, etc.
mixed_table = "allow"
unused_variable = "warn"
undefined_variable = "warn"
neovim.yml
---
base: lua51
globals:
_:
any: true
a:
any: true
jit:
any: true
bit:
any: true
vim:
any: true
assert:
args:
- type: bool
- type: string
required: false
after_each:
args:
- type: function
before_each:
args:
- type: function
describe:
args:
- type: string
- type: function
it:
args:
- type: string
- type: function
With these two files in the root of the project, selene --display-style quiet lua/plenary --allow-warnings results in the following.
lua/plenary/async/api.lua:4:22: warning[unused_variable]: t is defined, but never used
lua/plenary/bit.lua:136:21: warning[multiple_statements]: only one statement per line is allowed
lua/plenary/bit.lua:176:22: warning[multiple_statements]: only one statement per line is allowed
lua/plenary/bit.lua:179:22: warning[multiple_statements]: only one statement per line is allowed
lua/plenary/bit.lua:182:22: warning[multiple_statements]: only one statement per line is allowed
lua/plenary/bit.lua:226:28: warning[multiple_statements]: only one statement per line is allowed
lua/plenary/bit.lua:227:28: warning[multiple_statements]: only one statement per line is allowed
lua/plenary/bit.lua:228:28: warning[multiple_statements]: only one statement per line is allowed
lua/plenary/bit.lua:252:27: warning[multiple_statements]: only one statement per line is allowed
lua/plenary/bit.lua:269:27: warning[multiple_statements]: only one statement per line is allowed
lua/plenary/async/tests.lua:14:3: warning[undefined_variable]: `pending` is not defined
lua/plenary/busted.lua:5:26: warning[unused_variable]: element is defined, but never used
lua/plenary/busted.lua:13:19: error[mismatched_arg_count]: this function takes 1 argument but 2 arguments were supplied
lua/plenary/busted.lua:74:41: warning[shadowing]: shadowing variable `msg`
lua/plenary/busted.lua:201:30: warning[unused_variable]: func is defined, but never used
lua/plenary/busted.lua:211:1: warning[unscoped_variables]: `pending` is not declared locally, and will be available in every scope
lua/plenary/busted.lua:211:1: warning[unused_variable]: pending is defined, but never used
lua/plenary/busted.lua:214:1: warning[unscoped_variables]: `clear` is not declared locally, and will be available in every scope
lua/plenary/busted.lua:214:1: warning[unused_variable]: clear is defined, but never used
lua/plenary/profile.lua:16:24: warning[multiple_statements]: only one statement per line is allowed
lua/plenary/run.lua:5:55: warning[unused_variable]: opts is defined, but never used
Results:
1 errors
20 warnings
0 parse errors
[!note]
The error shown is because inlua/plenary/busted.luawe are using the functiondirnamewith 1 argument.But in the line
13,dirname(debug.getinfo(1, "Sl").source, ":h")is using 2. Unlike in line18,dirname(info.source)is just using one as the declaration forlocal dirname = function(p)indicates.
If we fix that error, dirname(debug.getinfo(1, "Sl").source, ":h") -> dirname(debug.getinfo(1, "Sl").source). The command for selene with the --allow-warnings flag will result in a success exit code when linting.
Integrations
For the CI process it will be easy.
- Extending the
Makefileto include:make lint-selene:selene --display-style quiet lua/plenary --allow-warnings
- Adding a
selenejob toworkflows:
selene:
name: Selene
runs-on: ubuntu-22.04
steps:
- name: Checkout sources
uses: actions/checkout@v2
- name: Run selene
uses: NTBBloodbath/[email protected]
with:
token: ${{ secrets.GITHUB_TOKEN }}
args: --display-style quiet lua/plenary --allow-warnings
[!note]
More aboutseleneaction here
- 主要语言
- Lua
- 星标
- 3.5k
- 派生
- 340
- PR 合并指标
- 30 天内没有已合并 PR
环境准备
这个项目没有提供开发容器、Dockerfile 或贡献指南,环境需要你自己搭建:先看它的 README,通用步骤见我们的新手贡献指南。
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
nvim-lua/plenary.nvim 的其他 Issue
-
难度 1/5 1 小时以内 新手友好度 88/100
nvim-lua/plenary.nvim#682 ·
-
uniform usage of `os.getenv`可能已有人在做 @rakotomandimby 于 126 天前认领。 未关闭
难度 1/5 1 小时以内 新手友好度 72/100
nvim-lua/plenary.nvim#680 ·
-
难度 2/5 1-3 小时 新手友好度 45/100
nvim-lua/plenary.nvim#675 ·
-
难度 4/5 3-5 天 新手友好度 28/100
nvim-lua/plenary.nvim#672 · 1 条评论 ·
-
难度 4/5 3-5 天 新手友好度 25/100
nvim-lua/plenary.nvim#671 · 1 条评论 ·
查看 nvim-lua/plenary.nvim 的全部 Issue
相似的 Issue
-
bug good first issue
难度 2/5 1-3 小时 新手友好度 82/100
eugenioenko/ttt#919 · 1 条评论 ·
维护者通常 1 天内回复
-
Profiler (Remotery) leaks a socket for every connection that fails the WebSocket handshake可能已有人在做 @rthery 今天认领。 未关闭triage
难度 2/5 1-3 小时 新手友好度 72/100
维护者通常 1 天内回复
-
Mosquito: LOOP_ANT_LOCK reads the IFF detonator cover可能已有人在做 @cbass2404 今天认领。 未关闭Mosquito
难度 1/5 1 小时以内 新手友好度 88/100
DCS-Skunkworks/dcs-bios#1925 ·
维护者通常 1 天内回复
-
难度 2/5 1 小时以内 新手友好度 80/100
mason-org/mason.nvim#2117 ·
-
难度 2/5 1-3 小时 新手友好度 72/100
mailcow/mailcow-dockerized#7518 ·
维护者通常 1 天内回复