Skip to content

Commit

Permalink
Now handles missing spaces inside brackets.
Browse files Browse the repository at this point in the history
  • Loading branch information
tamere-allo-peter committed May 4, 2022
1 parent b00c910 commit 7cd2435
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 5 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,8 @@ yamlfixer currently (as of 0.9.6) can fix the following problems as reported by
- syntax error: mapping values are not allowed here
- too few spaces after comma (commas)
- too few spaces before comment (comments)
- too few spaces inside empty brackets (brackets)
- too few spaces inside brackets
- too many blank lines
- too many spaces after colon (colons)
- too many spaces after comma (commas)
Expand Down
3 changes: 1 addition & 2 deletions TODO.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,10 @@ Here's a list of problems reported by yamllint which are not currently
supported by yamlfixer, but which might be supported in a future
release :

- too few spaces inside brackets
- too few spaces inside empty brackets
- too many spaces after question mark
- forbidden implicit octal value "%s"
- forbidden explicit octal value "%s"
- forbidden flow sequence (brackets)
- string value is not quoted with %s quotes
- string value is not quoted
- string value is redundantly quoted with %s quotes
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[flake8]
import-order-style = pep8
max-line-length = 120
ignore = T101, W503, AAA01
ignore = T100, T101, W503, AAA01

[pylint.FORMAT]
max-line-length = 120
Expand Down
2 changes: 2 additions & 0 deletions tests/test_listfixers.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ def test_listfixers(self):
- syntax error: mapping values are not allowed here
- too few spaces after comma (commas)
- too few spaces before comment (comments)
- too few spaces inside brackets (brackets)
- too few spaces inside empty brackets (brackets)
- too many blank lines
- too many spaces after colon (colons)
- too many spaces after comma (commas)
Expand Down
12 changes: 10 additions & 2 deletions yamlfixer/problemfixer.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ def fix_newlineateof(self, left, right): # pylint: disable=unused-argument,no-s
""" # noqa: D205, D208, D400
# We simply ignore it, because we always add \n when dumping
# and rely on universal newlines to handle them correctly.
# FIXME : doesn't work when transcoding files for another OS.

def fix_truthy(self, left, right):
"""Fix:
Expand All @@ -136,6 +137,7 @@ def fix_toofew_spacesbefore(self, left, right):
"""Fix:
- too few spaces before comment (comments)
""" # noqa: D205, D208, D400
# TODO : read correct value from yamllint's config
spaces = ' '
if left[-1] != ' ':
spaces += ' '
Expand Down Expand Up @@ -172,16 +174,21 @@ def fix_missingspace(self, left, right):
"""Fix:
- missing starting space in comment (comments)
- too few spaces after comma (commas)
- too few spaces inside brackets (brackets)
- too few spaces inside empty brackets (brackets)
""" # noqa: D205, D208, D400
self.ffixer.lines[self.linenum] = left + ' ' + right
self.ffixer.coffset += 1
# TODO : read correct value from yamllint's config
spaces = ' '
self.ffixer.lines[self.linenum] = left + spaces + right
self.ffixer.coffset += len(spaces)

def fix_toomany_spacesafter(self, left, right):
"""Fix:
- too many spaces after colon (colons)
- too many spaces after comma (commas)
- too many spaces after hyphen (hyphens)
""" # noqa: D205, D208, D400
# TODO : read correct value from yamllint's config
pos = self.colnum
while (pos > 0) and (left[pos - 1] == ' '):
pos -= 1
Expand All @@ -196,6 +203,7 @@ def fix_toomany_spacesother(self, left, right):
- too many spaces before comma (commas)
- too many spaces before colon (colons)
""" # noqa: D205, D208, D400
# TODO : read correct value from yamllint's config
pos = self.colnum
while (pos > 0) and (left[pos - 1] == ' '):
pos -= 1
Expand Down

0 comments on commit 7cd2435

Please sign in to comment.