Hacktoberfest 2026: những issue maintainer đã đánh dấu cho tháng Mười, đang mở và phù hợp người mới. Xem issue Hacktoberfest

[Feat] `selene` linter support

Đang mở
#579 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

@AlejandroSuero đang làm issue này rồi.

Từ ngày 9/5/2024.

  • #580 của @AlejandroSuero — đang mở

Đánh giá

Độ khó
3/5
Thời gian dự kiến
1-2 ngày
Mức phù hợp với người mới
45/100
Loại issue
Tính năng
Độ rõ ràng
Khá rõ ràng
Mức độ hoạt động
Đình trệ
Công nghệ
lua
Lĩnh vực
ci-cd, tooling

Hướng nghiên cứu

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.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

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

https://github.com/nvim-lua/plenary.nvim/blob/08e301982b9a057110ede7a735dd1b5285eb341f/lua/plenary/busted.lua#L1-L18

[!note]
The error shown is because in lua/plenary/busted.lua we are using the function dirname with 1 argument.

But in the line 13, dirname(debug.getinfo(1, "Sl").source, ":h") is using 2. Unlike in line 18, dirname(info.source) is just using one as the declaration for local 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 Makefile to include:
    • make lint-selene: selene --display-style quiet lua/plenary --allow-warnings
  • Adding a selene job to workflows:
  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 about selene action here

Ngôn ngữ chính
Lua
Star
3.5k
Fork
341
Chỉ số merge pull request
Không có pull request nào được merge trong 30 ngày

Chuẩn bị môi trường

Dự án này không cung cấp dev container, Dockerfile hay hướng dẫn đóng góp, nên bạn cần tự thiết lập môi trường: hãy bắt đầu từ README và xem hướng dẫn đóng góp lần đầu của chúng tôi để biết các bước chung.

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của nvim-lua/plenary.nvim

Tất cả issue của nvim-lua/plenary.nvim

Issue tương tự

Thêm issue về Lua

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.