nvimtools / none-ls.nvim

null-ls.nvim reloaded / Use Neovim as a language server to inject LSP diagnostics, code actions, and more via Lua.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

[Bug]: `selene` diagnostics not excluding files from `selene.toml` config

AlejandroSuero opened this issue · comments

FAQ

  • I have checked the FAQ and it didn't resolve my problem.

Issues

  • I have checked existing issues and there are no issues with the same problem.

Neovim Version

NVIM v0.9.5 Build type: RelWithDebInfo LuaJIT 2.1.1692716794

Dev Version?

  • I am using a stable Neovim release version, or if I am using a dev version of Neovim I have confirmed that my issue is reproducible on a stable version.

Operating System

MacOS 14.4.1

Minimal Config

-- this template is borrowed from nvim-lspconfig
local on_windows = vim.loop.os_uname().version:match("Windows")

local function join_paths(...)
  local path_sep = on_windows and "\\" or "/"
  local result = table.concat({ ... }, path_sep)
  return result
end

vim.g.loaded_remote_plugins = ""
vim.cmd([[set runtimepath=$VIMRUNTIME]])

local temp_dir = vim.loop.os_getenv("TEMP") or "/tmp"

vim.cmd("set packpath=" .. join_paths(temp_dir, "nvim", "site"))

local package_root = join_paths(temp_dir, "nvim", "site", "pack")
local install_path = join_paths(package_root, "packer", "start", "packer.nvim")
local compile_path = join_paths(install_path, "plugin", "packer_compiled.lua")

local null_ls_config = function()
  local null_ls = require("null-ls")
  local null_ls_utils = require("null-ls.utils")

  local diagnostics = null_ls.builtins.diagnostics
  -- add only what you need to reproduce your issue
  null_ls.setup({
    root_dir = null_ls_utils.root_pattern("selene.toml"),

    sources = {
      diagnostics.selene.with({
        condition = function(utils)
          return utils.root_has_file({ "selene.toml" })
        end,
      }),
    },
    debug = true,
  })
end

local function load_plugins()
  -- only add other plugins if they are necessary to reproduce the issue
  require("packer").startup({
    {
      "wbthomason/packer.nvim",
      {
        "nvimtools/none-ls.nvim",
        requires = { "nvim-lua/plenary.nvim" },
        config = null_ls_config,
      },
    },
    config = {
      package_root = package_root,
      compile_path = compile_path,
    },
  })
end

if vim.fn.isdirectory(install_path) == 0 then
  vim.fn.system({ "git", "clone", "https://github.com/wbthomason/packer.nvim", install_path })
  load_plugins()
  require("packer").sync()
else
  load_plugins()
  require("packer").sync()
end

Steps to Reproduce

In a testing enviroment (a directory for a lua project), have the following files.

  • Create a selene.toml file with the following config:
std="neovim"

exclude = ["*_spec.lua", ".luacheckrc"]

[rules]
global_usage = "allow"
multiple_statements = "allow"
incorrect_standard_library_use = "allow"
mixed_table = "allow"
unused_variable = "warn"
  • Create a neovim.yml file with the following config:
---
base: lua51

globals:
  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
  • Create a .luacheckrc file with the following config:
-- Rerun tests only if their modification time changed.
cache = true

ignore = {
  "122", -- Setting a read-only field of a global variable.
  "212", -- Unused argument, In the case of callback function, _arg_name is easier to understand than _, so this option is set to off.
  "631", -- max_line_length, vscode pkg URL is too long
}

-- Global objects defined by the C code
read_globals = {
  "vim",
}

include_files = { "lua", "tests" }
exclude_files = { ".luacheckrc", "tests/**/*_spec.lua" }

-- vim: ft=lua tw=80
  • Open NeoVim using nvim --clean -u minimal_init.lua and navigate to :e .luacheckrc

Reproducibility Check

  • I confirm that my minimal config is based on the minimal_init.lua template and that my issue is reproducible by running nvim --clean -u minimal_init.lua and following the steps above.

Expected Behavior

To not display any diagnostics from selene inside excluded files.

Actual Behavior

Displaying diagnostics from selene inside excluded files.

Debug Log

