Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

--fix adds redundant space into ${VARIABLE} (SpaceBeforeOpeningBrace fix rule error) #96

Closed
phts opened this issue Sep 2, 2020 · 1 comment · Fixed by #97
Closed
Labels
bug Something isn't working good first issue Good for newcomers

Comments

@phts
Copy link

phts commented Sep 2, 2020

I have a file Jenkinsfile

pipeline {
  stages {
    stage('CleanWorkspace') {
      steps {
        cleanWs()
        dir("../${JOB_NAME}@2"){
          deleteDir()
        }
      }
    }
  }
}
$ npm-groovy-lint

  6     info     The opening brace for the closure in class None is not preceded by a space or whitespace  SpaceBeforeOpeningBrace 

and after npm-groovy-lint --fix

it becomes

pipeline {
  stages {
    stage('CleanWorkspace') {
      steps {
        cleanWs()
        dir("../$ {JOB_NAME}@2"){
          deleteDir()
        }
      }
    }
  }
}
$ npm-groovy-lint --fix

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'   │      1      │      1      │        0        │
└─────────┴───────────┴─────────────┴─────────────┴─────────────────┘

which obviously breaks string content.

My .groovylint.json:

{
  "extends": "recommended-jenkinsfile",
  "rules": {
    "ClassJavadoc": "off",
    "DuplicateNumberLiteral": "off",
    "DuplicateStringLiteral": "off",
    "formatting.Indentation": {
      "severity": "error",
      "spacesPerIndentLevel": 2
    }
  }
}

$ npm-groovy-lint --version
GroovyLint: Successfully processed CodeNarc: 
CodeNarc version 1.6.1

npm-groovy-lint version 7.4.4

Embeds:
CodeNarc version 1.6.1
- Groovy version 3.0.5 (superlite)

$ node -v
v12.13.1
@phts phts changed the title Formatting adds redundant space into ${VARIABLE} --fix adds redundant space into ${VARIABLE} Sep 2, 2020
@nvuillam
Copy link
Owner

nvuillam commented Sep 2, 2020

That's indeed an ugly bug , thanks for reporting !

Before I provide a fix, I suggest as workaround that you use // groovylint-disable-line SpaceBeforeOpeningBrace at the end of the line :)

ex:

pipeline {
  stages {
    stage('CleanWorkspace') {
      steps {
        cleanWs()
        dir("../${JOB_NAME}@2"){ // groovylint-disable-line SpaceBeforeOpeningBrace
          deleteDir()
        }
      }
    }
  }
}

@nvuillam nvuillam changed the title --fix adds redundant space into ${VARIABLE} --fix adds redundant space into ${VARIABLE} (SpaceBeforeOpeningBrace fix rule error) Sep 2, 2020
@nvuillam nvuillam added bug Something isn't working good first issue Good for newcomers labels Sep 2, 2020
nvuillam added a commit that referenced this issue Sep 3, 2020
…ult file extensions (#97)

- Fix [(#96)](#96) --fix adds redundant space into `${VARIABLE}` (SpaceBeforeOpeningBrace fix rule error)
- Fix grails framework detection
- Fix Groovy parsing parsing when multiple files
- Add `.gvy` and `.nf` in default browsed files extensions
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working good first issue Good for newcomers
Projects
None yet
2 participants