Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

template variables misidentified as unused #57

Open
d3v-null opened this issue Nov 7, 2024 · 0 comments
Open

template variables misidentified as unused #57

d3v-null opened this issue Nov 7, 2024 · 0 comments

Comments

@d3v-null
Copy link

d3v-null commented Nov 7, 2024

Hey there,
Huge thanks to you all for getting the language server working properly in the VSCode extension.

One recurring issue is that the linter thinks a process variable is not used, when it is used in a template.

I like to make my python template scripts reusable, so I use a pattern of injecting arguments into template like this as command line arguments, e.g. templates/foo.py

#!/usr/bin/env python
from argparse import ArgumentParser
import shlex

def get_parser() -> ArgumentParser:
    ...

argv = sys.argv
if len(sys.argv) == 1:
    # is being called directly from nextflow, use argv from parsing argstr
    argv = shlex.split("${argstr}")

args = get_parser().parse_args(argv)
...
process foo {
    input: tuple val(arg1), val(arg2)
    script:
    argstr = "--arg1=${arg1} --arg2=${arg2}" //noqa
    template "foo.py"
}

In this example, the linter has a problem with argstr, "Variable was declared but not used", despite it being used in the template.

I can think of three ways around this:

  • surface template variables to the linter (sounds difficult)
  • inline comment to silence linter warnings for a line, like //noqa (sounds feasible, could be broadly applicable to other issues)
  • disable unused variable check between script: and template (easy but blunt hack)

Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant