Repository: MarketSquare/robotframework-robocop
Pull request #1281 (2025-03-04 07:43:50)

Rename --ext-rules to --custom-rules
It aligns with --custom-formatters option name.


Patch:
diff --git a/README.md b/README.md
index c4f8b40..ac32107 100644
--- a/README.md
+++ b/README.md
@@ -247,12 +247,10 @@ FAQ
 <details>
   <summary>Can I define custom rules?</summary>
 
-  # TODO refactor to update with new option names etc
-  **Yes**, you can define and include custom rules using `-rules / --ext-rules` command line option
-  by providing a path to a file containing your rule(s). The option accepts comma-separated list
-  of paths to files or directories, e.g.
+  **Yes**, you can define and include custom rules using `--custom-rules` command line option
+  by providing a path to a file containing your rule(s):
   ```
-  robocop -rules my/own/rule.py --ext-rules rules.py,external_rules.py
+  robocop --custom-rules my/own/rule.py --custom-rules rules.py,external_rules.py
   ```
 
   If you feel that your rule is very helpful and should be included in Robocop permanently,
diff --git a/docs/releasenotes/6.0.0dev1.rst b/docs/releasenotes/6.0.0dev1.rst
index ed5bc4f..94958e1 100644
--- a/docs/releasenotes/6.0.0dev1.rst
+++ b/docs/releasenotes/6.0.0dev1.rst
@@ -106,7 +106,7 @@ Formatting options from Robotidy:
 - ``-el/--endline`` became ``--end-line``
 
 
-``-rules / --ext-rules`` can be now only used under ``--ext-rules`` name.
+``-rules / --ext-rules`` can be now only used under ``--custom-rules`` name.
 
 ``--load-transformers / --custom-transformers`` is now renamed to ``--custom-formatters``.
 
diff --git a/docs/source/rules/external_rules.rst b/docs/source/rules/external_rules.rst
index 72a1aa3..c8ce61c 100644
--- a/docs/source/rules/external_rules.rst
+++ b/docs/source/rules/external_rules.rst
@@ -1,9 +1,9 @@
 .. _external-rules:
 
-External rules
-========================
+Custom rules
+=============
 
-You can include your own custom rules with ``--ext-rules`` arguments.
+You can include your own custom rules with ``--custom-rules`` arguments.
 It accepts comma-separated list of paths to files, directories or name of the Python module. Example:
 
 .. tab-set::
@@ -12,14 +12,14 @@ It accepts comma-separated list of paths to files, directories or name of the Py
 
         .. code:: shell
 
-            robocop check ext-rules my/own/rule.py --ext-rules external_rules.py
+            robocop check --custom-rules my/own/rule.py --custom-rules custom_rules.py
 
     .. tab-item:: Configuration file
 
         .. code:: toml
 
             [robocop.lint]
