Repository: MarketSquare/robotframework-robocop
Pull request #1265 (2025-02-28 09:56:58)

Add tests for extended view for documentation rules


Patch:
diff --git a/src/robocop/linter/rules/documentation.py b/src/robocop/linter/rules/documentation.py
index e2cc5c3..a52c097 100644
--- a/src/robocop/linter/rules/documentation.py
+++ b/src/robocop/linter/rules/documentation.py
@@ -90,6 +90,7 @@ class MissingDocTestSuiteRule(Rule):
     rule_id = "DOC03"
     message = "Missing documentation in suite"
     severity = RuleSeverity.WARNING
+    file_wide_rule = True
     added_in_version = "1.0.0"
 
 
@@ -108,6 +109,7 @@ class MissingDocResourceFileRule(Rule):
     rule_id = "DOC04"
     message = "Missing documentation in resource file"
     severity = RuleSeverity.WARNING
+    file_wide_rule = True
     added_in_version = "2.8.0"
 
 
@@ -139,9 +141,9 @@ class MissingDocumentationChecker(VisitorChecker):
     def visit_SettingSection(self, node: SettingSection) -> None:  # noqa: N802
         self.settings_section_exists = True
         if self.is_resource:
-            self.check_if_docs_are_present(node, self.missing_doc_resource_file, extend_disablers=False)
+            self.check_if_suite_docs_are_present(node, self.missing_doc_resource_file)
         else:
-            self.check_if_docs_are_present(node, self.missing_doc_test_suite, extend_disablers=False)
+            self.check_if_suite_docs_are_present(node, self.missing_doc_test_suite)
 
     def visit_File(self, node: File) -> None:  # noqa: N802
         source = node.source if node.source else self.source
@@ -173,3 +175,9 @@ class MissingDocumentationChecker(VisitorChecker):
                 )
             else:
                 self.report(rule, node=node, end_col=node.end_col_offset, extended_disablers=extended_disablers)
+
+    def check_if_suite_docs_are_present(self, node: SettingSection, rule: Rule):
+        for statement in node.body:
+            if isinstance(statement, Documentation):
+                return
+        self.report(rule, node=node)


Test patch:
diff --git a/tests/linter/rules/documentation/missing_doc_keyword/expected_extended.txt b/tests/linter/rules/documentation/missing_doc_keyword/expected_extended.txt
new file mode 100644
index 0000000..78650c9
--- /dev/null
+++ b/tests/linter/rules/documentation/missing_doc_keyword/expected_extended.txt
@@ -0,0 +1,10 @@
+test.robot:15:1 DOC01 Missing documentation in 'Keyword' keyword
+    |
+ 13 |
+ 14 | *** Keywords ***
+ 15 | Keyword
+    | ^^^^^^^ DOC01
+ 16 |     No Operation
+ 17 |     Pass
+    |
+
diff --git a/tests/linter/rules/documentation/missing_doc_keyword/test_rule.py b/tests/linter/rules/documentation/missing_doc_keyword/test_rule.py
index cba6753..5cfbbdd 100644
--- a/tests/linter/rules/documentation/missing_doc_keyword/test_rule.py
+++ b/tests/linter/rules/documentation/missing_doc_keyword/test_rule.py
@@ -4,3 +4,6 @@ from tests.linter.utils import RuleAcceptance
 class TestRuleAcceptance(RuleAcceptance):
     def test_rule(self):
         self.check_rule(src_files=["test.robot"], expected_file="expected_output.txt")
+
+    def test_extended(self):
+        self.check_rule(expected_file="expected_extended.txt", output_format="extended")
diff --git a/tests/linter/rules/documentation/missing_doc_resource_file/expected_extended.txt b/tests/linter/rules/documentation/missing_doc_resource_file/expected_extended.txt
new file mode 100644
index 0000000..74b0b28
--- /dev/null
+++ b/tests/linter/rules/documentation/missing_doc_resource_file/expected_extended.txt
@@ -0,0 +1,2 @@
+test.resource:1:1 DOC04 Missing documentation in resource file
+with_settings.resource:1:1 DOC04 Missing documentation in resource file
\ No newline at end of file
diff --git a/tests/linter/rules/documentation/missing_doc_resource_file/test_rule.py b/tests/linter/rules/documentation/missing_doc_resource_file/test_rule.py
index 4489da8..ae4bc5c 100644
--- a/tests/linter/rules/documentation/missing_doc_resource_file/test_rule.py
+++ b/tests/linter/rules/documentation/missing_doc_resource_file/test_rule.py
@@ -7,3 +7,6 @@ class TestRuleAcceptance(RuleAcceptance):
             src_files=["test.robot", "test.resource", "documentation.resource", "with_settings.resource"],
             expected_file="expected_output.txt",
         )
+
+    def test_extended(self):
+        self.check_rule(expected_file="expected_extended.txt", output_format="extended")
diff --git a/tests/linter/rules/documentation/missing_doc_suite/expected_extended.txt b/tests/linter/rules/documentation/missing_doc_suite/expected_extended.txt
new file mode 100644
index 0000000..e901a5a
--- /dev/null
+++ b/tests/linter/rules/documentation/missing_doc_suite/expected_extended.txt
@@ -0,0 +1,1 @@
+test.robot:1:1 DOC03 Missing documentation in suite
\ No newline at end of file
diff --git a/tests/linter/rules/documentation/missing_doc_suite/test_rule.py b/tests/linter/rules/documentation/missing_doc_suite/test_rule.py
index 484d493..0b2cc3a 100644
--- a/tests/linter/rules/documentation/missing_doc_suite/test_rule.py
+++ b/tests/linter/rules/documentation/missing_doc_suite/test_rule.py
@@ -4,3 +4,6 @@ from tests.linter.utils import RuleAcceptance
 class TestRuleAcceptance(RuleAcceptance):
     def test_rule(self):
         self.check_rule(src_files=["test.robot", "test.resource"], expected_file="expected_output.txt")
+
+    def test_extended(self):
+        self.check_rule(expected_file="expected_extended.txt", output_format="extended")
diff --git a/tests/linter/rules/documentation/missing_doc_test_case/expected_extended.txt b/tests/linter/rules/documentation/missing_doc_test_case/expected_extended.txt
new file mode 100644
index 0000000..ea1635d
--- /dev/null
+++ b/tests/linter/rules/documentation/missing_doc_test_case/expected_extended.txt
@@ -0,0 +1,10 @@
+test.robot:6:1 DOC02 Missing documentation in 'Test' test case
+   |
+ 4 |
+ 5 | *** Test Cases ***
+ 6 | Test
+   | ^^^^ DOC02
+ 7 |     [Tags]  sometag
+ 8 |     Pass
+   |
+
diff --git a/tests/linter/rules/documentation/missing_doc_test_case/test_rule.py b/tests/linter/rules/documentation/missing_doc_test_case/test_rule.py
index aa69e2b..a4e8ab0 100644
--- a/tests/linter/rules/documentation/missing_doc_test_case/test_rule.py
+++ b/tests/linter/rules/documentation/missing_doc_test_case/test_rule.py
@@ -5,6 +5,9 @@ class TestRuleAcceptance(RuleAcceptance):
     def test_rule(self):
         self.check_rule(src_files=["test.robot"], expected_file="expected_output.txt")
 
+    def test_extended(self):
+        self.check_rule(expected_file="expected_extended.txt", output_format="extended")
+
     def test_templated(self):
         self.check_rule(
             configure=["missing-doc-test-case.ignore_templated=False"],