Skip to content

Added more options to config file (spaces, line length and safety checks) #352

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Feb 12, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions gdtoolkit/formatter/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@
DEFAULT_CONFIG = MappingProxyType(
{
"excluded_directories": {".git"},
"safety_checks": None,
"use_spaces": None,
"line_length": None,
}
)

Expand Down
27 changes: 19 additions & 8 deletions gdtoolkit/formatter/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
Examples:
echo 'pass' | gdformat - # reads from STDIN
"""

import sys
import os
import logging
Expand Down Expand Up @@ -69,14 +70,6 @@ def main():
if arguments["--diff"]:
arguments["--check"] = True

line_length = int(arguments["--line-length"])
spaces_for_indent = (
int(arguments["--use-spaces"])
if arguments["--use-spaces"] is not None
else None
)
safety_checks = not arguments["--fast"]

config_file_path = _find_config_file()
config = _load_config_file_or_default(config_file_path)
_log_config_entries(config)
Expand All @@ -86,6 +79,24 @@ def main():
arguments["<path>"], excluded_directories=set(config["excluded_directories"])
)

line_length = (
int(arguments["--line-length"])
if arguments["--line-length"]
else config.get("line_length", DEFAULT_CONFIG["line_length"])
)

spaces_for_indent = (
int(arguments["--use-spaces"])
if arguments["--use-spaces"]
else config.get("use_spaces", DEFAULT_CONFIG["use_spaces"])
)

safety_checks = (
not arguments["--fast"]
if arguments.get("--fast")
else config.get("safety_checks", DEFAULT_CONFIG["safety_checks"])
)

if files == ["-"]:
_format_stdin(line_length, spaces_for_indent, safety_checks)
elif arguments["--check"]:
Expand Down