Skip to content

Commit

Permalink
Version 0.2.0 release, closes #114, closes #38, closes #36
Browse files Browse the repository at this point in the history
  • Loading branch information
sobolevn committed Mar 13, 2020
1 parent 32bf86f commit e8dccda
Show file tree
Hide file tree
Showing 9 changed files with 530 additions and 102 deletions.
4 changes: 4 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ dist: xenial
python:
- 3.6
- 3.7
- 3.8

install:
- pip install poetry
Expand All @@ -13,6 +14,9 @@ script:
- poetry run flake8 .
- poetry run pytest
- poetry run mypy flake8_broken_line.py
- poetry check
- poetry run pip check
- poetry run safety check --bare --full-report

after_success:
- pip install coveralls
Expand Down
26 changes: 26 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Version history

We follow Semantic Versions since the `0.1.0` release.

## 0.2.0

### Features

- Adds `python3.8` support

### Bugfixes

- Fixes a bunch of false positives


## 0.1.1

### Bugfixes

- Fixes typos
- Updates project structure


## 0.1.0

- Initial release
35 changes: 28 additions & 7 deletions flake8_broken_line.py
Original file line number Diff line number Diff line change
@@ -1,25 +1,46 @@
# -*- coding: utf-8 -*-

import re
from typing import Optional, Tuple
from typing import Iterator, Tuple, Sequence, Set
import tokenize

import pkg_resources

#: This is a name that we use to install this library:
pkg_name = 'flake8-broken-line'

#: We store the version number inside the `pyproject.toml`:
pkg_version: str = pkg_resources.get_distribution(pkg_name).version

INVALID_LINE_BREAK = re.compile(r'(?<!\\)\\$', re.M)
_INVALID_LINE_BREAK = re.compile(r'(?<!\\)\\$', re.M)
_IGNORED_TOKENS = frozenset((
tokenize.STRING,
tokenize.COMMENT,
tokenize.NL,
tokenize.NEWLINE,
tokenize.ENDMARKER,
))

N400 = 'N400: Found backslash that is used for line breaking'
_N400 = 'N400: Found backslash that is used for line breaking'


def check_line_breaks(physical_line: str) -> Optional[Tuple[int, str]]:
def check_line_breaks(
tree, # we only need this parameter, so plugin will be installed.
file_tokens: Sequence[tokenize.TokenInfo],
) -> Iterator[Tuple[int, int, str, str]]:
"""Functional ``flake8`` plugin to check for backslashes."""
if INVALID_LINE_BREAK.search(physical_line.rstrip()):
return 0, N400
return None
reported: Set[int] = set()

for line_token in file_tokens:
if line_token.exact_type in _IGNORED_TOKENS:
continue

if line_token.start[0] in reported:
continue # There might be several tokens on a same line.

if _INVALID_LINE_BREAK.search(line_token.line):
yield (*line_token.start, _N400, 'check_line_breaks')
reported.add(line_token.start[0])


# Flake8 API definition:
Expand Down
Loading

0 comments on commit e8dccda

Please sign in to comment.