npm-groovy-lint icon indicating copy to clipboard operation
npm-groovy-lint copied to clipboard

Incorrect indentation in blocks and braces

Open cdebergh opened this issue 3 months ago • 2 comments

Hello,

I tried using your linter to format groovy files, specifically Jenkinsfile groovy, but I can't seem to get the indentation formatting to be correct. Is this a known issue and is there a fix or a workaround?

Version:

npm-groovy-lint -v
GroovyLint: Successfully processed CodeNarc: 
CodeNarc version 3.3.0
npm-groovy-lint version 14.4.0

Embeds:
CodeNarc version 3.3.0
- Groovy version 3.0.9 (superlite)

Command:

npm-groovy-lint --format --noserver test.groovy 
test.groovy


npm-groovy-lint results in  linted files:
┌─────────┬───────────┬─────────────┬─────────────┬─────────────────┐
│ (index) │ Severity  │ Total found │ Total fixed │ Total remaining │
├─────────┼───────────┼─────────────┼─────────────┼─────────────────┤
│    0    │  'Error'  │      0      │      0      │        0        │
│    1    │ 'Warning' │      0      │      0      │        0        │
│    2    │  'Info'   │     14      │     14      │        0        │
└─────────┴───────────┴─────────────┴─────────────┴─────────────────┘

Input File:

def afterBuild() {
    stage('Run Tests')
    {
        try {
            runResult = runTests()
        }
        catch(Exception e)
        {
            throw new Exception(e)
        }
        finally
{
if (runResult)
{
log.info(runResult.out)
            try { 
                publish("Test Completed. Result" + runResult)
            }
            catch(Exception e)
            {
                log.warn("Unable to publish test results: " + e.toString())
            }
        
            }
}
    }
}

Output File:

def afterBuild() {
    stage('Run Tests')
    {
        try {
            runResult = runTests()
        }
        catch (Exception e)
        {
            throw new Exception(e)
        }
        finally
{
            if (runResult) {
                log.info(runResult.out)
                try {
                    publish('Test Completed. Result' + runResult)
                }
            catch (Exception e)
            {
                    log.warn('Unable to publish test results: ' + e.toString())
            }
            }
}
    }
}

I've also tried commands

npm-groovy-lint --format test.groovy
npm-groovy-lint --fix test.groovy
npm-groovy-lint --fix -x "Indentation,BracesForIfElse,BracesForTryCatchFinally,IndentationClosingBraces" test.groovy 

with the same result.

cdebergh avatar Mar 30 '24 20:03 cdebergh

@cdebergh npm-groovy-lint formatting is based on CodeNarc rule, which is sometimes not accurate , so this is a know problem :(

nvuillam avatar Mar 31 '24 11:03 nvuillam

This issue has been automatically marked as stale because it has not had recent activity. It will be closed in 14 days if no further activity occurs. Thank you for your contributions.

If you think this issue should stay open, please remove the O: stale 🤖 label or comment on the issue.

github-actions[bot] avatar May 01 '24 01:05 github-actions[bot]