Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: generic linter #134

Merged
merged 1 commit into from
Jan 12, 2024
Merged

fix: generic linter #134

merged 1 commit into from
Jan 12, 2024

Conversation

xiaoshihou514
Copy link
Collaborator

@xiaoshihou514 xiaoshihou514 commented Jan 12, 2024

closes #132

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

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

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
Collaborator 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

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
Collaborator 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