diff --git a/language_formatters_pre_commit_hooks/pretty_format_toml.py b/language_formatters_pre_commit_hooks/pretty_format_toml.py index bb3864c..949d820 100644 --- a/language_formatters_pre_commit_hooks/pretty_format_toml.py +++ b/language_formatters_pre_commit_hooks/pretty_format_toml.py @@ -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", @@ -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, ), diff --git a/test-data/pretty_format_toml/inline-comment-1spaces-pretty-formatted.toml b/test-data/pretty_format_toml/inline-comment-1spaces-pretty-formatted.toml new file mode 100644 index 0000000..076cfd5 --- /dev/null +++ b/test-data/pretty_format_toml/inline-comment-1spaces-pretty-formatted.toml @@ -0,0 +1,2 @@ +[root] +root_key = "root_key" # root diff --git a/test-data/pretty_format_toml/inline-comment-2spaces-pretty-formatted.toml b/test-data/pretty_format_toml/inline-comment-2spaces-pretty-formatted.toml new file mode 100644 index 0000000..982b514 --- /dev/null +++ b/test-data/pretty_format_toml/inline-comment-2spaces-pretty-formatted.toml @@ -0,0 +1,2 @@ +[root] +root_key = "root_key" # root diff --git a/tests/pretty_format_toml_test.py b/tests/pretty_format_toml_test.py index e5f8082..f0443ef 100644 --- a/tests/pretty_format_toml_test.py +++ b/tests/pretty_format_toml_test.py @@ -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):