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

bug: stylua doesn't respect .styluaignore file by default after v2.0.0 #615

Closed
2 tasks done
polirritmico opened this issue Dec 31, 2024 · 0 comments · Fixed by #616
Closed
2 tasks done

bug: stylua doesn't respect .styluaignore file by default after v2.0.0 #615

polirritmico opened this issue Dec 31, 2024 · 0 comments · Fixed by #616
Labels
bug Something isn't working

Comments

@polirritmico
Copy link
Contributor

polirritmico commented Dec 31, 2024

Neovim version (nvim -v)

NVIM v0.10.3 Build type: Release LuaJIT 2.1.1716656478

Operating system/version

Gentoo Linux 2.17

Read debugging tips

Add the debug logs

  • I have set log_level = vim.log.levels.DEBUG and pasted the log contents below.

Log file


Describe the bug

Since v2.0.0 StyLua adds the --respect-ignores flag (PR) and changes the default behaviour of --stdin-filepath:

Now, as we approach v2, we make the breaking change to make --stdin-filepath not respect ignores by default. Pass --respect-ignores to preserve original behaviour.

As result, conform is applying formatting to files in the .styluaignore file.

What is the severity of this bug?

breaking (some functionality is broken)

Steps To Reproduce

  1. In a new dir write the repro.lua
  2. Run nvim -u repro.lua
  3. Use :SetCase
  4. :w to write the .styluaignore file into the cwd
  5. <C-w>j and :w to write the foo.lua file.
  6. foo.lua is being formatted.

Expected Behavior

Since foo.lua is in the .styluaignore file, it shouldn't be formatted.

Minimal example file

Check the minimal init.lua SetCase command.

Minimal init.lua

vim.env.LAZY_STDPATH = ".repro"
load(vim.fn.system("curl -s https://raw.githubusercontent.com/folke/lazy.nvim/main/bootstrap.lua"))()

require("lazy.minit").repro({
  spec = {
    "stevearc/conform.nvim",
    dependencies = {
      {
        "williamboman/mason.nvim",
        build = { ":MasonUpdate" },
        config = function(_, opts)
          require("mason").setup(opts)
          local mr = require("mason-registry")
          if not mr.is_installed("stylua") then
            local p = mr.get_package("stylua")
            p:install()
          end
        end,
      },
    },
    opts = {
      formatters_by_ft = { lua = { "stylua" } },
      format_on_save = { timeout_ms = 500, lsp_fallback = true },
      -- FIX: Uncomment to fix the issue
      -- formatters = { stylua = { prepend_args = { "--respect-ignores" } } },
    },
  },
})

vim.api.nvim_create_user_command("SetCase", function()
  vim.cmd("edit foo.lua")
  vim.api.nvim_buf_set_lines(0, 0, -1, false, { 'return { foo = function() return { foo = 123, bar = "buz", } end }' })

  vim.cmd("split .styluaignore")
  vim.api.nvim_buf_set_lines(0, 0, -1, false, { "foo.lua" })
  vim.notify("Done. Save `.styluaignore` and then `foo.lua`. `foo.lua` will be formatted")
end, {})

vim.notify("Use `:SetCase` to fill the case content")

Additional context

To preserve the previous behaviour, --respect-ignores should be added in the args of the lua/conform/formatters/stylua.lua module.

Edit: Check the PR #616

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant