Skip to content

Commit

Permalink
flake8 and formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
ottobackwards committed Jan 26, 2023
1 parent ffb010d commit 2301c29
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 10 deletions.
19 changes: 19 additions & 0 deletions .flake8
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
[flake8]
# E203: whitespace before ':' (black / flake8 disagreement)
# E731: do not assign a lambda expression, use a def
# W503: line break before binary operator (black / flake8 disagreement)
ignore=E203,E731,W503
# E101: indentation contains mixed spaces and tabs ( formatting test strings )
# E402: module level import not at top of file
# E501: line too long ( for zeek script samples in comments )
# F405: may be undefined, or defined from star imports
# F403: from .manager import *' used; unable to detect undefined names
# F841: local variable name is assigned but never used
# W191: indentation contains tabs ( formatting test strings )
per-file-ignores = */__init__.py: F405,F403,E402 tests/*.py: E101,E402,F841,W191 zeekscript/script.py: E501

max-line-length = 88

# Do not check sub modules
exclude =
tree-sitter-zeek,
1 change: 1 addition & 0 deletions .git-blame-ignore-revs
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
# Migrate code style to Black
eabad6da1b6f8eef1d362e6d6a5d64a82663512b
10 changes: 7 additions & 3 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,25 @@ repos:
rev: v4.4.0
hooks:
- id: trailing-whitespace
exclude: testing/baselines
- id: end-of-file-fixer
exclude: testing/baselines
- id: check-yaml
- id: check-added-large-files
- repo: https://github.com/psf/black
rev: 23.1a1
hooks:
- id: black
types: [ python ]
- repo: https://github.com/asottile/pyupgrade
rev: v3.3.1
hooks:
- id: pyupgrade
args: ["--py37-plus"]

types: [ python ]
- repo: https://github.com/pycqa/flake8
rev: 5.0.4 # 6.0.0 requires Python 3.8
hooks:
- id: flake8
types: [ python ]
exclude: |
(?x)^(
tests/data|
Expand Down
2 changes: 1 addition & 1 deletion zeekscript/formatter.py
Original file line number Diff line number Diff line change
Expand Up @@ -1434,7 +1434,7 @@ def format(self):
try:
if (
self.node.next_cst_sibling.is_nl()
and self.node.next_cst_sibling.next_cst_sibling.is_zeekygen_prev_comment()
and self.node.next_cst_sibling.next_cst_sibling.is_zeekygen_prev_comment() # noqa: E501
):
self._write_nl()
except AttributeError:
Expand Down
9 changes: 5 additions & 4 deletions zeekscript/output.py
Original file line number Diff line number Diff line change
Expand Up @@ -223,10 +223,11 @@ def write_linebreak():
)

# Helpful for tracing linebreak decision-making:
# print_error('XXX gal:%d nla:%d nbh:%d tl:%d ex:%d ei:%d naw:%d | %s %s %s' % (
# cnd_good_after_lb, cnd_no_lb_after, cnd_no_break_hints,
# cnd_line_too_long, cnd_enough_excess, cnd_enough_line_items,
# cnd_no_addl_wrap, out.data, col_flushed, tbd_len))
# print_error('XXX gal:%d nla:%d nbh:%d tl:%d ex:%d ei:%d naw:%d
# | %s %s %s' % ( cnd_good_after_lb, cnd_no_lb_after,
# cnd_no_break_hints, cnd_line_too_long, cnd_enough_excess,
# cnd_enough_line_items, cnd_no_addl_wrap, out.data,
# col_flushed, tbd_len))

# If the line is too long and this chunk says it best follows a
# break, then break now. This helps align e.g. multi-part boolean
Expand Down
2 changes: 1 addition & 1 deletion zeekscript/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def as_file(source):


class Parser:
"""tree_sitter.Parser abstraction that takes care of loading the TS Zeek language."""
"""tree_sitter.Parser abstraction for loading the TS Zeek language."""

TS_PARSER = None # A tree_sitter.Parser singleton

Expand Down
1 change: 0 additions & 1 deletion zeekscript/script.py
Original file line number Diff line number Diff line change
Expand Up @@ -408,7 +408,6 @@ def make_node(node):
new_node.children[-1].prev_sibling = new_node.children[-2]

pending_errors = []
last_nonerror = None

for child in new_node.children:
if child.type == "ERROR":
Expand Down

0 comments on commit 2301c29

Please sign in to comment.