Skip to content

Commit

Permalink
Merge pull request #205 from alkatar21/inline-comment-spaces
Browse files Browse the repository at this point in the history
Add an option for inline-comment-spaces for toml
  • Loading branch information
macisamuele authored Mar 31, 2024
2 parents 97a46d9 + 39e67c5 commit 86cdd95
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 1 deletion.
8 changes: 7 additions & 1 deletion language_formatters_pre_commit_hooks/pretty_format_toml.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,12 @@ def pretty_format_toml(argv: typing.Optional[typing.List[str]] = None) -> int:
default="2",
help="The number of spaces to be used as delimiter for indentation level (Default: %(default)s)",
)
parser.add_argument(
"--inline-comment-spaces",
type=int,
default="2",
help="The number of spaces to be used as delimiter before inline comments (Default: %(default)s)",
)
parser.add_argument("filenames", nargs="*", help="Filenames to fix")
parser.add_argument(
"--trailing-commas",
Expand Down Expand Up @@ -58,7 +64,7 @@ def pretty_format_toml(argv: typing.Optional[typing.List[str]] = None) -> int:
),
sort_config=SortConfiguration(tables=not args.no_sort, table_keys=not args.no_sort),
format_config=FormattingConfiguration(
spaces_before_inline_comment=2,
spaces_before_inline_comment=args.inline_comment_spaces,
spaces_indent_inline_array=args.indent,
trailing_comma_inline_array=args.trailing_commas,
),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[root]
root_key = "root_key" # root
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[root]
root_key = "root_key" # root
4 changes: 4 additions & 0 deletions tests/pretty_format_toml_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ def test_pretty_format_toml(filename, expected_retval):
("indent4-pretty-formatted.toml", ["--indent=4"], 0),
("no-sort-pretty-formatted.toml", ["--no-sort"], 0),
("no-sort-pretty-formatted.toml", [], 1),
("inline-comment-2spaces-pretty-formatted.toml", [], 0),
("inline-comment-2spaces-pretty-formatted.toml", ["--inline-comment-spaces=2"], 0),
("inline-comment-1spaces-pretty-formatted.toml", [], 1),
("inline-comment-1spaces-pretty-formatted.toml", ["--inline-comment-spaces=1"], 0),
),
)
def test_pretty_format_toml_custom_cli_arguments(filename, args, expected_retval):
Expand Down

0 comments on commit 86cdd95

Please sign in to comment.