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

YAPF applies custom column length wrong on the first save (and correct on the second one) #984

Closed
courteouselk opened this issue Mar 8, 2018 · 3 comments
Labels
area-formatting bug Issue identified by VS Code Team member as probable bug

Comments

@courteouselk
Copy link

courteouselk commented Mar 8, 2018

Environment data

  • VS Code version: 1.21.1
  • Python Extension version: 2018.1
  • OS and version: Microsoft Windows [Version 10.0.14393]
  • Python Version: 3.6.3
  • Relevant/affected Python packages and their versions: pep8 (1.7.1), yapf (0.20.2), pycodestyle (2.3.1)

Actual behavior

After saving a file YAPF first reformats it using default 80 characters column limit, but then after saving the same file for the second time (without any changes) the actually configured column limit is applied (120 in my case) and the file is reformatted again.

I have the following setup.cfg:

[pep8]
max-line-length = 120

[pycodestyle]
max-line-length = 120

[yapf]
based_on_style = pep8
column_limit = 120

.. and the following user settings:

    "python.linting.enabled": true,
    "python.linting.pylintEnabled": false,
    "python.linting.pep8Enabled": true,
    "python.linting.pep8Path": "pycodestyle",
    "python.formatting.provider": "yapf",
    "[python]": { "editor.formatOnSave": true },

Expected behavior

Automatic formatting should by applied right first time.

Steps to reproduce:

  • Configure VS Code as per above snippets.
  • Create a file test.py with the following contents:
def foo():
    foo = ['f', 'o', 'o', ' ', 'f', 'o', 'o', ' ', 'f', 'o', 'o', ' ', 'f', 'o', 'o', ' ', 'f', 'o', 'o', ' ', 'f', 'o', 'o', ' ']
    return foo
  • Save it once, save it twice.

Logs

Output for Python in the Output panel (ViewOutput, change the drop-down the upper-right of the Output panel to Python)

none

Output from Console under the Developer Tools panel (toggle Developer Tools on under Help)

none

Screenshot

yapf

@courteouselk
Copy link
Author

courteouselk commented Mar 8, 2018

If I inject the column limit directly into YAPF command line like this (goes into user settings):

"python.formatting.yapfArgs": ["--style={ based_on_style: pep8, column_limit: 120 }"],

.. then I get the correct behavior.

@patrys
Copy link

patrys commented Mar 8, 2018

This is duplicate of #730

@DonJayamanne
Copy link

Agreed, closing as a duplicate

@DonJayamanne DonJayamanne added bug Issue identified by VS Code Team member as probable bug closed-duplicate area-formatting labels Mar 8, 2018
@lock lock bot locked as resolved and limited conversation to collaborators Jul 11, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-formatting bug Issue identified by VS Code Team member as probable bug
Projects
None yet
Development

No branches or pull requests

3 participants