Repository: MarketSquare/robotframework-robocop
Pull request #1361 (2025-03-27 14:15:01)

Fix reports not loaded from top configuration file
#1358


Patch:
diff --git a/docs/releasenotes/6.0.1.rst b/docs/releasenotes/6.0.1.rst
index d4a6f18..6515fe3 100644
--- a/docs/releasenotes/6.0.1.rst
+++ b/docs/releasenotes/6.0.1.rst
@@ -9,6 +9,11 @@ return_status report fails with no attribute exception (#1357)
 
 ``return_status`` report should no longer fail with `has no exit_code` attribute error.
 
+reports setting is ignored in the configuration file (#1358)
+------------------------------------------------------------
+
+Reports settings was not read correctly from the configuration file. It should now work as expected and reports
+can be enabled from the configuration file.
 
 Acknowledgements
 ================
diff --git a/src/robocop/config.py b/src/robocop/config.py
index 4299d8d..fc22958 100644
--- a/src/robocop/config.py
+++ b/src/robocop/config.py
@@ -723,10 +723,10 @@ class ConfigManager:
             sources = self.sources if self.sources else self.default_config.sources
             ignore_file_filters = not self.force_exclude and bool(sources)
             self.resolve_paths(sources, gitignores=None, ignore_file_filters=ignore_file_filters)
-            self.find_default_config()
+            self.set_default_config()
         yield from self._paths.items()
 
-    def find_default_config(self):
+    def set_default_config(self) -> None:
         """
         Find default config from all loaded configs and set it.
 
@@ -735,15 +735,16 @@ class ConfigManager:
 
         """
         if not self.cached_configs:
-            return self.default_config
+            return
         # look for path as cwd or any of parents of cwd
         cwd = Path.cwd()
         if cwd in self.cached_configs:
-            return self.cached_configs[cwd]
+            self.default_config = self.cached_configs[cwd]
+            return
         for parent in cwd.parents:
             if parent in self.cached_configs:
-                return self.cached_configs[parent]
-        return self.default_config
+                self.default_config = self.cached_configs[parent]
+                return
 
     def get_default_config(self, config_path: Path | None) -> Config:
         """Get default config either from --config option or from the cli."""
@@ -771,7 +772,7 @@ class ConfigManager:
         for check_dir in check_dirs:
             if check_dir in self.cached_configs:
                 return self.cached_configs[check_dir]
-            seen.append(check_dir)
+            seen.append(check_dir.resolve())
             for config_filename in CONFIG_NAMES:
                 if (config_path := (check_dir / config_filename)).is_file():
                     configuration = files.read_toml_config(config_path)
diff --git a/src/robocop/linter/runner.py b/src/robocop/linter/runner.py
index 20e6d71..29bd84a 100644
--- a/src/robocop/linter/runner.py
+++ b/src/robocop/linter/runner.py
@@ -27,6 +27,7 @@ class RobocopLinter:
     def __init__(self, config_manager: ConfigManager):
         self.config_manager = config_manager
         self.current_model: File = None
+        self.sources = self.config_manager.paths
         self.reports: dict[str, reports.Report] = reports.get_reports(self.config_manager.default_config)
         self.diagnostics: list[Diagnostic] = []
         self.configure_reports()
@@ -43,7 +44,7 @@ class RobocopLinter:
     def run(self) -> list[Diagnostic]:
         issues_no = 0
         files = 0
-        for source, config in self.config_manager.paths:
+        for source, config in self.sources:
             if config.verbose:
                 print(f"Scanning file: {source}")
             try:


Test patch:
diff --git a/tests/config/test_config_manager.py b/tests/config/test_config_manager.py
index 0c97e18..a4eee9b 100644
--- a/tests/config/test_config_manager.py
+++ b/tests/config/test_config_manager.py
@@ -419,3 +419,15 @@ class TestConfigFinder:
 
         # Assert
         assert sorted(actual_results.keys()) == expected_paths
+
+    def test_reports_loaded_from_top_config(self, test_data):
+        # Arrange
+        test_dir = test_data / "robot_toml_with_reports"
+
+        # Act
+        with working_directory(test_dir):
+            config_manager = ConfigManager()
+            _ = dict(config_manager.paths)
+
+        # Assert
+        assert config_manager.default_config.linter.reports == ["version", "all", "text_file", "return_status"]
diff --git a/tests/config/test_data/robot_toml_with_reports/robot.toml b/tests/config/test_data/robot_toml_with_reports/robot.toml
new file mode 100644
index 0000000..3b61c6f
--- /dev/null
+++ b/tests/config/test_data/robot_toml_with_reports/robot.toml
@@ -0,0 +1,32 @@
+[tool.robocop]
+
+
+[tool.robocop.lint]
+reports = ["version", "all", "text_file", "return_status"]
+ignore = [
+    "wrong-case-in-keyword-name",
+    "variable-overwritten-before-usage",
+    "no-suite-variable",
+    "no-global-variable",
+    "MISC06",
+]
+configure = [
+    "line-too-long.line_length=200",
+    "line-too-long.ignore_pattern=\"*{\\\"cards\\\":\\[\\],\\\"customers\\\":\\[\\],[\\S+\\s+]*\"",
+    "line-too-long.ignore_pattern=\"*\\$\\.\\.addresses\\[\\?\\([\\S+\\s+]*\"",
+    "too-many-calls-in-test-case.max_calls=30",
+    "too-many-calls-in-keyword.max_calls=30",
+    "too-long-test-case.max_len=60",
+    "too-many-arguments.max_args=10",
+    "too-long-keyword.max_len=90",
+    "file-too-long.max_lines=1000",
+    "inconsistent-assignment.assignment_sign_type=equal_sign",
+    "inconsistent-assignment-in-variables.assignment_sign_type=none",
+    "text_file.output_path=\"output/robocop.log\"",
+    "return_status.quality_gate.E=0",
+    "return_status.quality_gate.W=0",
+    "return_status.quality_gate.I=-1",
+]
+
+[tool.robocop.format]
+line_length = 200