npm-groovy-lint
npm-groovy-lint copied to clipboard
bug: Wrong autoformat indentation after complex expressions
Hi,
I am using the pre-commit hooks and found out that the format-npm-groovy-lint
messes up the indentation with complex expressions. For example, the following snippet
class MyClass {
static String writeReport(String testName, String testSummary) {
markupBuilder.testsuites {
delegate.testsuite(name: testName, tests: results.size(), failures: results.findAll { !it.TestResult.contains("Passed") }.size(), errors: 0) {
}
}
return stringWriter.toString()
}
}
is formatted as:
class MyClass {
static String writeReport(String testName, String testSummary) {
markupBuilder.testsuites {
delegate.testsuite(name: testName, tests: results.size(), failures: results.findAll { !it.TestResult.contains("Passed") }.size(), errors: 0) {
}
}
return stringWriter.toString()
}
}
but, if I move the findAll expression into a new line, the formatter works fine:
class MyClass {
static String writeReport(String testName, String testSummary) {
markupBuilder.testsuites {
delegate.testsuite(name: testName, tests: results.size(), failures: results.findAll {
!it.TestResult.contains("Passed")
}.size(), errors: 0) {
println it
}
}
return stringWriter.toString()
}
}
For reference,
- groovy lint rc file:
{
"extends": "recommended-jenkinsfile",
"rules": {
"formatting.Indentation": {
"spacesPerIndentLevel": 2,
"severity": "info"
}
}
}
- pre-commit config file:
repos:
- repo: https://github.com/nvuillam/npm-groovy-lint
rev: v14.6.0
hooks:
- id: npm-groovy-lint
name: Lint groovy files
description: Groovy & Jenkinsfile Linter
entry: npm-groovy-lint --output txt --failon error
language: node
types: [groovy]
- id: format-npm-groovy-lint
name: Format Lint groovy findings
description: Groovy & Jenkinsfile Formatter
entry: npm-groovy-lint --format
language: node
types: [groovy]
- id: fix-npm-groovy-lint
name: Fix Lint groovy findings
description: Groovy & Jenkinsfile Auto-fixer
entry: npm-groovy-lint --fix --output txt --failon error
language: node
types: [groovy]