Skip to content
This repository has been archived by the owner on Nov 30, 2024. It is now read-only.

Commit

Permalink
Rename lint prefix (#10)
Browse files Browse the repository at this point in the history
rename lint prefix to prevent collisions with other flake8 lints.

see: #9

Also update poetry config to latest & fix CI caching
  • Loading branch information
sbdchd authored Apr 17, 2019
1 parent 2e6cd7e commit 8480135
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 26 deletions.
14 changes: 6 additions & 8 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ jobs:

- restore_cache:
keys:
- v1-dependencies-{{ checksum "pyproject.lock" }}
- v1-dependencies-
- v2-dependencies-{{ checksum "poetry.lock" }}
- v2-dependencies-

- run:
name: install dependencies
Expand All @@ -26,7 +26,7 @@ jobs:
paths:
- ./.mypy_cache
- /home/circleci/.cache/pypoetry/
key: v1-dependencies-{{ checksum "pyproject.lock" }}
key: v2-dependencies-{{ checksum "poetry.lock" }}

- run:
name: run tests
Expand All @@ -37,7 +37,6 @@ jobs:
# https://stackoverflow.com/a/26544761/3720597
PYTHONPATH=. poetry run pytest
lint:
docker:
- image: circleci/python:3.6.1
Expand All @@ -47,8 +46,8 @@ jobs:

- restore_cache:
keys:
- v1-dependencies-{{ checksum "pyproject.lock" }}
- v1-dependencies-
- v2-dependencies-{{ checksum "poetry.lock" }}
- v2-dependencies-

- run:
name: install dependencies
Expand All @@ -64,7 +63,7 @@ jobs:
paths:
- ./.mypy_cache
- /home/circleci/.cache/pypoetry/
key: v1-dependencies-{{ checksum "pyproject.lock" }}
key: v2-dependencies-{{ checksum "poetry.lock" }}

- run:
name: run lint
Expand All @@ -73,7 +72,6 @@ jobs:
poetry run black --check .
poetry run flake8 .
workflows:
version: 2
test:
Expand Down
8 changes: 2 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,9 @@

> A flake8 extension that implements misc. lints

## lints

### B781: Assign and Return
### PIE781: Assign and Return

Based on Clippy's
[`let_and_return`](https://rust-lang.github.io/rust-clippy/master/index.html#let_and_return)
Expand All @@ -17,7 +16,6 @@ post](https://steve.dignam.xyz/2018/12/16/creating-a-flake8-lint/).

#### examples


```python
# error
def foo():
Expand All @@ -30,8 +28,7 @@ def foo():
return x
```


### B782: No Pointless F Strings
### PIE782: No Pointless F Strings

Warn about usage of f-string without templated values.

Expand All @@ -44,7 +41,6 @@ x = (
)
```


## dev

```shell
Expand Down
14 changes: 7 additions & 7 deletions flake8_pie.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from functools import partial
import ast

__version__ = "0.0.4"
__version__ = "0.2.0"


class ErrorLoc(NamedTuple):
Expand Down Expand Up @@ -42,7 +42,7 @@ def is_pointless_f_string(node: ast.JoinedStr) -> Optional[ErrorLoc]:
for value in node.values:
if isinstance(value, ast.FormattedValue):
return None
return B782(lineno=node.lineno, col_offset=node.col_offset)
return PIE782(lineno=node.lineno, col_offset=node.col_offset)


def get_assign_target_id(stmt: ast.stmt) -> Optional[str]:
Expand Down Expand Up @@ -78,7 +78,7 @@ def is_assign_and_return(func: ast.FunctionDef) -> Optional[ErrorLoc]:
assign_stmt = func.body[-2]
assign_id = get_assign_target_id(assign_stmt)
if return_stmt.value.id == assign_id:
return B781(
return PIE781(
lineno=return_stmt.lineno, col_offset=return_stmt.col_offset
)

Expand All @@ -100,15 +100,15 @@ def run(self) -> Iterable[ErrorLoc]:
yield from visitor.errors


B781 = partial(
PIE781 = partial(
ErrorLoc,
message="B781: You are assinging to a variable and then returning. Instead remove the assignment and return.",
message="PIE781: You are assinging to a variable and then returning. Instead remove the assignment and return.",
type=Flake8PieCheck,
)


B782 = partial(
PIE782 = partial(
ErrorLoc,
message="B782: Unncessary f-string. You can safely remove the `f` sigil.",
message="PIE782: Unncessary f-string. You can safely remove the `f` sigil.",
type=Flake8PieCheck,
)
File renamed without changes.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "python-lint"
version = "0.0.4"
version = "0.2.0"
description = ""
authors = ["Steve Dignam <steve@dignam.xyz>"]

Expand Down
8 changes: 4 additions & 4 deletions tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

import pytest

from flake8_pie import B781, B782, ErrorLoc, is_assign_and_return, Flake8PieCheck
from flake8_pie import PIE781, PIE782, ErrorLoc, is_assign_and_return, Flake8PieCheck


func_test_cases = [
Expand All @@ -13,7 +13,7 @@ def foo():
x = 'bar'
return x
""",
B781(lineno=4, col_offset=3),
PIE781(lineno=4, col_offset=3),
"single assign then return of that variable is not allowed",
),
(
Expand Down Expand Up @@ -69,7 +69,7 @@ def get_foo(id) -> Optional[Foo]:
).first()
return maybeFoo
""",
B781(lineno=6, col_offset=4),
PIE781(lineno=6, col_offset=4),
"even though we are assigning with a type, a cast would be better "
"and would remove the extra assignment",
),
Expand Down Expand Up @@ -112,7 +112,7 @@ def test_is_assign_and_return(
f"foo {y}",
f"bar"
)""",
B782(lineno=4, col_offset=4),
PIE782(lineno=4, col_offset=4),
"f string with no templates",
),
("f'foo {y}'", None, "used template"),
Expand Down

0 comments on commit 8480135

Please sign in to comment.