Skip to content

fix: generic linter#134

Merged
xiaoshihou514 merged 1 commit intonvimdev:mainfrom
xiaoshihou514:main
Jan 12, 2024
Merged

fix: generic linter#134
xiaoshihou514 merged 1 commit intonvimdev:mainfrom
xiaoshihou514:main

Conversation

@xiaoshihou514
Copy link
Copy Markdown
Member

@xiaoshihou514 xiaoshihou514 commented Jan 12, 2024

closes #132

@xiaoshihou514 xiaoshihou514 merged commit 192fd1d into nvimdev:main Jan 12, 2024
@UnderCooled
Copy link
Copy Markdown

This fix miss these conditions:

-- you need to check ft_handler(...).linter
ft('foo'):fmt(...)
ft('*'):lint(...)

-- merge two linter list
ft('foo'):lint(...)
ft('*'):lint(...)

@UnderCooled
Copy link
Copy Markdown

I'm not really sure whether this fix is elegant.

  local buf_config = ft_handler[vim.bo[buf].filetype]
  local generic_config = ft_handler['*']
  if not (buf_config or generic_config) then
    return
  end
  local linters = buf_config.linter or {}
  if generic_config.linter then
    vim.list_extend(linters, generic_config.linter)
  end

@xiaoshihou514
Copy link
Copy Markdown
Member Author

I'm not really sure whether this fix is elegant.

  local buf_config = ft_handler[vim.bo[buf].filetype]
  local generic_config = ft_handler['*']
  if not (buf_config or generic_config) then
    return
  end
  local linters = buf_config.linter or {}
  if generic_config.linter then
    vim.list_extend(linters, generic_config.linter)
  end

If it doesn't modify the original table then it seems fine.

@UnderCooled
Copy link
Copy Markdown

if not (buf_config or generic_config) is wrong, may cause buf_config.linter index on nil.

This is an uglier solution 🤣

  local buf_config = ft_handler[vim.bo[buf].filetype]
  local generic_config = ft_handler['*']
  local linters = {}
  if buf_config and buf_config.linter then
    vim.list_extend(linters, buf_config.linter)
  end
  if generic_config and generic_config.linter then
    vim.list_extend(linters, generic_config.linter)
  end
  if #linters == 0 then
    return
  end

@xiaoshihou514
Copy link
Copy Markdown
Member Author

Hmm, actually we should have a pre-condition that buf_config.linter is not nil or this autocmd wouldn't have been registered in the first place. But it is possible the configuration tables are modified during runtime, anyway, this deserves a refactor.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Guard.nvim should support lint on FileType *

2 participants