conform.nvim icon indicating copy to clipboard operation
conform.nvim copied to clipboard

bug: files listed in .gitignore are not formatted

Open Mccranky83 opened this issue 1 year ago • 3 comments

Neovim version (nvim -v)

0.10.1

Operating system/version

MacOS 14.5

Add the debug logs

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

Log file

Log file: /Users/Mccranky/.local/state/nvim/conform.log [error] 70 | await menuPageModel.expandGradeScope();

      17:22:52[ERROR] Formatter 'prettier' error: [error] /Users/Mccranky/GitHub/Projects/JavaScript/aistudy-docs-crawler/app/pom/MenuPageModel.js: SyntaxError: Unexpected token (260:9)
      [error]   258 |     await gradesIterator(sidebarIndex + 1);
      [error]   259 |   };
      [error] > 260 |   await gradesIterator();
      [error]       |         ^
      [error]   261 |
      [error]   262 |   await fs
      [error]   263 |     .writeFile("./sitemap.json", JSON.stringify(sitemap, null, 2), {
      
      22:04:36[ERROR] Formatter 'prettier' error: [error] /Users/Mccranky/GitHub/Projects/JavaScript/aistudy-docs-crawler/app/pom/MenuPageModel.js: SyntaxError: Unexpected token (178:22)
      [error]   176 |
      [error]   177 |     const semesters = ["上", "下"];
      [error] > 178 |     for (let semester)
      [error]       |                      ^
      [error]   179 |     await this.page.waitForNetworkIdle({ idleTime: 300 });
      [error]   180 |     await this.reselectCourses();
      [error]   181 |

Formatters for this buffer: LSP: tsserver prettier ready (jsonc, graphql, html, css, vue, svelte, javascript, javascriptreact, typescript, json, yaml, typescriptreact, liquid, markdown) /Users/Mccranky/.local/share/nvim/mason/bin/prettier

Other formatters: black ready (python) /Users/Mccranky/.local/share/nvim/mason/bin/black google-java-format ready (java) /Users/Mccranky/.local/share/nvim/mason/bin/google-java-format isort ready (python) /Users/Mccranky/.local/share/nvim/mason/bin/isort shfmt ready (bash, sh) /Users/Mccranky/.local/share/nvim/mason/bin/shfmt stylua ready (lua) /Users/Mccranky/.local/share/nvim/mason/bin/stylua

Describe the bug

Filenames that match the patterns listed in .gitignore are not formatted.

What is the severity of this bug?

tolerable (can work around it)

Steps To Reproduce

  1. :w in neovim after writing some unformatted code
  2. code remains unformatted

Expected Behavior

code should be formatted

Minimal example file

No response

Minimal init.lua

-- DO NOT change the paths and don't remove the colorscheme
local root = vim.fn.fnamemodify("./.repro", ":p")

-- set stdpaths to use .repro
for _, name in ipairs({ "config", "data", "state", "cache" }) do
  vim.env[("XDG_%s_HOME"):format(name:upper())] = root .. "/" .. name
end

-- bootstrap lazy
local lazypath = root .. "/plugins/lazy.nvim"
if not vim.loop.fs_stat(lazypath) then
  vim.fn.system({
    "git",
    "clone",
    "--filter=blob:none",
    "--single-branch",
    "https://github.com/folke/lazy.nvim.git",
    lazypath,
  })
end
vim.opt.runtimepath:prepend(lazypath)

-- install plugins
local plugins = {
  "folke/tokyonight.nvim",
  {
    "stevearc/conform.nvim",
    config = function()
      require("conform").setup({
        log_level = vim.log.levels.DEBUG,
        -- add your config here
      })
    end,
  },
  -- add any other plugins here
}
require("lazy").setup(plugins, {
  root = root .. "/plugins",
})

vim.cmd.colorscheme("tokyonight")
-- add anything else here

Additional context

No response

Mccranky83 avatar Jul 25 '24 15:07 Mccranky83

Same problem

lisuke avatar Feb 27 '25 18:02 lisuke

The only logs I see indicate a syntax error, which will prevent formatting from working. If that is not the cause of the error, please follow the debugging steps to produce

  1. the command that conform is running on your files
  2. a command that correctly formats your files when run from the terminal

stevearc avatar Mar 05 '25 17:03 stevearc

Same problem here. I don't see any errors in my logs, and this is my config:

return {
	"stevearc/conform.nvim",
	config = function()
		require("conform").setup({
			formatters_by_ft = {
				lua = { "stylua" },
				python = { "autoflake", "isort", "darker" },
				terraform = { "terraform_fmt" },
				javascript = { "prettier" },
			},
			formatters = {
				autoflake = {
					prepend_args = { "--in-place", "--remove-unused-variables" },
				},
				isort = {
					prepend_args = { "--profile", "black" },
				},
			},
			format_on_save = {
				timeout_ms = 1000,
				lsp_format = "fallback",
			},
		})
	end,
}

luis-duque-azumo avatar May 27 '25 16:05 luis-duque-azumo

Same problem with lazyvim, is there any fix ?

hieubnt235 avatar Dec 05 '25 07:12 hieubnt235