diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 791450a0..bda8bfe3 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -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 @@ -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'] @@ -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] @@ -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 diff --git a/babi/buf.py b/babi/buf.py index 9ddb78ac..347bc396 100644 --- a/babi/buf.py +++ b/babi/buf.py @@ -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 diff --git a/babi/linters/pre_commit.py b/babi/linters/pre_commit.py index d5ffc5c9..380608b4 100644 --- a/babi/linters/pre_commit.py +++ b/babi/linters/pre_commit.py @@ -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) diff --git a/setup.cfg b/setup.cfg index 92ed087d..952a484a 100644 --- a/setup.cfg +++ b/setup.cfg @@ -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 diff --git a/tests/features/save_test.py b/tests/features/save_test.py index a960bda1..1cea4b1b 100644 --- a/tests/features/save_test.py +++ b/tests/features/save_test.py @@ -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') diff --git a/tests/linters/pre_commit_test.py b/tests/linters/pre_commit_test.py index 6fdf20a3..7fa7781f 100644 --- a/tests/linters/pre_commit_test.py +++ b/tests/linters/pre_commit_test.py @@ -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):