How can I change pylint tab width from 4 spaces to 2 spaces?
Asked Answered
I

2

9

I have tried pylint --indent-string=" ", but I keep getting the help message. What am I supposed to do to configure pylint.

Inspiratory answered 9/1, 2019 at 20:17 Comment(0)
S
11

According to the docs, " " means 4 spaces.

You need to use single quotes: pylint --indent-string=' '

Scapular answered 27/6, 2019 at 22:39 Comment(2)
Doesn't seem to work Bad indentation. Found 2 spaces, expected 4Onshore
You should also update this: indent-after-paren=2Messinger
Y
1

I realize you're probably not having this issue anymore but figure i'd suggest another solution that could be useful for others.

Within pylintrc, generated with pylint --generate-rcfile have a look at the line configuring indent-string:

# String used as indentation unit. This is usually "  " (4 spaces) or "\t" (1
# tab).
indent-string="    "  

Here whatever number of spaces or tabs you put within the parenthesis will be considered the allowed indent style.

You can then run pylint using this file e.g.

pylint --rcfile .pylintrc <.py file to check>

I should note that the documentation for pylint use markdown which folds multiple whitespaces into one i.e. (the "    " into " ") and hence can be a bit confusing when looking at the docs as it would suggest " " defines a 4 space indent.

Yapon answered 28/2, 2023 at 18:42 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.