Skip to content

Commit 856f5dd

Browse files
authored
feat: allow to manually disable report (#1543)
1 parent a8be5b1 commit 856f5dd

File tree

6 files changed

+75
-10
lines changed

6 files changed

+75
-10
lines changed

docs/linter/reports/print_issues.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,3 +99,24 @@ Format of the **simple** output type can be configured with the global ``--issue
9999
"print_issues.issue_format={source}"
100100
]
101101
```
102+
103+
## Disable print_issues report
104+
105+
To turn off a ``print_issues`` report, set enabled to``False``:
106+
107+
=== ":octicons-command-palette-24: cli"
108+
109+
```bash
110+
robocop check --configure print_issues.enabled=False
111+
```
112+
113+
=== ":material-file-cog-outline: toml"
114+
115+
```toml
116+
[tool.robocop.lint]
117+
configure = [
118+
"print_issues.enabled=False"
119+
]
120+
```
121+
122+
If the goal is to disable all output, use [``--silent``](../../configuration/configuration_reference.md#silent) instead.

docs/linter/reports/reports.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,3 +171,25 @@ use. Use special keyword ``None`` to not run any reports even if configured:
171171
```bash
172172
robocop check --reports sarif,all,None
173173
```
174+
175+
## Disable specific report
176+
177+
To turn off a specific report, even if it’s enabled by configuration or by default (``print_issues``), set enabled to
178+
``False``:
179+
180+
=== ":octicons-command-palette-24: cli"
181+
182+
```bash
183+
robocop check --configure print_issues.enabled=False
184+
```
185+
186+
=== ":material-file-cog-outline: toml"
187+
188+
```toml
189+
[tool.robocop.lint]
190+
configure = [
191+
"print_issues.enabled=False"
192+
]
193+
```
194+
195+
``enabled`` cannot be used to enable a report - use ``reports`` option instead.

docs/releasenotes/changelog.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ Example configuration:
1515
"ignore_file_in_subpath/test2.robot" = ["SPC10"]
1616
```
1717

18+
- Allow manually disabling reports with ``enabled=False``. It can be used to disable default ``print_issues`` report ([issue #1540](https://github.com/MarketSquare/robotframework-robocop/issues/1540))
19+
1820
### Fixes
1921

2022
- Fix piping output (``robocop check > output.txt``) not working on Windows because of code lines converted to emojis ([issue #1539](https://github.com/MarketSquare/robotframework-robocop/issues/1539))

src/robocop/linter/reports/__init__.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ def generate_report(self, **kwargs) -> NoReturn:
3737

3838

3939
class JsonFileReport(Report):
40-
"""Base class for report that generates json-based file."""
40+
"""Base class for a report that generates a json-based file."""
4141

4242
def __init__(self, output_path: str, config: Config) -> None:
4343
self.output_path = output_path
@@ -76,7 +76,7 @@ def load_reports(config: Config) -> dict[str, type[Report]]:
7676
"""
7777
Load all valid reports.
7878
79-
Report is considered valid if it inherits from `Report` class
79+
Report is considered valid if it inherits from the ` Report ` class
8080
and contains both `name` and `description` attributes.
8181
"""
8282
reports = {}
@@ -95,9 +95,9 @@ def load_reports(config: Config) -> dict[str, type[Report]]:
9595

9696
def get_reports(config: Config):
9797
"""
98-
Return dictionary with list of valid, enabled reports (listed in `configured_reports` set of str).
98+
Return the dictionary with a list of valid, enabled reports (listed in `configured_reports` set of str).
9999
100-
If `configured_reports` contains `all` then all default reports are enabled.
100+
If `configured_reports` contains `all`, then all default reports are enabled.
101101
"""
102102
configured_reports = config.linter.reports
103103
configured_reports = [csv_report for report in configured_reports for csv_report in report.split(",")]
@@ -124,8 +124,8 @@ def print_reports(reports: dict[str, Report], only_enabled: bool | None) -> str:
124124
"""
125125
Return description of reports.
126126
127-
The reports list is filtered and only public reports are provided. If the report is enabled in current
128-
configuration it will have (enabled) suffix (and (disabled) if it is disabled).
127+
The report list is filtered and only public reports are provided. If the report is enabled in the current
128+
configuration, it will have (enabled) suffix (and (disabled) if it is disabled).
129129
130130
Args:
131131
reports: Dictionary with loaded reports.
@@ -171,11 +171,11 @@ def load_reports_result_from_cache():
171171

172172
def save_reports_result_to_cache(working_dir: str, report_results: dict) -> None:
173173
"""
174-
Save results from Robocop reports to json file.
174+
Save results from Robocop reports to JSON file.
175175
176-
Result file contains results grouped using working directory.
176+
The result file contains results grouped using a working directory.
177177
That's why we are loading previous results and overwriting only
178-
the results for current working directory.
178+
the results for the current working directory.
179179
"""
180180
cache_dir = get_robocop_cache_directory(ensure_exists=True)
181181
cache_file = cache_dir / ROBOCOP_CACHE_FILE

src/robocop/linter/runner.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,12 @@ def configure_reports(self):
170170
param, value = param_and_value.split("=", maxsplit=1)
171171
except ValueError:
172172
raise exceptions.InvalidConfigurationFormatError(config) from None
173-
if name in self.reports:
173+
if name not in self.reports:
174+
continue
175+
if param == "enabled":
176+
if value.lower() == "false":
177+
del self.reports[name]
178+
else:
174179
self.reports[name].configure(param, value)
175180

176181
def make_reports(self) -> None:

tests/linter/reports/test_reports.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
load_reports_result_from_cache,
1212
save_reports_result_to_cache,
1313
)
14+
from robocop.run import check_files
15+
from tests import working_directory
1416

1517

1618
@pytest.mark.parametrize(
@@ -108,3 +110,16 @@ def test_load_save_with_invalid_file(prepare_file_fn):
108110
save_reports_result_to_cache(root_1, root_1_content)
109111
result = load_reports_result_from_cache()
110112
assert result == expected_result
113+
114+
115+
def test_disabled_report_manually(tmp_path, capsys):
116+
# Arrange
117+
(tmp_path / "test.robot").write_text("*** Settings ***\n\n")
118+
# Act
119+
with working_directory(tmp_path):
120+
check_files(
121+
ignore_file_config=True, return_result=True, reports=["all"], configure=["print_issues.enabled=False"]
122+
)
123+
out, _ = capsys.readouterr()
124+
# Assert
125+
assert "test.robot:1:1 DOC03 Missing documentation in suite" not in out

0 commit comments

Comments
 (0)