Repository: nf-core/tools

Issue:
Linting exits with error `Indexerror`
<!--
# nf-core/tools bug report

Hi there!

Thanks for telling us about a problem with the nf-core/tools package.
Please delete this text and anything that's not relevant from the template below:
-->

## Description of the bug
I used nf-core lint on my pipeline which was written using the nf-core template. At first, linting worked as expected and I could fix some of the issues in the pipeline. However, I currently receive a linting error, which seems unhandled. 

At first I thought that it is coming from my computer, but pulling the github repository on another machine creates the same error.

## Steps to reproduce

Steps to reproduce the behaviour:

1. Command line: <!-- [e.g. `nf-core lint ...`] -->
`git clone git@github.com:DSchreyer/circdna.git`
`nf-core lint`

2. See error: <!-- [Please provide your error message] -->
```console
$ 02:33:21 BICR\dschreye@r01-srv01-l-s nf-core-circleseq ±|main ✗|→ nf-core lint

                                          ,--./,-.
          ___     __   __   __   ___     /,-._.--~\
    |\ | |__  __ /  ` /  \ |__) |__         }  {
    | \| |       \__, \__/ |  \ |___     \`-._,-`-,
                                          `._,._,'

    nf-core/tools version 2.1



INFO     Testing pipeline: .                                                                                                                                                                                                   __init__.py:240
Running lint checks ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╸━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 10 of 16 » template_strings
╭───────────────────────────────────────────────────────────────────────────────── Traceback (most recent call last) ──────────────────────────────────────────────────────────────────────────────────╮
│ /home/local/BICR/dschreye/miniconda3/bin/nf-core:10 in <module>                                                                                                                                      │
│                                                                                                                                                                                                      │
│    9 │   sys.argv[0] = re.sub(r'(-script\.pyw|\.exe)?$', '', sys.argv[0])                                                                                                                            │
│ ❱ 10 │   sys.exit(run_nf_core())                                                                                                                                                                     │
│                                                                                                                                                                                                      │
│ /home/local/BICR/dschreye/miniconda3/lib/python3.8/site-packages/nf_core/__main__.py:62 in run_nf_core                                                                                               │
│                                                                                                                                                                                                      │
│    61 │   # Lanch the click cli                                                                                                                                                                      │
│ ❱  62 │   nf_core_cli()                                                                                                                                                                              │
│                                                                                                                                                                                                      │
│ /home/local/BICR/dschreye/miniconda3/lib/python3.8/site-packages/click/core.py:829 in __call__                                                                                                       │
│                                                                                                                                                                                                      │
│    828 │   │   """Alias for :meth:`main`."""                                                                                                                                                         │
│ ❱  829 │   │   return self.main(*args, **kwargs)                                                                                                                                                     │
│                                                                                                                                                                                                      │
│ /home/local/BICR/dschreye/miniconda3/lib/python3.8/site-packages/click/core.py:782 in main                                                                                                           │
│                                                                                                                                                                                                      │
│    781 │   │   │   │   with self.make_context(prog_name, args, **extra) as ctx:                                                                                                                      │
│ ❱  782 │   │   │   │   │   rv = self.invoke(ctx)                                                                                                                                                     │
│    783 │   │   │   │   │   if not standalone_mode:                                                                                                                                                   │
│                                                                                                                                                                                                      │
│ /home/local/BICR/dschreye/miniconda3/lib/python3.8/site-packages/click/core.py:1259 in invoke                                                                                                        │
│                                                                                                                                                                                                      │
│   1258 │   │   │   │   with sub_ctx:                                                                                                                                                                 │
│ ❱ 1259 │   │   │   │   │   return _process_result(sub_ctx.command.invoke(sub_ctx))                                                                                                                   │
│                                                                                                                                                                                                      │
│ /home/local/BICR/dschreye/miniconda3/lib/python3.8/site-packages/click/core.py:1066 in invoke                                                                                                        │
│                                                                                                                                                                                                      │
│   1065 │   │   if self.callback is not None:                                                                                                                                                         │
│ ❱ 1066 │   │   │   return ctx.invoke(self.callback, **ctx.params)                                                                                                                                    │
│                                                                                                                                                                                                      │
│ /home/local/BICR/dschreye/miniconda3/lib/python3.8/site-packages/click/core.py:610 in invoke                                                                                                         │
│                                                                                                                                                                                                      │
│    609 │   │   │   with ctx:                                                                                                                                                                         │
│ ❱  610 │   │   │   │   return callback(*args, **kwargs)                                                                                                                                              │
│                                                                                                                                                                                                      │
│ /home/local/BICR/dschreye/miniconda3/lib/python3.8/site-packages/nf_core/__main__.py:336 in lint                                                                                                     │
│                                                                                                                                                                                                      │
│   335 │   try:                                                                                                                                                                                       │
│ ❱ 336 │   │   lint_obj, module_lint_obj = nf_core.lint.run_linting(                                                                                                                                  │
│   337 │   │   │   dir, release, fix, key, show_passed, fail_ignored, markdown, json                                                                                                                  │
│                                                                                                                                                                                                      │
│ /home/local/BICR/dschreye/miniconda3/lib/python3.8/site-packages/nf_core/lint/__init__.py:99 in run_linting                                                                                          │
│                                                                                                                                                                                                      │
│    98 │   if len(module_lint_obj.all_local_modules) > 0:                                                                                                                                             │
│ ❱  99 │   │   module_lint_obj.lint_modules(module_lint_obj.all_local_modules, local=True)                                                                                                            │
│   100 │   if len(module_lint_obj.all_nfcore_modules) > 0:                                                                                                                                            │
│                                                                                                                                                                                                      │
│ /home/local/BICR/dschreye/miniconda3/lib/python3.8/site-packages/nf_core/modules/lint/__init__.py:300 in lint_modules                                                                                │
│                                                                                                                                                                                                      │
│   299 │   │   │   │   progress_bar.update(lint_progress, advance=1, test_name=mod.module_name)                                                                                                       │
│ ❱ 300 │   │   │   │   self.lint_module(mod, local=local)                                                                                                                                             │
│                                                                                                                                                                                                      │
│ /home/local/BICR/dschreye/miniconda3/lib/python3.8/site-packages/nf_core/modules/lint/__init__.py:322 in lint_module                                                                                 │
│                                                                                                                                                                                                      │
│   321 │   │   if local:                                                                                                                                                                              │
│ ❱ 322 │   │   │   self.main_nf(mod)                                                                                                                                                                  │
│   323 │   │   │   self.passed += [LintResult(mod, *m) for m in mod.passed]                                                                                                                           │
│                                                                                                                                                                                                      │
│ /home/local/BICR/dschreye/miniconda3/lib/python3.8/site-packages/nf_core/modules/lint/main_nf.py:61 in main_nf                                                                                       │
│                                                                                                                                                                                                      │
│    60 │   │   if state == "output" and not _is_empty(module, l):                                                                                                                                     │
│ ❱  61 │   │   │   outputs += _parse_output(module, l)                                                                                                                                                │
│    62 │   │   │   outputs = list(set(outputs))  # remove duplicate 'meta's                                                                                                                           │
│                                                                                                                                                                                                      │
│ /home/local/BICR/dschreye/miniconda3/lib/python3.8/site-packages/nf_core/modules/lint/main_nf.py:244 in _parse_output                                                                                │
│                                                                                                                                                                                                      │
│   243 │   if "emit" in line:                                                                                                                                                                         │
│ ❱ 244 │   │   output.append(line.split("emit:")[1].strip())                                                                                                                                          │
╰──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯
IndexError: list index out of range
```
## Expected behaviour

<!-- A clear and concise description of what you expected to happen. -->
Generally, linting should give me a list of errors or warnings regarding the pipeline setup.

## System

- Hardware: <!-- [e.g. HPC, Desktop, Cloud...] --> HPC
- OS: <!-- [e.g. CentOS Linux, macOS, Linux Mint...] --> Ubuntu 20.4
- Version of nf-core/tools: <!-- [e.g. 1.1, 1.5, 1.8.2...] --> 2.1
- Python version: <!-- [e.g. 3.7, 3.8...] --> 3.8.3

## Nextflow Installation

- Version: <!-- [e.g. 19.10.0] --> 21.04.0

## Additional context

<!-- Add any other context about the problem here. -->



Discussion:
Note to self, attempting to reproduce error with the same state of the repo, guessing at around https://github.com/nf-core/circdna/tree/1e9fe9463486d9fa021c7dfa2d8907257fd5f6ac based on the timestamps of commits / the issue


Resolving patch:
diff --git a/nf_core/modules/lint/main_nf.py b/nf_core/modules/lint/main_nf.py
--- a/nf_core/modules/lint/main_nf.py
+++ b/nf_core/modules/lint/main_nf.py
@@ -276,9 +276,9 @@ def _parse_output(self, line):
     output = []
     if "meta" in line:
         output.append("meta")
-    if not "emit" in line:
+    if not "emit:" in line:
         self.failed.append(("missing_emit", f"Missing emit statement: {line.strip()}", self.main_nf))
-    if "emit" in line:
+    else:
         output.append(line.split("emit:")[1].strip())
 
     return output


Test patch: