Giter Site home page Giter Site logo

wemake-services / flake8-broken-line Goto Github PK

View Code? Open in Web Editor NEW
110.0 3.0 79.0 622 KB

🚨 Flake8 plugin to forbid backslashes (\) for line breaks

Home Page: https://pypi.org/project/flake8-broken-line/

License: MIT License

Python 100.00%
python python3 flake8 flake8-plugin linter linting code-quality lint

flake8-broken-line's Introduction

flake8-broken-line

wemake.services Build Status codecov Python Version PyPI version wemake-python-styleguide

Do not break the line! 🚨

Installation

pip install flake8-broken-line

It is also a valuable part of wemake-python-styleguide.

Code example

Things we check with this plugin:

# String line breaks, use `()` or `"""` instead:

some_string = 'first line\
second line'

# Use a single line, `()`, or new variables instead:

if 1 == 1 and \
    2 == 2:
    print('Do not do that!')

# Do not use for method chaining:
some_object \
  .call_method(param1, param2) \
  .call_other(keyword=value) \
  .finalize()

# Instead use:
some_objects.call_method(
    param1, param2,
).call_other(
    keyword=value
).finalize()

Error codes

Error code Description
N400 Found backslash that is used for line breaking

License

MIT.

flake8-broken-line's People

Contributors

davfsa avatar dependabot-preview[bot] avatar dependabot-support avatar dependabot[bot] avatar derwiki avatar georgek avatar jashparekh avatar merc1031 avatar mkniewallner avatar sobolevn avatar ydanilin avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

flake8-broken-line's Issues

[N400] How to short imports?

If I have a long import then how should I short it?
I have this:

from app.baz.bar.foo.first_word.second_word.handler import post as first_word_second_word_scoring

And it is longer than 100 symbols in one line. Isort does the following for me:

from app.baz.bar.foo.first_word.second_word.handler import \
    post as first_word_second_word_scoring

And I got: N400: Found backslash that is used for line breaking

PEP8 backslash exception for `with` statements is not honored

Given this example, explicitly allowed by PEP8 (lit. Backslashes may still be appropriate at times. For example, long, multiple with-statements cannot use implicit continuation, so backslashes are acceptable):

async def fnc():
    async with asdf() as a, \
               bsdf():
        return 1

with asdf() as a, \
     bsdf():
    return 1


with \
  asdf() as a, \
  bsdf():
    return 1

This plugin gives many non-PEP8-compliant false positives:

test_continuation.py:2:1: N400: Found backslash that is used for line breaking
    async with asdf() as a, \
               bsdf():
^
test_continuation.py:6:1: N400: Found backslash that is used for line breaking
with asdf() as a, \
     bsdf():
^
test_continuation.py:11:1: N400: Found backslash that is used for line breaking
with \
  asdf() as a, \
  bsdf():
^
test_continuation.py:12:3: N400: Found backslash that is used for line breaking
with \
  asdf() as a, \
  bsdf():
  ^

How to chain methods without arguments?

Thank you for your great strict linting job! I have an IRL question, and maybe it's a good idea to add more examples to README.

For example I have long chain of methods without arguments:

some_object \
  .call_method() \
  .call_other() \
  .finalize()

So it should be:

some_objects.call_method(

).call_other(

).finalize()

or

some_objects.call_method(
).call_other(
).finalize()

?

Support for flake8 4.x

Hi,

Trying to update flake8 to 4.x is not possible because this extension forces it to be <4.0. Probably there isn't any broken changes, but the dependency needs to be loosen

Compat with flake8 >= 6

"SolverProblemError

Because flake8-broken-line (0.6.0) depends on flake8 (>=3.5,<6) and no versions of flake8-broken-line match >0.6.0,<0.7.0, flake8-broken-line (>=0.6.0,<0.7.0) requires flake8 (>=3.5,<6). So, because project depends on both flake8 (^6.0.0) and flake8-broken-line (^0.6.0), version solving failed."

Please release new version

A recent change made this plugin work with flake8 version 5, but this is still unreleased and actively blocking from migrating to the new flake8 version.

Dependabot can't resolve your Python dependency files

Dependabot can't resolve your Python dependency files.

As a result, Dependabot couldn't update your dependencies.

The error Dependabot encountered was:

Creating virtualenv flake8-broken-line-M5gsrVWi-py3.8 in /home/dependabot/.cache/pypoetry/virtualenvs
Updating dependencies
Resolving dependencies...

[PackageNotFound]
Package pytest-isort (0.3.1) not found.

If you think the above is an error on Dependabot's side please don't hesitate to get in touch - we'll do whatever we can to fix it.

View the update logs.

'''\ Is detected as line break in triple quoted strings

flake8 --version
3.8.2 (flake8-broken-line: 0.2.0, flake8-bugbear: 20.1.4, flake8-colors:
0.1.0, flake8-comprehensions: 3.2.2, flake8-eradicate: 0.3.0, flake8_commas:
2.0.0, flake8_isort: 3.0.0, mccabe: 0.6.1, pycodestyle: 2.6.0, pyflakes:
2.2.0) CPython 3.6.3 on Linux

code to repro

'''\
'''

The \ there is used to elminate the newline from the literal string block as noted 1/2 page down or so here (https://docs.python.org/3.6/tutorial/introduction.html#strings)

String literals can span multiple lines. One way is using triple-quotes: """...""" or '''...'''. End of lines are automatically included in the string, but it’s possible to prevent this by adding a \ at the end of the line. The following example:

Dependabot can't resolve your Python dependency files

Dependabot can't resolve your Python dependency files.

As a result, Dependabot couldn't update your dependencies.

The error Dependabot encountered was:

Creating virtualenv flake8-broken-line-TAFSsRl8-py3.8 in /home/dependabot/.cache/pypoetry/virtualenvs
Updating dependencies
Resolving dependencies...

[PackageNotFound]
Package pytest-isort (0.3.1) not found.

If you think the above is an error on Dependabot's side please don't hesitate to get in touch - we'll do whatever we can to fix it.

View the update logs.

What does "do not reimplement chaining" mean?

The first two examples are good because they provide reasonable alternatives to using the line break. But the third, I'm not sure what it means. How is the programming "implementing" chaining? Can we just suggest a Pythonic alternative instead?

Dependabot can't resolve your Python dependency files

Dependabot can't resolve your Python dependency files.

As a result, Dependabot couldn't update your dependencies.

The error Dependabot encountered was:

Creating virtualenv flake8-broken-line-KHe-WgIB-py3.8 in /home/dependabot/.cache/pypoetry/virtualenvs
Updating dependencies
Resolving dependencies...

[PackageNotFound]
Package pytest-isort (0.3.1) not found.

If you think the above is an error on Dependabot's side please don't hesitate to get in touch - we'll do whatever we can to fix it.

View the update logs.

Broken line in triple quotes

If i have:

text = """
...
very long line 1 - very long line 2
...
"""

So i have E501 (line to long). This is not so beautiful, so i change:

text = """
...
very long line 1 - \
very long line 2
...
"""

And now i have N400 (Found backslash that is used for line braking)

What should i do on this?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.