Skip to content

Run Nextflow lint in pre-commit#8391

Closed
edmundmiller wants to merge 7 commits intomasterfrom
lint
Closed

Run Nextflow lint in pre-commit#8391
edmundmiller wants to merge 7 commits intomasterfrom
lint

Conversation

@edmundmiller
Copy link
Contributor

@edmundmiller edmundmiller commented May 4, 2025

This pull request adds a new linting hook for Nextflow scripts to the pre-commit configuration. This will help ensure consistent formatting and style for the repository's .nf and nextflow.config files.

  • The hook is set to run serially due to a known concurrency issue.
  • The hook will NOT format the code automatically. It'll just throw an error, and the user will have to correct it by hand.

@@ -1,3 +1,3 @@
process {
cpus = 1 // Needed for deterministic results
Copy link
Contributor

@robsyme robsyme May 5, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would be good to retain comments if possible.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is a current limitation in the formatter, it can't handle inline comments like this yet.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I recommend keeping the formatter off by default. It's not worth losing comments like this one

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's the point of pre-commit though 😞

@maxulysse
Copy link
Member

Looking good, but definitively this is WAY too many files modified at once.
Could we batch that in multiple PRs?

entry: nextflow lint
language: system
files: '\.nf$|nextflow\.config$'
args: ["-format", "-sort-declarations", "-spaces", "4", "-harshil-alignment", "-output", "concise"]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd much prefer a config file 😬 nextflow-io/nextflow#5934

Though I guess we can always add that later.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would as well, but perfect is the enemy of good 😉

@bentsherman
Copy link

I agree with Maxime. I would turn off the formatting and only fix linter errors in this PR. In a separate PR I would run the formatter as a once-off and undo any comment removals or controversial formatting changes. We should improve the formatter to handle those cases, not the other way around

@edmundmiller
Copy link
Contributor Author

edmundmiller commented May 5, 2025

I agree with Maxime. I would turn off the formatting and only fix linter errors in this PR. In a separate PR I would run the formatter as a once-off and undo any comment removals or controversial formatting changes. We should improve the formatter to handle those cases, not the other way around

Yeah it's a bit much. I'll chat with @nf-core/maintainers about it.

I'm thinking we

  1. Turn on the pre-commit formatting(for the CI check and ease)
  2. Report any issues we have to https://github.com/nextflow-io/language-server (Or Nextflow proper?)

@ewels
Copy link
Member

ewels commented May 5, 2025

Works for me 👍🏻 I think a slow roll-out at first until we're confident is a good idea. We can check each module one by one as they are updated to make sure that the changes are sanitised.

This will fail if the locally installed Nextflow version isn't recent enough, right? Any way that we can deal with that gracefully?

@edmundmiller edmundmiller marked this pull request as ready for review May 6, 2025 12:24
@edmundmiller
Copy link
Contributor Author

This will fail if the locally installed Nextflow version isn't recent enough, right? Any way that we can deal with that gracefully?

How complicated do you want to get?

  1. We can use script instead and add a version check that way.

  2. We can use the fail directive

-   repo: local
    hooks:
    -   id: changelogs-rst
        name: changelogs must be rst
        entry: changelog filenames must end in .rst
        language: fail
        files: 'changelog/.*(?<!\.rst)$'
  1. We can use docker_image or conda to force the right version

@ewels
Copy link
Member

ewels commented May 6, 2025

How complicated do you want to get?

As little as possible 😅

@edmundmiller edmundmiller enabled auto-merge May 9, 2025 18:06
@maxulysse
Copy link
Member

@adamrtalbot played with this too in https://github.com/adamrtalbot/nf-lint-pre-commit

@maxulysse
Copy link
Member

Ran it manually for some modules: #8891
It is still slightly messy

@LouisLeNezet
Copy link
Contributor

Hi,
I'm digging up this old PR, as we would like to add nextflow lint to the Github action and therefore it would be nice to also have it to the pre-commit !

@SPPearce
Copy link
Contributor

@bentsherman, @ewels , do you have any progress on improving the formatter?

@maxulysse
Copy link
Member

@nf-core-bot fix linting pretty please 🙏

@mashehu
Copy link
Contributor

mashehu commented Feb 10, 2026

we need to add setup-nextflow to the linting.yml and fix-litning.yml for this step to work

@ewels
Copy link
Member

ewels commented Feb 10, 2026

@bentsherman, @ewels , do you have any progress on improving the formatter?

No updates yet - we know it's a high priority issue and will get to it ASAP, I think it's currently scheduled to be done once the new Records stuff is in place. Hopefully done before the 26.04 release, but might be another month or so until we get to it.

Issues being tracked here, if anything is missing please add more issues.

@SPPearce
Copy link
Contributor

I think that we could move any comments that are going to be affected and apply the auto formatting anyway.

@adamrtalbot
Copy link
Contributor

@adamrtalbot played with this too in https://github.com/adamrtalbot/nf-lint-pre-commit

Updated this here: https://github.com/seqeralabs/nf-lint-pre-commit/releases/tag/v0.2.0

@SPPearce
Copy link
Contributor

Can we also set vscode to do the same on save?

@mashehu
Copy link
Contributor

mashehu commented Feb 11, 2026

Can we also set vscode to do the same on save?

this is just the linter without the formatter atm

edmundmiller and others added 7 commits February 11, 2026 15:27
This will just cause pre-commit to just throw an error but not reformat
the code.

Users will have to manually format for now.

nextflow-io/nextflow#6365

Co-authored-by: maxulysse <maxulysse@users.noreply.github.com>
@jonasscheid
Copy link
Contributor

Can we also set vscode to do the same on save?

I would suggest only doing that if vscode is not in auto-save mode

@mashehu
Copy link
Contributor

mashehu commented Feb 16, 2026

My plan for this PR is waiting for @LouisLeNezet to be done with his heroic linting fix efforts and then merge just the pre-commit-config.yml with the nextflow lint hook.

rev: v0.2.0
hooks:
- id: nextflow-lint
files: '\.nf$|nextflow\.config$'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the almost the same as the default for the pre-commit hook: https://github.com/seqeralabs/nf-lint-pre-commit/blob/58b2431ebcdf99a0c024c9c7f695bfa30c01555c/.pre-commit-hooks.yaml#L6

Shall we add *.nextflow files upstream? I've never seen one in the wild!

@mashehu
Copy link
Contributor

mashehu commented Feb 24, 2026

Closing in favor of #10241

@mashehu mashehu closed this Feb 24, 2026
auto-merge was automatically disabled February 24, 2026 10:25

Pull request was closed

@github-project-automation github-project-automation bot moved this from In Progress to Done in nf-core infrastructure projects Feb 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Development

Successfully merging this pull request may close these issues.

10 participants