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

fix: indentation of multiline string #10

Merged
merged 1 commit into from
Aug 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ repos:
hooks:
- id: black
- repo: https://github.com/pycqa/isort
rev: 5.10.1
rev: 5.12.0
hooks:
- id: isort
- repo: https://github.com/pre-commit/mirrors-mypy
Expand Down
2 changes: 1 addition & 1 deletion .pylintrc
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ ignore=CVS

# Add files or directories matching the regex patterns to the ignore-list. The
# regex matches against paths and can be in Posix or Windows format.
ignore-paths=
ignore-paths=tests,docs

# Files or directories matching the regex patterns are skipped. The regex
# matches against base names, not paths.
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ asort for `__all__` your `__all__` lists

asort is a Python utility / library to sort imports items in an `__all__` list alphabetically
It provides a command line utility, Python library and pre-commit support to
quickly sort all your imports. It requires Python 3.7+ to run but supports formatting
quickly sort all your imports. It requires Python 3.7+ to run but supports formatting
any version of Python code.

Works seemlessly with [black](https://github.com/psf/black) and [isort](https://github.com/PyCQA/isort) with no configuration needed
Expand Down
2 changes: 1 addition & 1 deletion src/asort/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ def write_stream(processed_tokens: Iterable[TokenInfo], output_stream: TextIO) -
whitespace_len = token.start[1] - prev_token.end[1]
else:
whitespace_len = len(token.line) - len(token.line.lstrip())
if token.string.isspace() or token.start[0] != token.end[0]:
if token.string.isspace():
whitespace_len = 0

output_stream.write(" " * whitespace_len)
Expand Down
42 changes: 35 additions & 7 deletions tests/integration/__snapshots__/test_cli.ambr
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,34 @@
True
# ---
# name: test_cli_output.2
'''
class SingleLine:
"""Single line of docstring."""

var = ["1", "2"]


class Multiline:
"""Multiple lines of docstring.

Used to test the docstring with multiple lines.
"""

var = ["1", "2"]
"""Test string in
multiple lines."""

"""Test string in a single line."""

"""Test \
string in a single line."""

'''
# ---
# name: test_cli_output.3
False
# ---
# name: test_cli_output.4
'''
__all__ = [ # comment
"Today", # comment
Expand All @@ -44,33 +72,33 @@

'''
# ---
# name: test_cli_output.3
# name: test_cli_output.5
True
# ---
# name: test_cli_output.4
# name: test_cli_output.6
'''
__all__ = ["1", "2", "5", "9"] ; __all__ = ["2", "3", "9"] # fmt: skip

'''
# ---
# name: test_cli_output.5
# name: test_cli_output.7
True
# ---
# name: test_cli_output.6
# name: test_cli_output.8
'''
__all__ = ["One", "Zed"]

'''
# ---
# name: test_cli_output.7
# name: test_cli_output.9
False
# ---
# name: test_cli_output.8
# name: test_cli_output.10
'''
__all__ = ["Today", "Yesterday", "_Thursday"] # comment

'''
# ---
# name: test_cli_output.9
# name: test_cli_output.11
True
# ---
20 changes: 20 additions & 0 deletions tests/integration/fixtures/multi_line_string_indentation.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
class SingleLine:
"""Single line of docstring."""

var = ["1", "2"]


class Multiline:
"""Multiple lines of docstring.

Used to test the docstring with multiple lines.
"""

var = ["1", "2"]
"""Test string in
multiple lines."""

"""Test string in a single line."""

"""Test \
string in a single line."""