Skip to content

Smart code line length validation #1182

Closed
@orsinium

Description

@orsinium

Rule request

Thesis

  1. Validate that code line not longer than N chars. Looks like 89.5 chars is a convention for now (one, two).
  2. Allow lines longer than N chars if the part after N chars contains only a string and optional comma.
  3. Maybe, even such lines should be limited. For instance, not to get longer than 120 chars. However, this part can be validated by flake8 max-line-length without any effort from us.

Example:

d = {
  # it is ok
  'one': 'some really long message that goes beyond 90 chars',
}

Reasoning

Statements longer than 80 columns will be broken into sensible chunks, unless exceeding 80 columns significantly increases readability and does not hide information. <...> However, never break user-visible strings such as printk messages, because that breaks the ability to grep for them.

I see a lot of Python code that does some awful breaks to fit long text messages into the project's line limit just because. However, it creates a lot of difficulties:

  1. Difficult to grep.
  2. Easy to miss a space on the string breaks.
  3. It doesn't make code more readable at all, even decreases readability. In most cases, I don't care if the ending of an error message goes outside of my screen.

After all, it's good to relax a rule that looks not so reasonable in the modern world:

Go has no line length limit. Don't worry about overflowing a punched card.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions