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

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

mabeyj
Copy link

@mabeyj mabeyj commented Jun 9, 2019

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant