Skip to content

bug: Dart format ignoring analysis_options.yaml #712

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

Open
2 tasks done
papitz opened this issue May 23, 2025 · 1 comment
Open
2 tasks done

bug: Dart format ignoring analysis_options.yaml #712

papitz opened this issue May 23, 2025 · 1 comment
Labels
bug Something isn't working

Comments

@papitz
Copy link

papitz commented May 23, 2025

Neovim version (nvim -v)

NVIM v0.11.1

Operating system/version

Linux arch 6.14.6-arch1-1

Read debugging tips

Add the debug logs

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

Log file

2025-05-2313:13:18[DEBUG] Running formatters on /home/paul/Projects/EFGH/flutter-template/lib/models/example_data.dart: { "dart_format" } 2025-05-23 13:13:18[INFO] Run dart_format on /home/paul/Projects/EFGH/flutter-template/lib/models/example_data.dart 2025-05-23 13:13:18[TRACE] Input lines: { "import 'package:dart_mappable/dart_mappable.dart';", "", "part 'example_data.mapper.dart';", "", "// Annotation to generate the mappers", "@MappableClass(caseStyle: CaseStyle.snakeCase)", "/// Mappable example class", "///", "/// This will generate functions like copyWith", "/// To use itdart run build_runner watchneeds to be run", "class ExampleData with ExampleDataMappable {", " final String uid;", " final String exampleField;", "", " ExampleData({required this.uid, required this.exampleField,});", "}" } 2025-05-23 13:13:18[DEBUG] Run command: { "/home/paul/fvm/default/bin/dart", "format" } 2025-05-23 13:13:18[DEBUG] Run default CWD: /home/paul/Projects/EFGH/flutter-template 2025-05-23 13:13:19[DEBUG] dart_format exited with code 0 2025-05-23 13:13:19[TRACE] Output lines: { "import 'package:dart_mappable/dart_mappable.dart';", "", "part 'example_data.mapper.dart';", "", "// Annotation to generate the mappers", "@MappableClass(caseStyle: CaseStyle.snakeCase)", "/// Mappable example class", "///", "/// This will generate functions like copyWith", "/// To use itdart run build_runner watchneeds to be run", "class ExampleData with ExampleDataMappable {", " final String uid;", " final String exampleField;", "", " ExampleData({required this.uid, required this.exampleField});", "}" } 2025-05-23 13:13:19[TRACE] dart_format stderr: { "" } 2025-05-23 13:13:19[TRACE] Applying formatting to /home/paul/Projects/EFGH/flutter-template/lib/models/example_data.dart 2025-05-23 13:13:19[TRACE] Comparing lines { "import 'package:dart_mappable/dart_mappable.dart';", "", "part 'example_data.mapper.dart';", "", "// Annotation to generate the mappers", "@MappableClass(caseStyle: CaseStyle.snakeCase)", "/// Mappable example class", "///", "/// This will generate functions like copyWith", "/// To use itdart run build_runner watchneeds to be run", "class ExampleData with ExampleDataMappable {", " final String uid;", " final String exampleField;", "", " ExampleData({required this.uid, required this.exampleField,});", "}" } and { "import 'package:dart_mappable/dart_mappable.dart';", "", "part 'example_data.mapper.dart';", "", "// Annotation to generate the mappers", "@MappableClass(caseStyle: CaseStyle.snakeCase)", "/// Mappable example class", "///", "/// This will generate functions like copyWith", "/// To use itdart run build_runner watch` needs to be run", "class ExampleData with ExampleDataMappable {", " final String uid;", " final String exampleField;", "", " ExampleData({required this.uid, required this.exampleField});", "}" }
2025-05-23 13:13:19[TRACE] Diff indices { { 15, 1, 15, 1 } }
2025-05-23 13:13:19[TRACE] Applying text edits: { {
newText = "",
range = {
["end"] = {
character = 61,
line = 14
},
start = {
character = 60,
line = 14
}
}
} }
2025-05-23 13:13:19[TRACE] Done formatting /home/paul/Projects/EFGH/flutter-template/lib/models/example_data.dart

Describe the bug

When calling dart format from within conform (or with the provided debug script through vim.system) the options set in analysis_options.yaml are ignored. The options are picked up when the formatter is run directly from the command line.

What is the severity of this bug?

tolerable (can work around it)

Steps To Reproduce

  1. Have analysis_options.yaml file in cwd
  2. nvim -u repro.lua example_file.dart
  3. Run the formatter
  4. Comma will be removed instead of splitting the lines

Expected Behavior

The arguments should be split up into two lines because of the trailing comma, instead the comma is dropped.

Minimal example file

class ExampleData {
  final String uid;
  final String exampleField;

  ExampleData({required this.uid, required this.exampleField,});
}

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-- 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
                                formatters_by_ft = {
                                        dart = { "dart_format" },
                                },
                        })
                end,
        },
        -- add any other plugins here
}
require("lazy").setup(plugins, {
        root = root .. "/plugins",
})

vim.cmd.colorscheme("tokyonight")
-- add anything else here
()
      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

analysis_options.yaml

formatter:
  trailing_commas: preserve
@papitz papitz added the bug Something isn't working label May 23, 2025
@papitz
Copy link
Author

papitz commented May 23, 2025

Setting lsp_format = 'prefer' fixes this in my full config, but obviously does not work if no lsps are set up, which is why this issue still stands.

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

No branches or pull requests

1 participant