Skip to content

Commit 780b44f

Browse files
Support .toml configuration format with --config flag (#249)
* Support .toml configuration format with --config flag * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
1 parent ad613b5 commit 780b44f

File tree

2 files changed

+31
-1
lines changed

2 files changed

+31
-1
lines changed

autoflake.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1194,7 +1194,11 @@ def merge_configuration_file(flag_args):
11941194

11951195
if "config_file" in flag_args:
11961196
config_file = pathlib.Path(flag_args["config_file"]).resolve()
1197-
config = process_config_file(config_file)
1197+
1198+
if config_file.suffix == ".toml":
1199+
config = process_pyproject_toml(config_file)
1200+
else:
1201+
config = process_config_file(config_file)
11981202

11991203
if not config:
12001204
_LOGGER.error(

test_autoflake.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3385,6 +3385,32 @@ def test_config_option(self):
33853385
check=True,
33863386
)
33873387

3388+
def test_config_option_toml(self):
3389+
with temporary_file(
3390+
suffix=".toml",
3391+
contents=(
3392+
"[tool.autoflake]\n"
3393+
"check = true\n"
3394+
'exclude = [\n "build",\n ".venv",\n]'
3395+
),
3396+
) as temp_config:
3397+
self.create_file("test_me.py")
3398+
files = [self.effective_path("test_me.py")]
3399+
3400+
args, success = autoflake.merge_configuration_file(
3401+
{
3402+
"files": files,
3403+
"config_file": temp_config,
3404+
},
3405+
)
3406+
assert success is True
3407+
assert args == self.with_defaults(
3408+
files=files,
3409+
config_file=temp_config,
3410+
check=True,
3411+
exclude="build,.venv",
3412+
)
3413+
33883414
def test_load_false(self):
33893415
self.create_file("test_me.py")
33903416
self.create_file(

0 commit comments

Comments
 (0)