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

Ability to ignore warnings #76

Open
ewels opened this issue Nov 25, 2024 · 1 comment
Open

Ability to ignore warnings #76

ewels opened this issue Nov 25, 2024 · 1 comment

Comments

@ewels
Copy link
Member

ewels commented Nov 25, 2024

The language server reports a range of code test results. Some are pretty critical (errors / deprecations) but some are a bit my stylistic (eg. unused variables needing a leading underscore).

It would be good if the more opinionated / less critical could be selectively ignored by using inline comments.

In the Python world this is typically done using # noqa comments - see the Flake8 docs. A specific error code can also be specified to ignore only that one. The exception typically only applies for the single line of code.

In Nextflow we could apply a similar // noqa comment to ignore a linting warning.

@ewels
Copy link
Member Author

ewels commented Nov 29, 2024

Looks like mberacochea/nf-linter has already added support for this:

Ignore files using "nf-lint: noqa"

In order to ignore a file, add the comment // nf-lint: noqa.

Example

// nf-lint: noqa
workflow {
   PROCESS()
}

Ignore errors using noqa

This linter supports ignoring errors per line or for the whole file.

It follows the Python linter's noqa rules, where you can ignore errors in lines using a comment.

Ignore an error in one Line

For example, ignore a specific error in one line.

The following script:

process LOOKUP_KINGDOM {
    input:
    tuple val(meta), path(fasta)

    output:
    tuple val(meta), env(value_detected), emit: value_detected

    script:
    """
    value_detected=$(example.py ${meta.id})
    """
}

Reports:

-----------------------------------------------------------------------------
📄 Linting: nf-linter/src/test/resources/test_with_errors_but_noqa_inline.nf
-----------------------------------------------------------------------------
🚩 Errors
- `value_detected` is not defined @ line 6, column 26.
----------------------------------------
Summary for script files
Total files linted: 1
Total errors: 1 🚩
Total warnings: 0 ⚠️
----------------------------------------

But it's possible to ignore this error by adding // noqa on the line with the error:

process LOOKUP_KINGDOM {
    input:
    tuple val(meta), path(fasta)

    output:
    tuple val(meta), env(value_detected), emit: value_detected // noqa

    script:
    """
    value_detected=$(example.py ${meta.id})
    """
}

That error is ignored:

-----------------------------------------------------------------------------
📄 Linting: nf-linter/src/test/resources/test_with_errors_but_noqa_inline.nf
-----------------------------------------------------------------------------
✨ No issues with this one.
----------------------------------------
Summary for script files
Total files linted: 1
Total errors: 0 🚩
Total warnings: 0 ⚠️
----------------------------------------

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