Skip to content

Commit

Permalink
Merge branch 'asottile:main' into add-support-for-backword
Browse files Browse the repository at this point in the history
  • Loading branch information
qexat authored Jan 23, 2024
2 parents f291719 + 661eec0 commit 402deb0
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 12 deletions.
12 changes: 6 additions & 6 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.4.0
rev: v4.5.0
hooks:
- id: trailing-whitespace
- id: end-of-file-fixer
Expand All @@ -10,11 +10,11 @@ repos:
- id: name-tests-test
- id: requirements-txt-fixer
- repo: https://github.com/asottile/setup-cfg-fmt
rev: v2.4.0
rev: v2.5.0
hooks:
- id: setup-cfg-fmt
- repo: https://github.com/asottile/reorder-python-imports
rev: v3.10.0
rev: v3.12.0
hooks:
- id: reorder-python-imports
args: [--py38-plus, --add-import, 'from __future__ import annotations']
Expand All @@ -23,7 +23,7 @@ repos:
hooks:
- id: add-trailing-comma
- repo: https://github.com/asottile/pyupgrade
rev: v3.10.1
rev: v3.15.0
hooks:
- id: pyupgrade
args: [--py38-plus]
Expand All @@ -32,10 +32,10 @@ repos:
hooks:
- id: autopep8
- repo: https://github.com/PyCQA/flake8
rev: 6.1.0
rev: 7.0.0
hooks:
- id: flake8
- repo: https://github.com/pre-commit/mirrors-mypy
rev: v1.5.1
rev: v1.8.0
hooks:
- id: mypy
2 changes: 1 addition & 1 deletion babi/buf.py
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ def tab_string(self) -> str:

def rendered_line(self, idx: int, dim: Dim) -> str:
x = self._cursor_x if idx == self.y else 0
expanded = self._lines[idx].expandtabs(self.tab_size)
expanded = self._lines[idx].expandtabs(self.tab_size).lstrip('\ufeff')
return scrolled_line(expanded, x, dim.width)

# movement
Expand Down
10 changes: 8 additions & 2 deletions babi/linters/pre_commit.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,16 @@ def command(self, filename: str, scope: str) -> tuple[str, ...] | None:
return None # not in a git repo!

# no pre-commit config!
if not os.path.exists(os.path.join(root, '.pre-commit-config.yaml')):
cfg = os.path.join(root, '.pre-commit-config.yaml')
if not os.path.exists(cfg):
return None

return ('pre-commit', 'run', '--color=never', '--files', filename)
return (
'pre-commit', 'run',
'--color=never',
'--config', cfg,
'--files', filename,
)

def parse(self, filename: str, output: str) -> tuple[linting.Error, ...]:
root = self._root(filename)
Expand Down
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[metadata]
name = babi
version = 1.5.5
version = 1.5.6
description = a text editor
long_description = file: README.md
long_description_content_type = text/markdown
Expand Down
11 changes: 11 additions & 0 deletions tests/features/save_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,17 @@ def test_mixed_newlines(run, tmpdir):
h.await_text(r"mixed newlines will be converted to '\n'")


def test_byte_order_marker(run, tmpdir):
src = b'\xef\xbb\xbfhello\n'
f = tmpdir.join('f')
f.write_binary(src)
with run(str(f)) as h, and_exit(h):
# renders ok without an extra space for BOM
h.await_text('\nhello\n')
h.press('^S')
assert f.read_binary() == src


def test_modify_file_with_windows_newlines(run, tmpdir):
f = tmpdir.join('f')
f.write_binary(b'foo\r\nbar\r\n')
Expand Down
10 changes: 8 additions & 2 deletions tests/linters/pre_commit_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,10 +96,16 @@ def test_command_returns_none_no_pre_commit_config(tmpdir_git):


def test_command_returns_when_config_exists(tmpdir_git):
tmpdir_git.join('.pre-commit-config.yaml').write('{}\n')
cfg = tmpdir_git.join('.pre-commit-config.yaml')
cfg.write('{}\n')
path = str(tmpdir_git.join('t.py'))
ret = PreCommit().command(path, 'source.python')
assert ret == ('pre-commit', 'run', '--color=never', '--files', path)
assert ret == (
'pre-commit', 'run',
'--color=never',
'--config', str(cfg),
'--files', path,
)


def test_filters_file_paths_to_actual_file(tmpdir_git):
Expand Down

0 comments on commit 402deb0

Please sign in to comment.