Repository: nf-core/tools

Issue:
Lint test - check all params in `nextflow.config` are mentioned in `main.nf`
Sometimes parameters are added in `nextflow.config` and then removed from the pipeline. These dangling parameters confuse matters as they need to be in the schema and clutter things up. However, they are quite difficult to spot when reviewing.

It would be nice to have a simple test that checks that all `params` are found in `main.nf`. May need one or two exceptions, but that's fine.



Discussion:

Resolving patch:
diff --git a/nf_core/lint/__init__.py b/nf_core/lint/__init__.py
--- a/nf_core/lint/__init__.py
+++ b/nf_core/lint/__init__.py
@@ -97,23 +97,24 @@ class PipelineLint(nf_core.utils.Pipeline):
         warned (list): A list of tuples of the form: ``(<warned no>, <reason>)``
     """
 
+    from .actions_awsfulltest import actions_awsfulltest
+    from .actions_awstest import actions_awstest
+    from .actions_ci import actions_ci
+    from .actions_schema_validation import actions_schema_validation
+    from .conda_dockerfile import conda_dockerfile
+    from .conda_env_yaml import conda_env_yaml
     from .files_exist import files_exist
     from .files_unchanged import files_unchanged
+    from .merge_markers import merge_markers
     from .nextflow_config import nextflow_config
-    from .actions_ci import actions_ci
-    from .actions_awstest import actions_awstest
-    from .actions_awsfulltest import actions_awsfulltest
-    from .readme import readme
-    from .version_consistency import version_consistency
-    from .conda_env_yaml import conda_env_yaml
-    from .conda_dockerfile import conda_dockerfile
-    from .pipeline_todos import pipeline_todos
+    from .params_used import params_used
     from .pipeline_name_conventions import pipeline_name_conventions
-    from .template_strings import template_strings
+    from .pipeline_todos import pipeline_todos
+    from .readme import readme
     from .schema_lint import schema_lint
     from .schema_params import schema_params
-    from .actions_schema_validation import actions_schema_validation
-    from .merge_markers import merge_markers
+    from .template_strings import template_strings
+    from .version_consistency import version_consistency
 
     def __init__(self, wf_path, release_mode=False, fix=(), key=(), fail_ignored=False):
         """ Initialise linting object """
@@ -133,6 +134,7 @@ def __init__(self, wf_path, release_mode=False, fix=(), key=(), fail_ignored=Fal
         self.lint_tests = [
             "files_exist",
             "nextflow_config",
+            "params_used",
             "files_unchanged",
             "actions_ci",
             "actions_awstest",
diff --git a/nf_core/lint/merge_markers.py b/nf_core/lint/merge_markers.py
--- a/nf_core/lint/merge_markers.py
+++ b/nf_core/lint/merge_markers.py
@@ -14,7 +14,6 @@ def merge_markers(self):
     This test looks for remaining merge markers in the code, e.g.:
     >>>>>>> or <<<<<<<
 
-
     """
     passed = []
     failed = []
diff --git a/nf_core/lint/params_used.py b/nf_core/lint/params_used.py
new file mode 100644
--- /dev/null
+++ b/nf_core/lint/params_used.py
@@ -0,0 +1,36 @@
+#!/usr/bin/env python
+
+import os
+
+
+def params_used(self):
+    """Check for that params in ``nextflow.config`` are mentioned in ``main.nf``."""
+
+    ignore_params_template = [
+        "params.custom_config_version",
+        "params.custom_config_base",
+        "params.config_profile_name",
+        "params.show_hidden_params",
+        "params.schema_ignore_params",
+    ]
+    ignore_params = self.lint_config.get("params_used", [])
+
+    passed = []
+    warned = []
+    ignored = []
+
+    with open(os.path.join(self.wf_path, "main.nf"), "r") as fh:
+        main_nf = fh.read()
+
+    for cf in self.nf_config.keys():
+        if not cf.startswith("params.") or cf in ignore_params_template:
+            continue
+        if cf in ignore_params:
+            ignored.append("Config variable ignored: {}".format(self._wrap_quotes(cf)))
+            continue
+        if cf in main_nf:
+            passed.append("Config variable found in `main.nf`: {}".format(self._wrap_quotes(cf)))
+        else:
+            warned.append("Config variable not found in `main.nf`: {}".format(self._wrap_quotes(cf)))
+
+    return {"passed": passed, "warned": warned, "ignored": ignored}


Test patch:
diff --git a/docs/api/_src/pipeline_lint_tests/params_used.rst b/docs/api/_src/pipeline_lint_tests/params_used.rst
new file mode 100644
--- /dev/null
+++ b/docs/api/_src/pipeline_lint_tests/params_used.rst
@@ -0,0 +1,4 @@
+params_used
+===========
+
+.. automethod:: nf_core.lint.PipelineLint.params_used