bug: prettier error being written to buffer

Open
#548 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
35/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Stale
Tech stack
lua, neovim
Domain
tooling

Research direction

Reproduce the issue in Neovim using the provided Prettier configuration, an SCSS buffer, and a missing bracket. Start by tracing how the formatter handles stderr and the configured exit_codes; done means an exit code of 2 leaves the buffer unchanged. The payload names no repository file or test path.

Written by the indexing model from the issue text.

Description

bug
Neovim version (nvim -v)

0.10.2

Operating system/version

macos 15

Read debugging tips
Add the debug logs
  • I have set log_level = vim.log.levels.DEBUG and pasted the log contents below.
Log file

... filepath
[error] 1 |
[error] > 2 | <input css 1>
[error] | ^
[error] 3 | 13:5 ✖ Unknown word CssSyntaxError
[error] 4 |
[error] 5 | 1 problem (1 error, 0 warnings)

Describe the bug

When theres a syntax error, the error gets written to the buffer despite the exit code being 2 and me specifying 0,1.

What is the severity of this bug?

breaking (some functionality is broken)

Steps To Reproduce

open this as scss

nav {
ul {
margin: 0;
padding: 0;
list-style: none;
}

li { display: inline-block; }

a {
display: block;
padding: 6px 12px;
text-decoration: none;
}
}

then delete a bracket. Then try to format, the error gets written into the buffer

Expected Behavior

It should not modify the buffer because the exit code was 2.

Minimal example file
      prettier = {
        command = format_utils.from_node_modules("prettier"),
        args = function(self, ctx)
          local args = { "--stdin-filepath", "$FILENAME" }

          -- Get the current buffer's shiftwidth
          local shiftwidth = vim.bo.shiftwidth

          -- Determine if tabs or spaces are being used
          local use_tabs = vim.bo.expandtab == false

          -- Add indentation options
          table.insert(args, "--use-tabs")
          table.insert(args, tostring(use_tabs))
          table.insert(args, "--tab-width")
          table.insert(args, tostring(shiftwidth))

          -- Add config path if specified
          local config_path = format_utils.find_config_file("prettier", prettier_config_patterns, ctx)
          if config_path then
            table.insert(args, "--config")
            table.insert(args, config_path)
          end

          return args
        end,
        stdin = true,
        exit_codes = { 0, 1 },
        cwd = function()
          return file_utils.find_closest_node_modules_to_current_file()
        end,
        condition = function(_, ctx)
          return format_utils.formatter_condition("prettier", prettier_config_patterns, ctx)
        end,
      },
Minimal init.lua

No response

Additional context

No response

Dominant language
Lua
Stars
5.3k
Forks
311
PR merge metrics
No merged PRs in 30d

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from stevearc/conform.nvim

All issues in stevearc/conform.nvim

Similar issues

More Lua issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.