Repository: MarketSquare/robotframework-robocop
Pull request #1364 (2025-03-28 11:16:09)

Fix rule severity parameter not configurable
#1362


Patch:
diff --git a/docs/releasenotes/6.0.1.rst b/docs/releasenotes/6.0.1.rst
index 4238b49..290fbaf 100644
--- a/docs/releasenotes/6.0.1.rst
+++ b/docs/releasenotes/6.0.1.rst
@@ -28,6 +28,15 @@ configure from cli overwriting configuration file setting (#1360)
 will result in Robocop using both configurations for ``line-too-long`` and ``too-long-test-case`` rules instead of only
 using value from cli.
 
+severity of the rule is not configurable (#1362)
+------------------------------------------------
+
+Rule severity can be now configured::
+
+    robocop check --configure line-too-long.severity=e
+
+Because of the attribute name clash for ``severity``, configuration for it was ignored before.
+
 Acknowledgements
 ================
 
diff --git a/src/robocop/linter/rules/__init__.py b/src/robocop/linter/rules/__init__.py
index 00f08e4..4801775 100644
--- a/src/robocop/linter/rules/__init__.py
+++ b/src/robocop/linter/rules/__init__.py
@@ -482,6 +482,9 @@ class Rule:
                 f"    {configurables_text}"
             )
         self.config[param].value = value
+        # If you want to use the same parameter name as Rule attribute (for example severity), you need to skip getattr
+        if param == "severity":
+            self.severity = self.config[param].value
 
     def available_configurables(self, include_severity: bool = True):
         params = []


Test patch:
diff --git a/tests/linter/rules/misc/unreachable_code/expected_output_error.txt b/tests/linter/rules/misc/unreachable_code/expected_output_error.txt
new file mode 100644
index 0000000..4c88ce0
--- /dev/null
+++ b/tests/linter/rules/misc/unreachable_code/expected_output_error.txt
@@ -0,0 +1,14 @@
+test.robot:14:9 [E] MISC10 Unreachable code after RETURN statement
+test.robot:62:9 [E] MISC10 Unreachable code after RETURN statement
+test.robot:66:9 [E] MISC10 Unreachable code after RETURN statement
+test.robot:70:9 [E] MISC10 Unreachable code after RETURN statement
+test.robot:74:9 [E] MISC10 Unreachable code after RETURN statement
+test.robot:77:9 [E] MISC10 Unreachable code after RETURN statement
+test.robot:80:9 [E] MISC10 Unreachable code after RETURN statement
+test.robot:83:5 [E] MISC10 Unreachable code after RETURN statement
+test.robot:86:9 [E] MISC10 Unreachable code after RETURN statement
+test.robot:106:13 [E] MISC10 Unreachable code after CONTINUE statement
+test.robot:109:9 [E] MISC10 Unreachable code after BREAK statement
+test.robot:112:5 [E] MISC10 Unreachable code after RETURN statement
+test.robot:118:13 [E] MISC10 Unreachable code after BREAK statement
+test.robot:123:5 [E] MISC10 Unreachable code after RETURN statement
\ No newline at end of file
diff --git a/tests/linter/rules/misc/unreachable_code/test_rule.py b/tests/linter/rules/misc/unreachable_code/test_rule.py
index da59494..5e92fc5 100644
--- a/tests/linter/rules/misc/unreachable_code/test_rule.py
+++ b/tests/linter/rules/misc/unreachable_code/test_rule.py
@@ -16,3 +16,11 @@ class TestRuleAcceptance(RuleAcceptance):
             output_format="extended",
             test_on_version=">=5.0",
         )
+
+    def test_with_error_severity(self):
+        self.check_rule(
+            src_files=["test.robot"],
+            expected_file="expected_output_error.txt",
+            configure=["unreachable-code.severity=e"],
+            test_on_version=">=5.0",
+        )