Skip to content
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
1 change: 1 addition & 0 deletions docs/changes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ Weblate 5.15.2

* :ref:`addon-weblate.generate.generate` is now triggered upon installation.
* Screenshots updated from the repository have proper history.
* :ref:`check-rst-syntax` now reports unintended list conversion.

.. rubric:: Bug fixes

Expand Down
2 changes: 1 addition & 1 deletion docs/locales/ja/LC_MESSAGES/docs.po
Original file line number Diff line number Diff line change
Expand Up @@ -48921,7 +48921,7 @@ msgstr ""

#: ../../security/passwords.rst:33
msgid "Social or third-party authentication"
msgstr "- ソーシャル認証またはサードパーティ認証"
msgstr "ソーシャル認証またはサードパーティ認証"

#: ../../security/passwords.rst:35
msgid ""
Expand Down
15 changes: 12 additions & 3 deletions weblate/checks/markup.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,8 @@
re.compile(r"""Interpreted text role "([^"]*)" not implemented\."""),
]

RST_LIST_START = ("- ", "* ", "+ ")


def strip_entities(text):
"""Strip all HTML entities (we don't care about them)."""
Expand Down Expand Up @@ -418,7 +420,7 @@
def extract_rst_references(text: str) -> tuple[dict[str, str], Counter, list[str]]:
memo = SimpleNamespace()
publisher = get_rst_publisher()
document = utils.new_document("", publisher.settings)

Check failure on line 423 in weblate/checks/markup.py

View workflow job for this annotation

GitHub Actions / mypy

Argument 2 to "new_document" has incompatible type "dict[str, Any]"; expected "Values | None"
memo.reporter = document.reporter
memo.document = document
memo.language = languages.get_language(
Expand Down Expand Up @@ -492,7 +494,7 @@
gettext("The following reStructuredText markup is extra: {}"), values
)

def check_single(

Check failure on line 497 in weblate/checks/markup.py

View workflow job for this annotation

GitHub Actions / mypy

Return type "bool | MissingExtraDict" of "check_single" incompatible with return type "bool" in supertype "weblate.checks.base.TargetCheck"
self, source: str, target: str, unit: Unit
) -> bool | MissingExtraDict:
src_references, src_set, _alltags = extract_rst_references(source)
Expand Down Expand Up @@ -531,7 +533,7 @@
):
if isinstance(result, dict):
for key, value in result.items():
results[key].extend(value)

Check failure on line 536 in weblate/checks/markup.py

View workflow job for this annotation

GitHub Actions / mypy

TypedDict key must be a string literal; expected one of ("missing", "extra", "errors")
if results:
errors.extend(self.format_result(results))
if errors:
Expand Down Expand Up @@ -577,9 +579,9 @@
@lru_cache(maxsize=512)
def validate_rst_snippet(
snippet: str, source_tags: tuple[str] | None = None
) -> tuple[list[str], list[str]]:
) -> tuple[tuple[str, ...], tuple[str, ...]]:
publisher = get_rst_publisher()
document = utils.new_document("", publisher.settings)

Check failure on line 584 in weblate/checks/markup.py

View workflow job for this annotation

GitHub Actions / mypy

Argument 2 to "new_document" has incompatible type "dict[str, Any]"; expected "Values | None"

errors: list[str] = []
roles: list[str] = []
Expand Down Expand Up @@ -632,7 +634,7 @@
transform = transform_class(transformer.document, startnode=pending)
transform.apply(**kwargs)
transformer.applied.append((priority, transform_class, pending, kwargs))
return errors, roles
return tuple(errors), tuple(roles)


class RSTSyntaxCheck(RSTBaseCheck):
Expand All @@ -640,11 +642,18 @@
name = gettext_lazy("reStructuredText syntax error")
description = gettext_lazy("reStructuredText syntax error in the translation.")

def check_single(

Check failure on line 645 in weblate/checks/markup.py

View workflow job for this annotation

GitHub Actions / mypy

Return type "bool | MissingExtraDict" of "check_single" incompatible with return type "bool" in supertype "weblate.checks.base.TargetCheck"
self, source: str, target: str, unit: Unit
) -> bool | MissingExtraDict:
_errors, source_roles = validate_rst_snippet(source)
errors, _target_roles = validate_rst_snippet(target, tuple(source_roles))
rst_errors, _target_roles = validate_rst_snippet(target, source_roles)
errors = list(rst_errors)

# This is valid RST, but might mess up the document
if not source.startswith(RST_LIST_START) and target.startswith(RST_LIST_START):
errors.append(
gettext("The translation should not start with a list marker.")
)

if errors:
return {"errors": errors}
Expand All @@ -662,7 +671,7 @@
):
if isinstance(result, dict):
for key, value in result.items():
results[key].extend(value)

Check failure on line 674 in weblate/checks/markup.py

View workflow job for this annotation

GitHub Actions / mypy

TypedDict key must be a string literal; expected one of ("missing", "extra", "errors")
if results:
errors.extend(self.format_result(results))
if errors:
Expand Down
58 changes: 58 additions & 0 deletions weblate/checks/tests/test_markup_checks.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@
def test_skip_mixed(self) -> None:
self.do_test(
False,
(

Check failure on line 96 in weblate/checks/tests/test_markup_checks.py

View workflow job for this annotation

GitHub Actions / mypy

Argument 2 to "do_test" of "CheckTestCase" has incompatible type "tuple[list[str], str, str]"; expected "tuple[str, str, str] | None"
["<emphasis>1st</emphasis>", "<invalid>"],
"<emphasis>not</ emphasis>",
"",
Expand Down Expand Up @@ -413,7 +413,7 @@
)
check = Check(unit=unit)
self.assertHTMLEqual(
self.check.get_description(check),

Check failure on line 416 in weblate/checks/tests/test_markup_checks.py

View workflow job for this annotation

GitHub Actions / mypy

Argument 1 to "assertHTMLEqual" of "SimpleTestCase" has incompatible type "str | _StrPromise"; expected "str"
"""
The following reStructuredText markup is missing:
<span class="hlcheck" data-value=":ref:`bar`">:ref:`bar`</span>,
Expand Down Expand Up @@ -888,7 +888,7 @@
)
check = Check(unit=unit)
self.assertHTMLEqual(
self.check.get_description(check),

Check failure on line 891 in weblate/checks/tests/test_markup_checks.py

View workflow job for this annotation

GitHub Actions / mypy

Argument 1 to "assertHTMLEqual" of "SimpleTestCase" has incompatible type "str | _StrPromise"; expected "str"
"""
The following errors were found:<br>
Inline interpreted text or phrase reference start-string without end-string.
Expand All @@ -904,3 +904,61 @@
"rst-text",
),
)

def test_list(self) -> None:
self.do_test(
False,
(
"Text",
"Text",
"rst-text",
),
)
self.do_test(
True,
(
"Text",
"* Text",
"rst-text",
),
)
self.do_test(
True,
(
"Text",
"- Text",
"rst-text",
),
)
self.do_test(
True,
(
"Text",
"+ Text",
"rst-text",
),
)
self.do_test(
False,
(
"- Text",
"- Text",
"rst-text",
),
)
self.do_test(
False,
(
"- Text",
"* Text",
"rst-text",
),
)
self.do_test(
False,
(
"- Text",
"+ Text",
"rst-text",
),
)
Loading