Lint Check for Indentation
See original GitHub issueIntroduction
We would like to have a pylint check for indentation in Python code. This will likely require a custom lint check. Here are some of the cases we want to handle:
Indent By 4 Spaces
Good:
def func():
pass
my_list = [
'a',
'b',
]
Bad:
def func():
pass
my_list = ['a',
'b',
]
Indent by 8 Spaces for Clarity
Sometimes indenting by 4 spaces is confusing:
if (
some_var == 1):
pass
In these cases, we should indent by 8 spaces instead:
if (
some_var == 1):
pass
Closing Braces/Brackets/Parentheses at End of Line or Same Indentation as Opening Brace/Bracket/Parenthesis
Good:
my_list = {
'a': [
1,
2,
],
'b': True,
}
my_list = {
'a': [
1,
2],
'b': True,
}
Bad:
my_list = {
'a': [
1,
2,
],
}
my_list = {
'a': [
1,
2,
],
}
Sometimes It’s Okay to Not Indent
In some cases, putting a pair of parentheses/braces/brackets on a new line and indenting is unnecessary:
some_function(
{
'a': True,
}
)
This is fine instead:
some_function({
'a': True,
})
Note that here we treat the ({
as a single opening character, so the 'a': True
line is only indented by 4 spaces (not 8)
Issue Analytics
- State:
- Created 2 years ago
- Comments:28 (13 by maintainers)
Top Results From Across the Web
indent - ESLint - Pluggable JavaScript Linter
A pluggable and configurable linter tool for identifying and reporting on patterns in JavaScript. Maintain your code quality with ease.
Read more >Checks - puppet-lint
Checks · Spacing, Indentation & Whitespace · Comments · Quoting · Resources · Conditionals · Classes · Variables · Documentation.
Read more >indentation - Stylelint
By default, the indent level of the CSS code block in non-CSS-like files is determined by the shortest indent of non-empty line. The...
Read more >Space Indentation Expected in ng lint - Stack Overflow
By default ng lint expects indentation to be 2 spaces. You can change these settings in your tslint.json. If you want to use...
Read more >indent - Rule
Indentation size is required for auto-fixing, but not for rule checking. NOTE: auto-fixing will only convert invalid indent whitespace to the desired type,...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
All yours @FaazAbidi!
Are you referring to the above code from the style guide? It’s validly formatted, but this would also be valid:
Does that help?