diff --git a/autoflake.py b/autoflake.py index 79bc76e..7c087a2 100755 --- a/autoflake.py +++ b/autoflake.py @@ -1194,7 +1194,11 @@ def merge_configuration_file(flag_args): if "config_file" in flag_args: config_file = pathlib.Path(flag_args["config_file"]).resolve() - config = process_config_file(config_file) + + if config_file.suffix == ".toml": + config = process_pyproject_toml(config_file) + else: + config = process_config_file(config_file) if not config: _LOGGER.error( diff --git a/test_autoflake.py b/test_autoflake.py index 4dd6271..060da6a 100755 --- a/test_autoflake.py +++ b/test_autoflake.py @@ -3385,6 +3385,32 @@ def test_config_option(self): check=True, ) + def test_config_option_toml(self): + with temporary_file( + suffix=".toml", + contents=( + "[tool.autoflake]\n" + "check = true\n" + 'exclude = [\n "build",\n ".venv",\n]' + ), + ) as temp_config: + self.create_file("test_me.py") + files = [self.effective_path("test_me.py")] + + args, success = autoflake.merge_configuration_file( + { + "files": files, + "config_file": temp_config, + }, + ) + assert success is True + assert args == self.with_defaults( + files=files, + config_file=temp_config, + check=True, + exclude="build,.venv", + ) + def test_load_false(self): self.create_file("test_me.py") self.create_file(