vscode python formatting autopep8 disable E266
Asked Answered
Q

1

5

I'm trying to set Visual Studio Code to format using autopep8 but ignoring E266 (too many leading '#' for block comments) to allow Markdown sub-headings in comments.

--ignore setting seems to work for other errors, like E302, but not specifically for E266.

My formatting config is below, E266 still gets enforced, even though E302 is ignored:

    "python.formatting.provider": "autopep8",
    "python.formatting.autopep8Args": [
        "--ignore",
        "E266,E302",
        // E266 = multiple-# in comments
        // E302 = expect 2 blank lines before def
    ],

With the config above, autopep8 will ignore E302 (so it won't insert lines before def), but it continues to remove extra # in comments per E266.

I can set my Linter to ignore E266 so it doesn't get underlined in the UI, but not the Formatter that modifies the code. This is the Linter config which works fine

    "python.pythonPath": "...path...",
    "python.linting.pep8Enabled": true,
    "python.linting.pep8Args": [
        "--ignore=E266"
        // E266 = multiple-# in comments
    ],
    "python.linting.pylintPath": "...path...",
    "python.linting.pylintArgs": [
        "--load-plugins",
        "pylint_django"
    ],
    "python.linting.pylintEnabled": true,

Is there an overlapping rule that's similar to E266 that's causing the Formatter to still make the change despite ignoring E266? Doesn't appear so since the lines being edited are not identified by the Linter when ignoring E266.

Example.py for sample usage

## These lines will lose one "#" when Formatted in VSCode
## Even though we set it to ignore E266
Qintar answered 5/8, 2019 at 21:21 Comment(0)
P
7

You're looking for E265 - Format block comments.

With the following config in my Vscode :

    "python.formatting.autopep8Args": [
    "--ignore=E302,E265"
],

Your example is unchanged for me.
It seems like autopep8 --list-fixes does not match what they list in the README.

Pirandello answered 4/10, 2019 at 8:42 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.