neoformat icon indicating copy to clipboard operation
neoformat copied to clipboard

Fix issues when running multiple formatters and one formatter add/removes lines

Open mabeyj opened this issue 5 years ago • 0 comments

When running multiple formatters, Neoformat doesn't account for lines being added or removed by individual formatters. It just passes the same number of lines to next formatter which can cause issues like the bottom of the file not being formatted or syntax errors.

For example, with this configuration:

let g:neoformat_run_all_formatters = 1
let g:neoformat_enabled_python = ['isort', 'yapf']

Before:

before

  • Run 1: Input is 4 lines. isort inserts 3 blank lines and outputs 7 lines. Only the first 4 lines get passed to yapf which causes the function to not get formatted and a blank line gets removed.
  • Run 2: Input is 6 lines. isort inserts one blank line and outputs 7 lines. Only the first 6 lines get passed to yapf which fails with a syntax error (the missing line being the function body).
  • Run 3: Input is 7 lines and isort doesn't insert any more lines, so the file gets formatted correctly.

After:

after

  • The file is formatted correctly after one run.

mabeyj avatar Jun 09 '19 17:06 mabeyj