diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml new file mode 100644 index 0000000..cc1bf41 --- /dev/null +++ b/.github/workflows/lint.yml @@ -0,0 +1,31 @@ +name: linting + +on: [push, pull_request] + +jobs: + luacheck: + name: Luacheck + runs-on: ubuntu-22.04 + steps: + - uses: actions/checkout@v3 + + - name: Prepare + run: | + sudo apt-get update + sudo apt-get install -y luarocks + sudo luarocks install luacheck + + - name: Lint + run: sudo luacheck lua + + stylua: + name: stylua + runs-on: ubuntu-22.04 + steps: + - uses: actions/checkout@v3 + - uses: JohnnyMorganz/stylua-action@v3 + with: + token: ${{ secrets.GITHUB_TOKEN }} + version: latest + # CLI arguments + args: --color always --check lua/ diff --git a/.luacheckrc b/.luacheckrc new file mode 100644 index 0000000..a6be5c0 --- /dev/null +++ b/.luacheckrc @@ -0,0 +1,23 @@ +-- Rerun tests only if their modification time changed. +cache = true + +std = luajit +codes = true + +self = false + +-- Glorious list of warnings: https://luacheck.readthedocs.io/en/stable/warnings.html +ignore = { + "212", -- Unused argument, In the case of callback function, _arg_name is easier to understand than _, so this option is set to off. + "122", -- Indirectly setting a readonly global +} + +globals = { + "_", + "__TelescopeUISelectSpecificOpts", +} + +-- Global objects defined by the C code +read_globals = { + "vim", +} diff --git a/lua/telescope/_extensions/ui-select.lua b/lua/telescope/_extensions/ui-select.lua index d43a279..50e66fd 100644 --- a/lua/telescope/_extensions/ui-select.lua +++ b/lua/telescope/_extensions/ui-select.lua @@ -114,32 +114,34 @@ return require("telescope").register_extension { local make_ordinal = vim.F.if_nil(sopts.make_ordinal, function(e) return opts.format_item(e.text) end) - pickers.new(topts, { - prompt_title = string.gsub(prompt, "\n", " "), - finder = finders.new_table { - results = indexed_items, - entry_maker = function(e) - return { - value = e, - display = make_display, - ordinal = make_ordinal(e), - } + pickers + .new(topts, { + prompt_title = string.gsub(prompt, "\n", " "), + finder = finders.new_table { + results = indexed_items, + entry_maker = function(e) + return { + value = e, + display = make_display, + ordinal = make_ordinal(e), + } + end, + }, + attach_mappings = function(prompt_bufnr) + actions.select_default:replace(function() + local selection = action_state.get_selected_entry() + if selection == nil then + utils.__warn_no_selection "ui-select" + return + end + actions.close(prompt_bufnr) + on_choice(selection.value.text, selection.value.idx) + end) + return true end, - }, - attach_mappings = function(prompt_bufnr) - actions.select_default:replace(function() - local selection = action_state.get_selected_entry() - if selection == nil then - utils.__warn_no_selection "ui-select" - return - end - actions.close(prompt_bufnr) - on_choice(selection.value.text, selection.value.idx) - end) - return true - end, - sorter = conf.generic_sorter(topts), - }):find() + sorter = conf.generic_sorter(topts), + }) + :find() end end, }