-            ext_rules = [
+            custom_rules = [
                 "my/own/rule.py",
                 "external_rules.py"
             ]
@@ -175,14 +175,14 @@ Configurable parameter can be referred by its ``name`` in command line options:
 
         .. code:: shell
 
-            robocop check --ext-rules my/own/rule.py --configure example-in-name.param_name=AnotherExample
+            robocop check --custom-rules my/own/rule.py --configure example-in-name.param_name=AnotherExample
 
     .. tab-item:: Configuration file
 
         .. code:: toml
 
             [robocop.lint]
-            ext_rules = [
+            custom_rules = [
                 "my/own/rule.py"
             ]
             configure = [
diff --git a/src/robocop/cli.py b/src/robocop/cli.py
index fb0b4ce..c574ccd 100644
--- a/src/robocop/cli.py
+++ b/src/robocop/cli.py
@@ -168,9 +168,9 @@ def check_files(
         str, typer.Option("--issue-format", show_default=config.DEFAULT_ISSUE_FORMAT, rich_help_panel="Other")
     ] = None,
     language: language_option = None,
-    ext_rules: Annotated[
+    custom_rules: Annotated[
         list[str],
-        typer.Option("--ext-rules", help="Load custom rules", show_default=False, rich_help_panel="Selecting rules"),
+        typer.Option("--custom-rules", help="Load custom rules", show_default=False, rich_help_panel="Selecting rules"),
     ] = None,
     ignore_git_dir: Annotated[
         bool,
@@ -213,7 +213,7 @@ def check_files(
         ignore=ignore,
         issue_format=issue_format,
         threshold=threshold,
-        ext_rules=ext_rules,
+        custom_rules=custom_rules,
         reports=reports,
         persistent=persistent,
         compare=compare,
diff --git a/src/robocop/config.py b/src/robocop/config.py
index 8a145ff..14021ac 100644
--- a/src/robocop/config.py
+++ b/src/robocop/config.py
@@ -155,7 +155,7 @@ class LinterConfig:
     ignore: list[str] | None = field(default_factory=list)
     issue_format: str | None = DEFAULT_ISSUE_FORMAT
     threshold: RuleSeverity | None = RuleSeverity.INFO
-    ext_rules: list[str] | None = field(default_factory=list)
+    custom_rules: list[str] | None = field(default_factory=list)
     include_rules: set[str] | None = field(default_factory=set, compare=False)
     exclude_rules: set[str] | None = field(default_factory=set, compare=False)
     include_rules_patterns: set[re.Pattern] | None = field(default_factory=set, compare=False)
diff --git a/src/robocop/linter/rules/__init__.py b/src/robocop/linter/rules/__init__.py
index 3c691b6..e7289c1 100644
--- a/src/robocop/linter/rules/__init__.py
+++ b/src/robocop/linter/rules/__init__.py
@@ -787,7 +787,7 @@ class RobocopImporter:
 
 
 def init(config: LinterConfig) -> None:
-    robocop_importer = RobocopImporter(external_rules_paths=config.ext_rules)
+    robocop_importer = RobocopImporter(external_rules_paths=config.custom_rules)
     for checker in robocop_importer.get_initialized_checkers():
         config.register_checker(checker)
     # linter.rules.update(robocop_importer.deprecated_rules)
diff --git a/src/robocop/migrate_config.py b/src/robocop/migrate_config.py
index dbd62f0..84d1e2e 100644
--- a/src/robocop/migrate_config.py
+++ b/src/robocop/migrate_config.py
@@ -274,8 +274,8 @@ def migrate_deprecated_configs(config_path: Path) -> None:
             "persistent": "persistent",
             "language": "language",
             "ignore_git_dir": "ignore_git_dir",
-            "ext_rules": "ext_rules",
-            "rules": "ext_rules",
+            "ext_rules": "custom_rules",
+            "rules": "custom_rules",
             "configure": ("configure", convert_robocop_configure),
         },
     )


Test patch:
diff --git a/tests/config/test_config_manager.py b/tests/config/test_config_manager.py
index 809a276..54b662c 100644
--- a/tests/config/test_config_manager.py
+++ b/tests/config/test_config_manager.py
@@ -50,7 +50,7 @@ def overwrite_config() -> Config:
         ignore=None,
         issue_format=None,
         threshold=None,
-        ext_rules=None,
+        custom_rules=None,
         reports=None,
         persistent=None,
         compare=None,
@@ -112,7 +112,7 @@ class TestConfigFinder:
         config.linter.reports = ["all", "sarif"]
         config.linter.issue_format = "{source_abs}:{line}:{col} [{severity}] {rule_id} {desc} ({name})"
         config.language = ["eng", "pl"]
-        config.linter.ext_rules = ["CustomRules.py"]
+        config.linter.custom_rules = ["CustomRules.py"]
         config.linter.persistent = True
         config.linter.compare = True
         config.linter.exit_zero = True
diff --git a/tests/config/test_data/config_with_all_options/pyproject.toml b/tests/config/test_data/config_with_all_options/pyproject.toml
index 5e48b2b..2b0dc1c 100644
--- a/tests/config/test_data/config_with_all_options/pyproject.toml
+++ b/tests/config/test_data/config_with_all_options/pyproject.toml
@@ -19,7 +19,7 @@ ignore = [
 threshold = "W"
 reports = ["all", "sarif"]
 issue_format = "{source_abs}:{line}:{col} [{severity}] {rule_id} {desc} ({name})"
-ext_rules = [
+custom_rules = [
     "CustomRules.py"
 ]
 persistent = true
diff --git a/tests/linter/cli/test_list_rules.py b/tests/linter/cli/test_list_rules.py
index 7a67fb2..113d4d2 100644
--- a/tests/linter/cli/test_list_rules.py
+++ b/tests/linter/cli/test_list_rules.py
@@ -7,7 +7,7 @@ from robocop.cli import list_rules
 from robocop.linter.rules import Rule, RuleFilter, RuleSeverity, VisitorChecker
 from robocop.linter.utils.misc import ROBOT_VERSION
 
-TEST_DATA = Path(__file__).parent.parent / "test_data" / "ext_rules"
+TEST_DATA = Path(__file__).parent.parent / "test_data" / "custom_rules"
 
 
 # @pytest.fixture
@@ -400,8 +400,8 @@ class TestListingRules:
     #     )
     #     assert all(msg in out for msg in exp_msg)
 
-    # def test_list_ext_rules_disabled_by_default(self, empty_linter, capsys):  # TODO
-    #     empty_linter.config.ext_rules = {
+    # def test_list_custom_rules_disabled_by_default(self, empty_linter, capsys):  # TODO
+    #     empty_linter.config.custom_rules = {
     #         str(TEST_DATA / "disabled_by_default" / "external_rule.py"),
     #         str(TEST_DATA / "disabled_by_default" / "external_rule2.py"),
     #     }
@@ -415,8 +415,8 @@ class TestListingRules:
     #     )
     #     assert all(msg in out for msg in exp_msg)
 
-    # def test_list_ext_rules_disabled_by_default_enable(self, empty_linter, capsys):  # TODO
-    #     empty_linter.config.ext_rules = {
+    # def test_list_custom_rules_disabled_by_default_enable(self, empty_linter, capsys):  # TODO
+    #     empty_linter.config.custom_rules = {
     #         str(TEST_DATA / "disabled_by_default" / "external_rule.py"),
     #         str(TEST_DATA / "disabled_by_default" / "external_rule2.py"),
     #     }
diff --git a/tests/linter/rules/custom_tests/project_checker/test_rule.py b/tests/linter/rules/custom_tests/project_checker/test_rule.py
index fdd2c15..a687513 100644
--- a/tests/linter/rules/custom_tests/project_checker/test_rule.py
+++ b/tests/linter/rules/custom_tests/project_checker/test_rule.py
@@ -14,5 +14,5 @@ class TestRuleAcceptance(RuleAcceptance):
             src_files=["."],
             expected_file="expected_output.txt",
             include=["project-checker", "test-total-count"],
-            ext_rules=[f"{CUR_DIR}/external_project_checker"],
+            custom_rules=[f"{CUR_DIR}/external_project_checker"],
         )
diff --git a/tests/linter/test_data/custom_rules/config_pyproject/pyproject.toml b/tests/linter/test_data/custom_rules/config_pyproject/pyproject.toml
new file mode 100644
index 0000000..ca5a286
--- /dev/null
+++ b/tests/linter/test_data/custom_rules/config_pyproject/pyproject.toml
@@ -0,0 +1,2 @@
+[tool.robocop.lint]
+custom_rules = ["RobocopRules"]
\ No newline at end of file
diff --git a/tests/linter/test_data/ext_rules/disabled_by_default/external_rule.py b/tests/linter/test_data/custom_rules/custom_rule/external_rule.py
similarity index 100%
rename from tests/linter/test_data/ext_rules/disabled_by_default/external_rule.py
rename to tests/linter/test_data/custom_rules/custom_rule/external_rule.py
diff --git a/tests/linter/test_data/ext_rules/ext_rule/external_rule2.py b/tests/linter/test_data/custom_rules/custom_rule/external_rule2.py
similarity index 100%
rename from tests/linter/test_data/ext_rules/ext_rule/external_rule2.py
rename to tests/linter/test_data/custom_rules/custom_rule/external_rule2.py
diff --git a/tests/linter/test_data/ext_rules/ext_rule/other_file.template b/tests/linter/test_data/custom_rules/custom_rule/other_file.template
similarity index 100%
rename from tests/linter/test_data/ext_rules/ext_rule/other_file.template
rename to tests/linter/test_data/custom_rules/custom_rule/other_file.template
diff --git a/tests/linter/test_data/ext_rules/ext_rule_duplicate/external_rule_dup.py b/tests/linter/test_data/custom_rules/custom_rule_duplicate/external_rule_dup.py
similarity index 100%
rename from tests/linter/test_data/ext_rules/ext_rule_duplicate/external_rule_dup.py
rename to tests/linter/test_data/custom_rules/custom_rule_duplicate/external_rule_dup.py
diff --git a/tests/linter/test_data/ext_rules/ext_rule_invalid_file/invalid_file.py b/tests/linter/test_data/custom_rules/custom_rule_invalid_file/invalid_file.py
similarity index 100%
rename from tests/linter/test_data/ext_rules/ext_rule_invalid_file/invalid_file.py
rename to tests/linter/test_data/custom_rules/custom_rule_invalid_file/invalid_file.py
diff --git a/tests/linter/test_data/ext_rules/ext_rule_invalid_reports/external_rule.py b/tests/linter/test_data/custom_rules/custom_rule_invalid_reports/external_rule.py
similarity index 100%
rename from tests/linter/test_data/ext_rules/ext_rule_invalid_reports/external_rule.py
rename to tests/linter/test_data/custom_rules/custom_rule_invalid_reports/external_rule.py
diff --git a/tests/linter/test_data/ext_rules/ext_rule_missing_register/external_rule_missing_register.py b/tests/linter/test_data/custom_rules/custom_rule_missing_register/external_rule_missing_register.py
similarity index 100%
rename from tests/linter/test_data/ext_rules/ext_rule_missing_register/external_rule_missing_register.py
rename to tests/linter/test_data/custom_rules/custom_rule_missing_register/external_rule_missing_register.py
diff --git a/tests/linter/test_data/ext_rules/ext_rule_module/RobocopRules/__init__.py b/tests/linter/test_data/custom_rules/custom_rule_module/RobocopRules/__init__.py
similarity index 100%
rename from tests/linter/test_data/ext_rules/ext_rule_module/RobocopRules/__init__.py
rename to tests/linter/test_data/custom_rules/custom_rule_module/RobocopRules/__init__.py
diff --git a/tests/linter/test_data/ext_rules/ext_rule_module/RobocopRules/some_rules.py b/tests/linter/test_data/custom_rules/custom_rule_module/RobocopRules/some_rules.py
similarity index 100%
rename from tests/linter/test_data/ext_rules/ext_rule_module/RobocopRules/some_rules.py
rename to tests/linter/test_data/custom_rules/custom_rule_module/RobocopRules/some_rules.py
diff --git a/tests/linter/test_data/ext_rules/ext_rule_module/RobocopRules/submodule/__init__.py b/tests/linter/test_data/custom_rules/custom_rule_module/RobocopRules/submodule/__init__.py
similarity index 100%
rename from tests/linter/test_data/ext_rules/ext_rule_module/RobocopRules/submodule/__init__.py
rename to tests/linter/test_data/custom_rules/custom_rule_module/RobocopRules/submodule/__init__.py
diff --git a/tests/linter/test_data/ext_rules/ext_rule_module/RobocopRules/submodule/some_rules.py b/tests/linter/test_data/custom_rules/custom_rule_module/RobocopRules/submodule/some_rules.py
similarity index 100%
rename from tests/linter/test_data/ext_rules/ext_rule_module/RobocopRules/submodule/some_rules.py
rename to tests/linter/test_data/custom_rules/custom_rule_module/RobocopRules/submodule/some_rules.py
diff --git a/tests/linter/test_data/ext_rules/ext_rule_module_import_robocop/RobocopCustomRules/__init__.py b/tests/linter/test_data/custom_rules/custom_rule_module_import_robocop/RobocopCustomRules/__init__.py
similarity index 100%
rename from tests/linter/test_data/ext_rules/ext_rule_module_import_robocop/RobocopCustomRules/__init__.py
rename to tests/linter/test_data/custom_rules/custom_rule_module_import_robocop/RobocopCustomRules/__init__.py
diff --git a/tests/linter/test_data/ext_rules/ext_rule_module_simple_import/RobocopRules/__init__.py b/tests/linter/test_data/custom_rules/custom_rule_module_simple_import/RobocopRules/__init__.py
similarity index 100%
rename from tests/linter/test_data/ext_rules/ext_rule_module_simple_import/RobocopRules/__init__.py
rename to tests/linter/test_data/custom_rules/custom_rule_module_simple_import/RobocopRules/__init__.py
diff --git a/tests/linter/test_data/ext_rules/ext_rule_module_simple_import/RobocopRules/single_rule.py b/tests/linter/test_data/custom_rules/custom_rule_module_simple_import/RobocopRules/single_rule.py
similarity index 100%
rename from tests/linter/test_data/ext_rules/ext_rule_module_simple_import/RobocopRules/single_rule.py
rename to tests/linter/test_data/custom_rules/custom_rule_module_simple_import/RobocopRules/single_rule.py
diff --git a/tests/linter/test_data/ext_rules/ext_rule_module_simple_import/RobocopRules/submodule/__init__.py b/tests/linter/test_data/custom_rules/custom_rule_module_simple_import/RobocopRules/submodule/__init__.py
similarity index 100%
rename from tests/linter/test_data/ext_rules/ext_rule_module_simple_import/RobocopRules/submodule/__init__.py
rename to tests/linter/test_data/custom_rules/custom_rule_module_simple_import/RobocopRules/submodule/__init__.py
diff --git a/tests/linter/test_data/ext_rules/ext_rule_module_simple_import/RobocopRules/submodule/some_rules.py b/tests/linter/test_data/custom_rules/custom_rule_module_simple_import/RobocopRules/submodule/some_rules.py
similarity index 100%
rename from tests/linter/test_data/ext_rules/ext_rule_module_simple_import/RobocopRules/submodule/some_rules.py
rename to tests/linter/test_data/custom_rules/custom_rule_module_simple_import/RobocopRules/submodule/some_rules.py
diff --git a/tests/linter/test_data/ext_rules/deprecated/deprecated_rules.py b/tests/linter/test_data/custom_rules/deprecated/deprecated_rules.py
similarity index 100%
rename from tests/linter/test_data/ext_rules/deprecated/deprecated_rules.py
rename to tests/linter/test_data/custom_rules/deprecated/deprecated_rules.py
diff --git a/tests/linter/test_data/ext_rules/ext_rule/external_rule.py b/tests/linter/test_data/custom_rules/disabled_by_default/external_rule.py
similarity index 100%
rename from tests/linter/test_data/ext_rules/ext_rule/external_rule.py
rename to tests/linter/test_data/custom_rules/disabled_by_default/external_rule.py
diff --git a/tests/linter/test_data/ext_rules/disabled_by_default/external_rule2.py b/tests/linter/test_data/custom_rules/disabled_by_default/external_rule2.py
similarity index 100%
rename from tests/linter/test_data/ext_rules/disabled_by_default/external_rule2.py
rename to tests/linter/test_data/custom_rules/disabled_by_default/external_rule2.py
diff --git a/tests/linter/test_data/ext_rules/version_matching/rules_with_version_limits.py b/tests/linter/test_data/custom_rules/version_matching/rules_with_version_limits.py
similarity index 100%
rename from tests/linter/test_data/ext_rules/version_matching/rules_with_version_limits.py
rename to tests/linter/test_data/custom_rules/version_matching/rules_with_version_limits.py
diff --git a/tests/linter/test_data/ext_rules/config_pyproject/pyproject.toml b/tests/linter/test_data/ext_rules/config_pyproject/pyproject.toml
deleted file mode 100644
index b2a27a0..0000000
--- a/tests/linter/test_data/ext_rules/config_pyproject/pyproject.toml
+++ /dev/null
@@ -1,2 +0,0 @@
-[tool.robocop]
-ext-rules = ["RobocopRules"]
\ No newline at end of file
diff --git a/tests/linter/test_data/ext_rules/config_robocop/.robocop b/tests/linter/test_data/ext_rules/config_robocop/.robocop
deleted file mode 100644
index 92724c1..0000000
--- a/tests/linter/test_data/ext_rules/config_robocop/.robocop
+++ /dev/null
@@ -1,1 +0,0 @@
---ext-rules RobocopRules
\ No newline at end of file
diff --git a/tests/migrate_config/test_data/common_migrated.toml b/tests/migrate_config/test_data/common_migrated.toml
index b3ef957..6148b16 100644
--- a/tests/migrate_config/test_data/common_migrated.toml
+++ b/tests/migrate_config/test_data/common_migrated.toml
@@ -31,7 +31,7 @@ language = [
     "pt",
     "fi",
 ]
-ext_rules = [
+custom_rules = [
     "path_to_external\\dir",
 ]
 configure = [