Skip to content

Commit a81994a

Browse files
authored
Merge pull request #135 from nextflow-io/fix/ignoreParams
Correctly ignore nested params
2 parents 5a9b1ae + 0216b86 commit a81994a

File tree

4 files changed

+44
-5
lines changed

4 files changed

+44
-5
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# nextflow-io/nf-schema: Changelog
22

3+
# Version 2.4.2
4+
5+
## Bug fixes
6+
7+
1. `validateParameters` should now correctly ignore nested parameters given in the `validation.ignoreParams` and the `validation.defaultIgnoreParams` configuration options.
8+
39
# Version 2.4.1
410

511
## Bug fixes

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ dependencies {
88
implementation 'com.sanctionco.jmail:jmail:1.6.3' // Needed for e-mail format validation
99
}
1010

11-
version = '2.4.1'
11+
version = '2.4.2'
1212

1313
nextflowPlugin {
1414
nextflowVersion = '24.10.0'

src/main/groovy/nextflow/validation/parameters/ParameterValidator.groovy

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -150,13 +150,17 @@ class ParameterValidator {
150150
// Check for nextflow core params and unexpected params
151151
//=====================================================================//
152152
unevaluatedParams.each{ param ->
153+
def String dotParam = param.replaceAll("/", ".")
153154
if (NF_OPTIONS.contains(param)) {
154155
errors << "You used a core Nextflow option with two hyphens: '--${param}'. Please resubmit with '-${param}'".toString()
155156
}
156-
else if (config.failUnrecognisedParams && !config.ignoreParams.contains(param)) {
157-
errors << "* --${param.replaceAll("/", ".")}: ${getValueFromJsonPointer("/"+param, paramsJSON)}".toString()
158-
} else if (!config.ignoreParams.contains(param)) {
159-
warnings << "* --${param.replaceAll("/", ".")}: ${getValueFromJsonPointer("/"+param, paramsJSON)}".toString()
157+
else if (!config.ignoreParams.any { dotParam == it || dotParam.startsWith(it + ".") } ) { // Check if an ignore param is present
158+
def String text = "* --${param.replaceAll("/", ".")}: ${getValueFromJsonPointer("/"+param, paramsJSON)}".toString()
159+
if(config.failUnrecognisedParams) {
160+
errors << text
161+
} else {
162+
warnings << text
163+
}
160164
}
161165
}
162166
// check for warnings

src/test/groovy/nextflow/validation/ValidateParametersTest.groovy

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1435,4 +1435,33 @@ class ValidateParametersTest extends Dsl2Spec{
14351435
error.message.contains("* --input (src/testRe..._extension): \"src/testResources/wrong_samplesheet_with_a_super_long_name.and_a_weird_extension\" does not match regular expression [^\\S+\\.(csv|tsv|yaml|json)\$]")
14361436
!stdout
14371437
}
1438+
1439+
def 'should correctly detect invalid parameters' () {
1440+
given:
1441+
def schema = Path.of('src/testResources/nextflow_schema_no_type.json').toAbsolutePath().toString()
1442+
def SCRIPT = """
1443+
params.genome = [
1444+
"test": "test"
1445+
]
1446+
params.genomebutlonger = true
1447+
params.testing = "test"
1448+
include { validateParameters } from 'plugin/nf-schema'
1449+
1450+
validateParameters(parameters_schema: '$schema')
1451+
"""
1452+
1453+
when:
1454+
def config = ["validation": [
1455+
"defaultIgnoreParams": [ "genome" ]
1456+
]]
1457+
def result = new MockScriptRunner(config).setScript(SCRIPT).execute()
1458+
def stdout = capture
1459+
.toString()
1460+
.readLines()
1461+
.findResults {it.contains('WARN nextflow.validation.SchemaValidator') || it.startsWith('* --') ? it : null }
1462+
1463+
then:
1464+
noExceptionThrown()
1465+
stdout == ["* --testing: test", "* --genomebutlonger: true"]
1466+
}
14381467
}

0 commit comments

Comments
 (0)