Skip to content

Commit

Permalink
Merge pull request #177 from lyz-code/fix/jinja_on_variables
Browse files Browse the repository at this point in the history
fix/jinja on variables
  • Loading branch information
lyz-code committed Aug 1, 2022
2 parents 6b2ddcf + ef3a793 commit 6f292b7
Show file tree
Hide file tree
Showing 7 changed files with 80 additions and 77 deletions.
2 changes: 1 addition & 1 deletion .cruft.json
@@ -1,6 +1,6 @@
{
"template": "https://github.com/lyz-code/cookiecutter-python-project",
"commit": "c505523e4dbc5d52dccd56bfc30c86f3e8782bcc",
"commit": "b4ee022e63368b00d8dcd877ace8d3760eb706ba",
"context": {
"cookiecutter": {
"project_name": "yamlfix",
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Expand Up @@ -170,7 +170,7 @@ build-docs:
@echo "- Building documentation -"
@echo "--------------------------"

pdm run mkdocs build
pdm run mkdocs build --strict

@echo ""

Expand Down
2 changes: 0 additions & 2 deletions mkdocs.yml
Expand Up @@ -30,8 +30,6 @@ markdown_extensions:
- abbr
- def_list
- admonition
- markdown_include.include:
base_path: docs
- meta
- toc:
permalink: true
Expand Down
125 changes: 68 additions & 57 deletions pdm.lock

Large diffs are not rendered by default.

7 changes: 3 additions & 4 deletions pyproject.toml
Expand Up @@ -69,9 +69,6 @@ editable-backend = "path"
# To be removed once https://github.com/flakeheaven/flakeheaven/issues/55 is solved
"importlib-metadata" = ">=3.10"

# To be removed once https://github.com/mkdocs/mkdocs/issues/2892 is solved
markdown = "<3.4"

[tool.pdm.dev-dependencies]
lint = [
"yamllint>=1.26.3",
Expand Down Expand Up @@ -282,8 +279,10 @@ pyflakes = [

[tool.flakeheaven.exceptions."tests/"]
flake8-docstrings = [
"-D205", # 1 blank line required between summary line and description
"-D212", # Multi-line docstring summary should start at the first line
"-D400", # First line should end with a period
"-D205" # 1 blank line required between summary line and description
"-D415", # First line should end with a period, question mark, or exclamation point
]
flake8-annotations = [
"-ANN001",
Expand Down
2 changes: 1 addition & 1 deletion src/yamlfix/services.py
Expand Up @@ -352,7 +352,7 @@ def _encode_jinja2_line(line: str) -> str:
variable_terms.append(word)
new_line.append("★".join(variable_terms))
variable_terms = []
elif word == "{{" or len(variable_terms) > 0:
elif re.search("{{", word) or len(variable_terms) > 0:
variable_terms.append(word)
else:
new_line.append(word)
Expand Down
17 changes: 6 additions & 11 deletions tests/unit/test_services.py
Expand Up @@ -567,29 +567,24 @@ def test_fix_code_respects_comment_symbol_in_strings_with_double_quotes(

assert result == desired_source

def test_fix_code_respects_jinja_variables(
def test_fix_code_respects_jinja_variables_with_equals(
self,
) -> None:
"""
Given: Code with a long string that contains a jinja variable
Given: Code with a long string that contains a jinja variable after an equal
When: fix_code is run
Then: The jinja string is not broken
"""
source = (
"---\n"
"project: This is a long long long long line that should not be split on "
"the jinja {{ variable }}"
)
desired_source = (
"---\n"
"project: This is a long long long long line that should not be split on "
"the jinja\n"
" {{ variable }}\n"
"environment:\n"
" - SUPER_LONG_VARIABLE={{ this_is_a_super_long_long_long_long_long"
"_variable_name }}\n"
)

result = fix_code(source)

assert result == desired_source
assert result == source

def test_fix_code_respects_many_jinja_variables(
self,
Expand Down

0 comments on commit 6f292b7

Please sign in to comment.