Skip to content

Commit

Permalink
Implement pycodestyle's logical line detection
Browse files Browse the repository at this point in the history
  • Loading branch information
charliermarsh committed Feb 1, 2023
1 parent 841d176 commit 916fe4c
Show file tree
Hide file tree
Showing 17 changed files with 718 additions and 10 deletions.
7 changes: 7 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ doctest = false

[dependencies]
anyhow = { version = "1.0.66" }
bisection = { version = "0.1.0" }
bitflags = { version = "1.3.2" }
cfg-if = { version = "1.0.0" }
chrono = { version = "0.4.21", default-features = false, features = ["clock"] }
Expand Down
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -695,6 +695,10 @@ For more, see [pycodestyle](https://pypi.org/project/pycodestyle/) on PyPI.
| Code | Name | Message | Fix |
| ---- | ---- | ------- | --- |
| E101 | mixed-spaces-and-tabs | Indentation contains mixed spaces and tabs | |
| E221 | multiple-spaces-before-operator | Multiple spaces before operator | |
| E222 | multiple-spaces-after-operator | Multiple spaces after operator | |
| E223 | tab-before-operator | Tab before operator | |
| E224 | tab-after-operator | Tab after operator | |
| E401 | multiple-imports-on-one-line | Multiple imports on one line | |
| E402 | module-import-not-at-top-of-file | Module level import not at top of file | |
| E501 | line-too-long | Line too long ({length} > {limit} characters) | |
Expand Down
171 changes: 171 additions & 0 deletions resources/test/fixtures/pycodestyle/E22.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,171 @@
#: E221
a = 12 + 3
b = 4 + 5
#: E221 E221
x = 1
y = 2
long_variable = 3
#: E221 E221
x[0] = 1
x[1] = 2
long_variable = 3
#: E221 E221
x = f(x) + 1
y = long_variable + 2
z = x[0] + 3
#: E221:3:14
text = """
bar
foo %s""" % rofl
#: Okay
x = 1
y = 2
long_variable = 3
#:


#: E222
a = a + 1
b = b + 10
#: E222 E222
x = -1
y = -2
long_variable = 3
#: E222 E222
x[0] = 1
x[1] = 2
long_variable = 3
#:


#: E223
foobart = 4
a = 3 # aligned with tab
#:


#: E224
a += 1
b += 1000
#:


#: E225
submitted +=1
#: E225
submitted+= 1
#: E225
c =-1
#: E225
x = x /2 - 1
#: E225
c = alpha -4
#: E225
c = alpha- 4
#: E225
z = x **y
#: E225
z = (x + 1) **y
#: E225
z = (x + 1)** y
#: E225
_1kB = _1MB >>10
#: E225
_1kB = _1MB>> 10
#: E225 E225
i=i+ 1
#: E225 E225
i=i +1
#: E225
i = 1and 1
#: E225
i = 1or 0
#: E225
1is 1
#: E225
1in []
#: E225
i = 1 @2
#: E225
i = 1@ 2
#: E225 E226
i=i+1
#: E225 E226
i =i+1
#: E225 E226
i= i+1
#: E225 E226
c = (a +b)*(a - b)
#: E225 E226
c = (a+ b)*(a - b)
#:

#: E226
z = 2//30
#: E226 E226
c = (a+b) * (a-b)
#: E226
norman = True+False
#: E226
x = x*2 - 1
#: E226
x = x/2 - 1
#: E226 E226
hypot2 = x*x + y*y
#: E226
c = (a + b)*(a - b)
#: E226
def halves(n):
return (i//2 for i in range(n))
#: E227
_1kB = _1MB>>10
#: E227
_1MB = _1kB<<10
#: E227
a = b|c
#: E227
b = c&a
#: E227
c = b^a
#: E228
a = b%c
#: E228
msg = fmt%(errno, errmsg)
#: E228
msg = "Error %d occurred"%errno
#:

#: Okay
i = i + 1
submitted += 1
x = x * 2 - 1
hypot2 = x * x + y * y
c = (a + b) * (a - b)
_1MiB = 2 ** 20
_1TiB = 2**30
foo(bar, key='word', *args, **kwargs)
baz(**kwargs)
negative = -1
spam(-1)
-negative
func1(lambda *args, **kw: (args, kw))
func2(lambda a, b=h[:], c=0: (a, b, c))
if not -5 < x < +5:
print >>sys.stderr, "x is out of range."
print >> sys.stdout, "x is an integer."
x = x / 2 - 1
x = 1 @ 2

if alpha[:-i]:
*a, b = (1, 2, 3)


def squares(n):
return (i**2 for i in range(n))


ENG_PREFIXES = {
-6: "\u03bc", # Greek letter mu
-3: "m",
}
#:
6 changes: 6 additions & 0 deletions ruff.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -1401,6 +1401,12 @@
"E1",
"E10",
"E101",
"E2",
"E22",
"E221",
"E222",
"E223",
"E224",
"E4",
"E40",
"E401",
Expand Down
Loading

0 comments on commit 916fe4c

Please sign in to comment.