Skip to content

Commit

Permalink
fix. Added the --tabsize command line option. Closes #72.
Browse files Browse the repository at this point in the history
  • Loading branch information
tamere-allo-peter committed Mar 22, 2022
1 parent 06c3562 commit e65f24b
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 9 deletions.
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ This software automatically fixes some errors and warnings reported by
`yamllint`.

```shell
usage: yamlfixer [-h] [-v] [-b] [-B BACKUPSUFFIX] [-d] [-j | -p | -s] [file [file ...]]
usage: yamlfixer [-h] [-v] [-b] [-B BACKUPSUFFIX] [-d] [-j | -p | -s] [-t TABSIZE] [file [file ...]]

Fix formatting problems in YAML documents. If no file is specified,
then reads input from `stdin`.
Expand All @@ -72,6 +72,9 @@ optional arguments:
-s, --summary output colored plain text summary to stderr.
If stderr is not a TTY output is identical to
--plainsummary.
-t TABSIZE, --tabsize TABSIZE
sets the number of spaces to replace tabs with,
default is 2.
```
yamlfixer launches `yamllint` on each specified filename, then parses
Expand Down
3 changes: 3 additions & 0 deletions examples/withtabs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
---
block:
items: # list
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[metadata]
version = 0.4.2
version = 0.4.3
name = yamlfixer-opt-nc
description = automates the fixing of problems reported by yamllint
long_description = file: README.md
Expand Down
2 changes: 1 addition & 1 deletion yamlfixer/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

import time

__version__ = "0.4.2"
__version__ = "0.4.3"
__author__ = "OPT-NC"
__license__ = "GPLv3+"
__copyright__ = "Copyright (C) 2021-%s %s" % (time.strftime("%Y",
Expand Down
6 changes: 5 additions & 1 deletion yamlfixer/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
import argparse

from . import __version__, __copyright__
from .constants import EXIT_CMDLINEERROR
from .yamlfixer import YAMLFixer

GPLBLURB = """
Expand Down Expand Up @@ -77,6 +76,11 @@ def run():
action="store_true",
help="output colored plain text summary to stderr. "
"If stderr is not a TTY output is identical to --plainsummary.")
cmdline.add_argument("-t", "--tabsize",
type=int,
default=2,
help="sets the number of spaces to replace tabs "
"with, default is %(default)i.")
cmdline.add_argument("filenames",
nargs="*",
metavar="file",
Expand Down
9 changes: 4 additions & 5 deletions yamlfixer/problemfixer.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,14 +133,13 @@ def fix_toomany_blanklines(self, left, right): # pylint: disable=unused-argument
del self.ffixer.lines[self.linenum - nblines + 1:self.linenum + 1]
self.ffixer.loffset -= nblines

def fix_syntax_tabchar(self, left, right):
def fix_syntax_tabchar(self, left, right): # pylint: disable=unused-argument
"""Fix:
- syntax error: found character '\\t' that cannot start any token (syntax)
"""
# TODO: We replace TAB with a single space for now
# TODO: yamllint only reports the first one
# TODO: use expandtabs after reading indentation size from .yamllint if possible
self.ffixer.lines[self.linenum] = left + ' ' + right[1:]
line = self.ffixer.lines[self.linenum][:]
self.ffixer.lines[self.linenum] = line.expandtabs(self.ffixer.yfixer.arguments.tabsize)
self.ffixer.coffset += len(self.ffixer.lines[self.linenum]) - len(line)

def fix_missingspace(self, left, right):
"""Fix:
Expand Down

0 comments on commit e65f24b

Please sign in to comment.