[DEBUG Thu May  9 14:45:59 2024] /tmp/nvim/site/pack/packer/start/none-ls.nvim/lua/null-ls/sources.lua:82: registering conditional source selene
[TRACE Thu May  9 14:45:59 2024] /tmp/nvim/site/pack/packer/start/none-ls.nvim/lua/null-ls/client.lua:114: starting null-ls client
[TRACE Thu May  9 14:45:59 2024] /tmp/nvim/site/pack/packer/start/none-ls.nvim/lua/null-ls/rpc.lua:106: received LSP request for method initialize
[DEBUG Thu May  9 14:45:59 2024] /tmp/nvim/site/pack/packer/start/none-ls.nvim/lua/null-ls/client.lua:182: unable to notify client for method textDocument/didOpen (client not active): {
  textDocument = {
    uri = "file:///Users/aome/dev/nvim_plugins/colorscheme-installer.nvim/.luacheckrc"
  }
}
[TRACE Thu May  9 14:45:59 2024] /tmp/nvim/site/pack/packer/start/none-ls.nvim/lua/null-ls/rpc.lua:131: received LSP notification for method initialized
[TRACE Thu May  9 14:45:59 2024] /tmp/nvim/site/pack/packer/start/none-ls.nvim/lua/null-ls/rpc.lua:131: received LSP notification for method textDocument/didOpen
[TRACE Thu May  9 14:45:59 2024] /tmp/nvim/site/pack/packer/start/none-ls.nvim/lua/null-ls/generators.lua:21: running generators for method NULL_LS_DIAGNOSTICS_ON_OPEN
[DEBUG Thu May  9 14:45:59 2024] /tmp/nvim/site/pack/packer/start/none-ls.nvim/lua/null-ls/helpers/generator_factory.lua:329: spawning command "selene" at /Users/aome/dev/nvim_plugins/colorscheme-installer.nvim with args { "--display-style", "quiet", "-" }
[TRACE Thu May  9 14:45:59 2024] /tmp/nvim/site/pack/packer/start/none-ls.nvim/lua/null-ls/helpers/generator_factory.lua:207: error output: nil
[TRACE Thu May  9 14:45:59 2024] /tmp/nvim/site/pack/packer/start/none-ls.nvim/lua/null-ls/helpers/generator_factory.lua:208: output: -:2:1: warning[unscoped_variables]: `cache` is not declared locally, and will be available in every scope
-:2:1: warning[unused_variable]: cache is defined, but never used
-:4:1: warning[unscoped_variables]: `ignore` is not declared locally, and will be available in every scope
-:4:1: warning[unused_variable]: ignore is defined, but never used
-:11:1: warning[unscoped_variables]: `read_globals` is not declared locally, and will be available in every scope
-:11:1: warning[unused_variable]: read_globals is defined, but never used
-:15:1: warning[unscoped_variables]: `include_files` is not declared locally, and will be available in every scope
-:15:1: warning[unused_variable]: include_files is defined, but never used
-:16:1: warning[unscoped_variables]: `exclude_files` is not declared locally, and will be available in every scope
-:16:1: warning[unused_variable]: exclude_files is defined, but never used
Results:
0 errors
10 warnings
0 parse errors

[TRACE Thu May  9 14:45:59 2024] /tmp/nvim/site/pack/packer/start/none-ls.nvim/lua/null-ls/diagnostics.lua:181: received diagnostics from source 1
[TRACE Thu May  9 14:45:59 2024] /tmp/nvim/site/pack/packer/start/none-ls.nvim/lua/null-ls/diagnostics.lua:182: { {
    code = "unscoped_variables",
    col = 0,
    end_col = 5,
    end_lnum = 1,
    lnum = 1,
    message = "`cache` is not declared locally, and will be available in every scope",
    row = "2",
    severity = 2,
    source = "selene"
  }, {
    code = "unused_variable",
    col = 0,
    end_col = 5,
    end_lnum = 1,
    lnum = 1,
    message = "cache is defined, but never used",
    row = "2",
    severity = 2,
    source = "selene"
  }, {
    code = "unscoped_variables",
    col = 0,
    end_col = 6,
    end_lnum = 3,
    lnum = 3,
    message = "`ignore` is not declared locally, and will be available in every scope",
    row = "4",
    severity = 2,
    source = "selene"
  }, {
    code = "unused_variable",
    col = 0,
    end_col = 6,
    end_lnum = 3,
    lnum = 3,
    message = "ignore is defined, but never used",
    row = "4",
    severity = 2,
    source = "selene"
  }, {
    code = "unscoped_variables",
    col = 0,
    end_col = 12,
    end_lnum = 10,
    lnum = 10,
    message = "`read_globals` is not declared locally, and will be available in every scope",
    row = "11",
    severity = 2,
    source = "selene"
  }, {
    code = "unused_variable",
    col = 0,
    end_col = 12,
    end_lnum = 10,
    lnum = 10,
    message = "read_globals is defined, but never used",
    row = "11",
    severity = 2,
    source = "selene"
  }, {
    code = "unscoped_variables",
    col = 0,
    end_col = 13,
    end_lnum = 14,
    lnum = 14,
    message = "`include_files` is not declared locally, and will be available in every scope",
    row = "15",
    severity = 2,
    source = "selene"
  }, {
    code = "unused_variable",
    col = 0,
    end_col = 13,
    end_lnum = 14,
    lnum = 14,
    message = "include_files is defined, but never used",
    row = "15",
    severity = 2,
    source = "selene"
  }, {
    code = "unscoped_variables",
    col = 0,
    end_col = 13,
    end_lnum = 15,
    lnum = 15,
    message = "`exclude_files` is not declared locally, and will be available in every scope",
    row = "16",
    severity = 2,
    source = "selene"
  }, {
    code = "unused_variable",
    col = 0,
    end_col = 13,
    end_lnum = 15,
    lnum = 15,
    message = "exclude_files is defined, but never used",
    row = "16",
    severity = 2,
    source = "selene"
  } }

Help

No

Implementation Help

No response

Requirements

  • I have read and followed the instructions above and understand that my issue will be closed if I did not provide the required information.

@AlejandroSuero This issue has nothing to do with none-ls. You are not using selene exclude correctly (refer to the docs). Also Mixing two linters is by general rule a bad idea.

@Zeioth according to the documentation, in the excluding files section this is how it is supposed to work.

I'm not planning on mixing them (in the minimal I only use one), I am trying to support selene linting for people that don't use luacheck inside a project but want to have the linting diagnostics and have selene already installed, thats all.

Project tree:

 .git/
 .github/
 .gitignore
 .luacheckrc
 .luarc.json
 .markdownlint.json
 .yamllint.yml
 colorscheme-installer-scm-1.rockspec
 contrib/
 doc/
 LICENSE
 lua/
 luacov.stats.out
 Makefile
 neovim.yml
 README.md
 scripts/
 selene.toml
 stylua.toml
 tests/

  • selene . and selene .luacheckrc excluding the files from command-line:
selene command
  • selene --no-exclude .luacheckrc not excluding the files from command-line:
selene command --no-exclude
  • Diagnostics using none-ls not excluding the files:
Diagnostics own config

With my own config

Diagnostics minimal

With the minimal config