Repository: MarketSquare/robotframework-robocop (language: python)

Issue:
Two rules are reporting on Run Keyword Unless
We should consider limiting it to just one rule:

```
keywords.robot:71:5 [W] 0319 'Run Keyword Unless' is deprecated since Robot Framework version 5.*, use 'IF' instead (deprecated-statement)
keywords.robot:71:5 [I] 0908 'Run Keyword Unless' can be replaced with IF block since Robot Framework 4.0 (if-can-be-used)
```

Not sure currently if it's bug.


Discussion / hints:
The main difference is that we report deprecated-statement since Robotidy 2.0 but we filter out messages depending on configuration:

```
   deprecated_keywords = {
        "runkeywordunless": (5, "IF"),
        "runkeywordif": (5, "IF"),
        (...)
```

``if-can-be-used`` reports since 4.0 and ``deprecated-statement`` since 5.0. I guess the main difference is that Run Keyword If etc were not deprecated before, it was just suggestion to replace the syntax. So we can:

 - between 4 and 5 RF version report only ``if-can-be-used`` (Info)
- starting from 5 RF version report only ``deprecated-statement`` (Warning)
> So we can:
> 
> * between 4 and 5 RF version report only `if-can-be-used` (Info)
> * starting from 5 RF version report only `deprecated-statement` (Warning)

Agreed, seems like a good approach.

Fix patch:
diff --git a/docs/releasenotes/unreleased/fixes.9.rst b/docs/releasenotes/unreleased/fixes.9.rst
new file mode 100644
index 000000000..0edec4dd4
--- /dev/null
+++ b/docs/releasenotes/unreleased/fixes.9.rst
@@ -0,0 +1,9 @@
+if-can-be-used and deprecated-statement double reporting on Run Keyword Unless (#945)
+-------------------------------------------------------------------------------------
+
+I0908 ``if-can-be-used`` was introduced in Robot Framework 4.0 to suggest replacing ``Run Keyword If`` and
+``Run Keyword Unless`` keywords by ``IF``. Since Robot Framework 5.0 W0319 ``deprecated-statement`` started to warn
+on the use of those keywords. Because of that there were 2 issues reported starting from Robot Framework 5.0.
+
+``if-can-be-used`` was updated to only report for Robot Framework 4.0 code. Starting from RF version 5.0 only
+``deprecated-statement`` will be reported.
diff --git a/robocop/checkers/misc.py b/robocop/checkers/misc.py
index 57e9ec6be..2e8b56f4e 100644
--- a/robocop/checkers/misc.py
+++ b/robocop/checkers/misc.py
@@ -98,7 +98,7 @@
         name="if-can-be-used",
         msg="'{{ run_keyword }}' can be replaced with IF block since Robot Framework 4.0",
         severity=RuleSeverity.INFO,
-        version=">=4",
+        version="==4.*",
         docs="""
         Starting from Robot Framework 4.0 ``Run Keyword If`` and ``Run Keyword Unless`` can be replaced by IF block.
         """,


Test patch:
diff --git a/tests/atest/rules/misc/if_can_be_used/test_rule.py b/tests/atest/rules/misc/if_can_be_used/test_rule.py
index df3c44f3b..6ebc393c5 100644
--- a/tests/atest/rules/misc/if_can_be_used/test_rule.py
+++ b/tests/atest/rules/misc/if_can_be_used/test_rule.py
@@ -3,4 +3,4 @@
 
 class TestRuleAcceptance(RuleAcceptance):
     def test_rule(self):
-        self.check_rule(src_files=["test.robot"], expected_file="expected_output.txt", target_version=">=4")
+        self.check_rule(src_files=["test.robot"], expected_file="expected_output.txt", target_version="==4")