question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Lint Check for Indentation

See original GitHub issue

Introduction

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:open
  • Created 2 years ago
  • Comments:28 (13 by maintainers)

github_iconTop GitHub Comments

1reaction
U8NWXDcommented, Jul 15, 2022

All yours @FaazAbidi!

0reactions
U8NWXDcommented, Dec 10, 2022
my_function_with_a_really_long_name(
    'abc', 'def', None)

Are you referring to the above code from the style guide? It’s validly formatted, but this would also be valid:

my_function_with_a_really_long_name(
    'abc',
    'def',
    None,
)

Does that help?

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found