diff --git a/src/usethis/_core/tool.py b/src/usethis/_core/tool.py index 62ac3846..b3bce896 100644 --- a/src/usethis/_core/tool.py +++ b/src/usethis/_core/tool.py @@ -449,8 +449,7 @@ def use_ruff( tool.add_configs() if linter: - tool.select_rules(rule_config.get_all_selected()) - tool.ignore_rules(rule_config.get_all_ignored()) + tool.apply_rule_config(rule_config) if PreCommitTool().is_used(): tool.add_pre_commit_config() else: diff --git a/src/usethis/_tool/impl/ruff.py b/src/usethis/_tool/impl/ruff.py index f4d6efd0..f69b07b3 100644 --- a/src/usethis/_tool/impl/ruff.py +++ b/src/usethis/_tool/impl/ruff.py @@ -409,9 +409,7 @@ def apply_rule_config(self, rule_config: RuleConfig) -> None: """ self.select_rules(rule_config.get_all_selected()) self.ignore_rules(rule_config.get_all_ignored()) - self.ignore_rules_in_glob( - rule_config.tests_unmanaged_ignored, glob="*/tests/**" - ) + self.ignore_rules_in_glob(rule_config.tests_unmanaged_ignored, glob="tests/**") def remove_rule_config(self, rule_config: RuleConfig) -> None: """Remove the Ruff rules associated with a rule config from the project. diff --git a/tests/usethis/_core/test_core_tool.py b/tests/usethis/_core/test_core_tool.py index a354f910..97af2ae6 100644 --- a/tests/usethis/_core/test_core_tool.py +++ b/tests/usethis/_core/test_core_tool.py @@ -1369,10 +1369,24 @@ def test_inp_rules_not_selected_for_tests_dir(self, tmp_path: Path): select = ["INP"] [lint.per-file-ignores] -"*/tests/**" = ["INP"] +"tests/**" = ["INP"] """ ) + @pytest.mark.usefixtures("_vary_network_conn") + def test_ruff_passes(self, tmp_path: Path): + with change_cwd(tmp_path), files_manager(): + # Arrange + use_ruff() + use_pytest() + + # Act + use_import_linter() + + # Assert + with change_cwd(tmp_path), files_manager(): + call_uv_subprocess(["run", "ruff", "check", "."], change_toml=False) + class TestRemove: def test_config_file(self, uv_init_repo_dir: Path): # Arrange @@ -2419,6 +2433,21 @@ def test_foo(): # Assert (that this doesn't raise an error) call_uv_subprocess(["run", "pytest"], change_toml=False) + @pytest.mark.usefixtures("_vary_network_conn") + def test_import_linter_inp_rules(self, tmp_path: Path): + with change_cwd(tmp_path), files_manager(): + # Arrange + use_import_linter() + + # Act + (tmp_path / "ruff.toml").touch() + use_ruff() + + # Assert + with change_cwd(tmp_path), files_manager(): + contents = (tmp_path / "ruff.toml").read_text() + assert """"tests/**" = ["INP"]""" in contents + class TestRemove: class TestRuffIntegration: def test_deselected(self, uv_init_dir: Path): diff --git a/tests/usethis/_interface/test_tool.py b/tests/usethis/_interface/test_tool.py index 9e22fcce..6f547976 100644 --- a/tests/usethis/_interface/test_tool.py +++ b/tests/usethis/_interface/test_tool.py @@ -404,6 +404,20 @@ def test_how(self, tmp_path: Path): """ ) + @pytest.mark.usefixtures("_vary_network_conn") + def test_passes_using_all_tools(self, uv_init_dir: Path): + """Test that pytest runs with all tools installed.""" + with change_cwd(uv_init_dir): + # Arrange, Act + for cmd in ALL_TOOL_COMMANDS: + if not usethis_config.offline: + call_subprocess(["usethis", "tool", cmd]) + else: + call_subprocess(["usethis", "tool", cmd, "--offline"]) + + # Act, Assert + call_uv_subprocess(["run", "ruff", "check", "."], change_toml=False) + class TestPytest: @pytest.mark.usefixtures("_vary_network_conn")