Skip to content

Commit 51e0e03

Browse files
ewelsbentsherman
andauthored
Fix lint error formatting for errors at end of line (nextflow-io#6717)
Co-authored-by: Ben Sherman <bentshermann@gmail.com>
1 parent c256c5f commit 51e0e03

File tree

2 files changed

+88
-4
lines changed

2 files changed

+88
-4
lines changed

modules/nextflow/src/main/groovy/nextflow/script/parser/v2/ErrorListener.groovy

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -157,8 +157,8 @@ class StandardErrorListener implements ErrorListener {
157157

158158
for( int i = fromLine; i <= toLine; i++ ) {
159159
String fullLine = lines[i - 1]
160-
int start = (i == startLine) ? startColumn - 1 : 0
161-
int end = (i == endLine) ? endColumn - 1 : fullLine.length()
160+
int start = (i == startLine) ? Math.min(startColumn - 1, fullLine.length()) : 0
161+
int end = (i == endLine) ? Math.min(endColumn - 1, fullLine.length()) : fullLine.length()
162162

163163
// Truncate to max 70 characters
164164
int maxLen = 70
@@ -174,8 +174,8 @@ class StandardErrorListener implements ErrorListener {
174174
}
175175

176176
String line = fullLine.substring(windowStart, Math.min(lineLen, windowStart + maxLen))
177-
int adjStart = Math.max(0, start - windowStart)
178-
int adjEnd = Math.max(adjStart + 1, Math.min(end - windowStart, line.length()))
177+
int adjStart = Math.max(0, Math.min(start - windowStart, line.length()))
178+
int adjEnd = Math.max(adjStart, Math.min(end - windowStart, line.length()))
179179

180180
// Left border
181181
if(i == toLine && i !== startLine) term.fg(color).a("").reset().a(" ")
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
/*
2+
* Copyright 2013-2026, Seqera Labs
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package nextflow.cli
18+
19+
import java.nio.file.Files
20+
21+
import nextflow.exception.AbortOperationException
22+
import org.junit.Rule
23+
import spock.lang.Specification
24+
import test.OutputCapture
25+
/**
26+
*
27+
* @author Ben Sherman <bentshermann@gmail.com>
28+
*/
29+
class CmdLintTest extends Specification {
30+
31+
@Rule
32+
OutputCapture capture = new OutputCapture()
33+
34+
def 'should report compilation errors' () {
35+
36+
given:
37+
def dir = Files.createTempDirectory('test')
38+
39+
dir.resolve('main.nf').text = '''\
40+
process HELLO {
41+
42+
script:
43+
"""
44+
${
45+
params.is_paired_end
46+
? "..."
47+
: "..."
48+
}
49+
"""
50+
}
51+
'''
52+
53+
dir.resolve('nextflow.config').text = '''\
54+
process {
55+
withLabel:
56+
'bambino' {
57+
container = "..."
58+
}
59+
}
60+
'''
61+
62+
when:
63+
def cmd = new CmdLint()
64+
cmd.args = [dir.toFile().toString()]
65+
cmd.launcher = Mock(Launcher) {
66+
getOptions() >> Mock(CliOptions)
67+
}
68+
cmd.run()
69+
70+
then:
71+
thrown(AbortOperationException)
72+
and:
73+
capture.toString().contains("Error $dir/main.nf:5:19: Unexpected input: '\\n'")
74+
capture.toString().contains("│ 5 | \${")
75+
capture.toString().contains("╰ | ^")
76+
capture.toString().contains("Error $dir/nextflow.config:2:27: Unexpected input: '\\n'")
77+
capture.toString().contains("│ 2 | withLabel:")
78+
capture.toString().contains("╰ | ^")
79+
80+
cleanup:
81+
dir?.deleteDir()
82+
}
83+
84+
}

0 commit comments

Comments
 (0)