Skip to content

Conversation

@ewels
Copy link
Member

@ewels ewels commented Jan 16, 2026

Fixes variable redeclaration errors for strict syntax compliance.

Details

Changes

This PR fixes 53 strict syntax errors across 30+ modules by resolving variable redeclaration issues using multiple strategies:

  1. Renaming closure parameters - Changed shadowing parameter names (e.g., indexidx)
  2. Renaming local variables - Added suffixes to distinguish from inputs (e.g., fastqfastq_opt)
  3. Using distinct meta names - Renamed duplicate meta parameters (e.g., meta2, meta3)
  4. Adding def keywords - Explicitly declared variables in script sections

Example fix:

// Before - closure parameter shadows outer variable
def index = "genome"
files.eachWithIndex { file, index ->  // ERROR: redeclaration
    println(index)
}

// After - renamed closure parameter
def index = "genome"
files.eachWithIndex { file, idx ->
    println(idx)
}

Why

Nextflow 25.10+ strict syntax mode enforces stricter scoping rules and prevents variable redeclarations that could lead to ambiguity or bugs. Each variable must be declared only once per scope.

Affected Modules (30+)

Including: bbmap/bbsplit, mafft/align, spaceranger/count, krakentools/kreport2krona, cnvnator,hmmer/hmmalign, jvarkit/sam2tsv, salsa2, and many others.

Testing

  • All changes maintain existing functionality and logic
  • Pre-commit hooks passed
  • Ready for nextflow lint validation
  • 4 commits organized by fix strategy for easy review

This work was completed with AI assistance using Seqera AI.

@ewels ewels requested review from a team and edmundmiller as code owners January 16, 2026 20:07
ewels and others added 4 commits January 17, 2026 22:33
Remove variable redeclarations by renaming closure parameters and local
variables that shadow input parameters or previously declared variables.

Fixed modules:
- bbmap/bbsplit: Renamed 'index' closure parameter to 'idx' in eachWithIndex
- bedtools/groupby: Renamed local 'summary_col' to 'summary_col_opt'
- mafft/align: Renamed stub section variables with '_stub' suffix
- spaceranger/count: Renamed option variables with '_opt' suffix

This addresses variable redeclaration errors flagged by nextflow lint in
strict syntax mode (NXF_SYNTAX_PARSER=v2).

Co-Authored-By: Claude Sonnet 4.5 <[email protected]>
Continue fixing variable redeclaration errors for strict syntax mode:

- krakentools/extractkrakenreads: Use distinct meta parameter names (meta2, meta3)
- mafft/align: Rename local option variables with _opt suffix
- blobtk/plot: Add def keyword to script section variables
- cellranger/count: Add def keyword to script section variables
- diann: Add def keyword to script section variables
- flash: Add def keyword to script section variables
- scds: Add def keyword to script section variables

In strict syntax mode, all variable declarations must use the def keyword
explicitly, and variables cannot be redeclared within the same scope.

Co-Authored-By: Claude Sonnet 4.5 <[email protected]>
Continue fixing variable redeclarations:

- peka, pureclip: Use distinct meta parameter names for multiple tuple inputs
- svtyper/svtyper: Fix duplicate meta2 in inputs, rename vcf shadow variable
- svtyper/svtypersso: Rename vcf and fasta shadow variables with _opt suffix
- cellrangerarc/mkref: Rename reference_config to reference_config_name
- eklipse: Rename ref_gb to ref_gb_path
- ichorcna/createpon: Rename exons to exons_opt, add def to prefix
- igvreports: Rename fasta to fasta_opt

Co-Authored-By: Claude Sonnet 4.5 <[email protected]>
Complete fixing all variable redeclaration errors for strict syntax mode:

- pureclip: Use distinct meta parameter name (meta3) for third input
- jvarkit/sam2tsv, jvarkit/vcf2table: Rename regions_file to regions_opt
- hmmer/hmmfetch: Rename index to index_opt
- chewbbaca/createschema: Rename prodigal_tf and cds to *_opt
- cnvnator/cnvnator: Add def to prefix in script section
- crumble: Rename bedout to bedout_opt in both script and stub
- gmmdemux: Rename skip and type_report to *_opt
- happy/sompy: Rename bams to bams_opt
- salsa2: Rename gfa and dup to *_opt
- sam2lca/analyze: Rename database to database_path
- segemehl/align: Rename reads to reads_opt, add def to prefix
- svanalyzer/svbenchmark: Rename bed to bed_opt

All 53 variable redeclaration errors have been resolved.

Co-Authored-By: Claude Sonnet 4.5 <[email protected]>
@ewels ewels force-pushed the fix/variable-redeclarations branch from 363af1f to 8954f04 Compare January 17, 2026 21:34
Copy link
Contributor

@SPPearce SPPearce left a comment

Choose a reason for hiding this comment

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

I don't know why it is trying to add the def to the prefix, even when it needs to be there.

@ewels ewels marked this pull request as draft January 19, 2026 09:39
ewels and others added 2 commits January 19, 2026 13:33
Addresses review comments from @SPPearce on PR nf-core#9684:

1. Remove 'def' from prefix variables used in output blocks:
   - cnvnator/cnvnator: Remove def from prefix (script & stub)
   - diann: Remove def from prefix (script & stub)
   - flash: Remove def from prefix (script & stub)
   - ichorcna/createpon: Remove def from prefix (script only)
   - segemehl/align: Remove def from prefix (script only)

2. Remove unnecessary variable declarations:
   - mafft/align: Remove unused stub variables (args_stub, add_stub,
     addfragments_stub, addfull_stub, addprofile_stub, addlong_stub)
   - mafft/align: Remove def from prefix (script) and prefix_stub

3. Improve code formatting:
   - spaceranger/count: Add backslash continuation between image option
     variables for better readability

All changes verified with:
- nextflow lint (all modules pass)
- NXF_SYNTAX_PARSER=v2 nextflow inspect (all modules pass)

Co-Authored-By: Claude Sonnet 4.5 <[email protected]>
When process inputs use meta2/meta3 to avoid variable redeclaration,
the corresponding meta.yml files must document these renamed variables.

Updated:
- krakentools/extractkrakenreads: meta → meta2, meta3
- peka: meta → meta2
- pureclip: meta → meta2, meta3
- svtyper/svtyper: meta2 → meta3 (for fai input)

All modules verified with:
- nextflow inspect (standard parser)
- NXF_SYNTAX_PARSER=v2 nextflow inspect (strict parser)

Co-Authored-By: Claude Sonnet 4.5 <[email protected]>
Copy link
Contributor

@SPPearce SPPearce left a comment

Choose a reason for hiding this comment

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

This looks fine, if the tests pass (a big if)

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

Successfully merging this pull request may close these issues.

3 participants