PyCQA / pycodestyle

Simple Python style checker in one Python file
https://pycodestyle.pycqa.org
Other
5.01k stars 755 forks source link

E501: strings links should allow “introduction” #406

Open xZise opened 9 years ago

xZise commented 9 years ago

The line length checker excepts URL only lines because of #224 which is sensible. But usually there is some introduction like:

So maybe there is a way to allow something before an URL when it's a comment or doc string. The question is now what is sensible. Maybe something like [^ ]+: so it would allow the above line or something like:

See: https://example.com/a-very-very-very

It wouldn't allow “See also:” so maybe it should just strip the URL and check the rest of the line?

wbolster commented 8 years ago

One should just add a newline instead of leading text before a long url in a comment. The leading text is just normal prose which should be wrapped if possible:

# See also:
# http://example.org/a-very-very-very-very-very-very-very-very-very-very-long-url

However, a common scenario is to list multiple urls, and use some sort of "list formatting" inside that comment:

# See also:
# - http://example.org/a-very-very-very-very-very-very-very-very-very-very-long-url
# - http://example.org/another-very-very-very-very-very-very-very-very-very-very-long-url

This currently triggers E501 (line too long), but imho it should not, since this seems a very reasonable way to format a comment like this.

Perhaps the url exception (see #224) can be extended to allow any non-alphabetic leading string? This would account for the "list scenario" in the example above, and would allow using - (hyphen) and * (asterisk) as a bullet.

wbolster commented 8 years ago

Btw, keep in mind that comments can contain markup, e.g. Sphinx documentation for attributes use reStructuredText markup inside magical comment strings starting with #:. Contrived example to illustrate this:

class Foo(object):
    #: This is the description for some attribute. It can take the following values:
    #: - foo
    #: - bar
    #:
    #: See also:
    #: - http://example.org/a-very-very-very-very-very-very-very-very-very-very-long-url
    #: - http://example.org/another-very-very-very-very-very-very-very-very-very-very-long-url
    some_attr = 'some-default'

Sphinx will render this into HTML with a paragraph, a list, another paragraph, and a list of links.