Repository: LazyVim/LazyVim
File: tests/extras/extra_spec.lua (Lua)

Code before:

local Plugin = require("lazy.core.plugin")
_G.LazyVim = require("lazyvim.util")

describe("Extra", function()
  local Config = require("lazy.core.config")
  assert(vim.tbl_count(Config.plugins) > 0, "Lazy not properly setup")

  ---@type {modname:string, modpath:string}[]
  local extras = vim.tbl_map(
    ---@param path string
    function(path)
      local modname = path:sub(5):gsub("%.lua$", ""):gsub("/", ".")
      return { modname = modname, modpath = path }
    end,
    vim.fs.find(function(name)
      return name:match("%.lua$")
    end, { limit = math.huge, type = "file", path = "lua/lazyvim/plugins/extras" })
  )

  local ignore = { "lazyvim.plugins.extras.ui.treesitter-rewrite" }
  extras = vim.tbl_filter(function(extra)
    return not vim.tbl_contains(ignore, extra.modname)
  end, extras)

  local lsp_to_pkg = require("mason-lspconfig").get_mappings().lspconfig_to_package

  local tsspec = Plugin.Spec.new({
    import = "lazyvim.plugins.treesitter",
  }, { optional = true })

  local tsopts = Plugin.values(tsspec.plugins["nvim-treesitter"], "opts", false)

  local tsensure = tsopts.ensure_installed
  assert(type(tsensure) == "table", "No ensure_installed in nvim-treesitter spec")

  for _, extra in ipairs(extras) do
    local name = extra.modname:sub(#"lazyvim.plugins.extras" + 2)
    describe(name, function()
      it("spec is valid", function()
        local mod = require(extra.modname)
        assert.is_not_nil(mod)
        local spec = Plugin.Spec.new({
          { "mason-org/mason.nvim", opts = { ensure_installed = {} } },
          { "nvim-treesitter/nvim-treesitter", opts = { ensure_installed = {} } },
          mod,
        }, { optional = true })
        assert(#spec.notifs == 0, "Invalid spec: " .. vim.inspect(spec.notifs))
      end)

      if extra.modname:find("%.lang%.") then

Review comment (suggestion):
```suggestion
  local lsp_to_pkg = {}
  if vim.fn.has("nvim-0.11") == 1 then
    lsp_to_pkg = require("mason-lspconfig.mappings").get_mason_map().lspconfig_to_package
  else
    lsp_to_pkg = require("mason-lspconfig.mappings.server").lspconfig_to_package
  end
```

Code after:

local Plugin = require("lazy.core.plugin")
_G.LazyVim = require("lazyvim.util")

describe("Extra", function()
  local Config = require("lazy.core.config")
  assert(vim.tbl_count(Config.plugins) > 0, "Lazy not properly setup")

  ---@type {modname:string, modpath:string}[]
  local extras = vim.tbl_map(
    ---@param path string
    function(path)
      local modname = path:sub(5):gsub("%.lua$", ""):gsub("/", ".")
      return { modname = modname, modpath = path }
    end,
    vim.fs.find(function(name)
      return name:match("%.lua$")
    end, { limit = math.huge, type = "file", path = "lua/lazyvim/plugins/extras" })
  )

  local ignore = { "lazyvim.plugins.extras.ui.treesitter-rewrite" }
  extras = vim.tbl_filter(function(extra)
    return not vim.tbl_contains(ignore, extra.modname)
  end, extras)

  local lsp_to_pkg = {}
  lsp_to_pkg = require("mason-lspconfig.mappings").get_mason_map().lspconfig_to_package

  local tsspec = Plugin.Spec.new({
    import = "lazyvim.plugins.treesitter",
  }, { optional = true })

  local tsopts = Plugin.values(tsspec.plugins["nvim-treesitter"], "opts", false)

  local tsensure = tsopts.ensure_installed
  assert(type(tsensure) == "table", "No ensure_installed in nvim-treesitter spec")

  for _, extra in ipairs(extras) do
    local name = extra.modname:sub(#"lazyvim.plugins.extras" + 2)
    describe(name, function()
      it("spec is valid", function()
        local mod = require(extra.modname)
        assert.is_not_nil(mod)
        local spec = Plugin.Spec.new({
          { "mason-org/mason.nvim", opts = { ensure_installed = {} } },
          { "nvim-treesitter/nvim-treesitter", opts = { ensure_installed = {} } },
          mod,
        }, { optional = true })
        assert(#spec.notifs == 0, "Invalid spec: " .. vim.inspect(spec.notifs))
      end)