Introducing Code Styles:

Linting and Formatting

Objectives 🚀

Tools 🛠

Language Linter Formatter
Groovy CodeNarc IntelliJ
Python pylint * PyCharm *
Shell Shellcheck * shfmt / IntelliJ? *
Terraform 😞 terraform fmt
YAML yamllint 😞
YAML (k8s) kubeval * 😞
* - pending implementation

Running Locally 👨‍💻

Example: jenkins-job-dsl-seed-jobs

make fmt

make lint

Makefile Example

        
CODENARC='docker.io/abletonag/groovylint:0.7.1'

.PHONY: lint
lint:
    @docker run --rm -v `pwd`:/ws -u `id -u`:`id -g` \
        $(CODENARC) python3 /opt/run_codenarc.py -- \
            -includes='**/Jenkinsfile,**/*.groovy,**/*.dsl' \
            -rulesetfiles=file\:ruleset.groovy
        
        

Running in CI 🤖

Running in CI 🤖

            
stage('Lint') { steps { container('docker') { runCodeChecks() } } post { always { postCodeChecks() } failure { archiveArtifacts '*.log' } } }

Example

CodeNarc 👮‍‍

CodeNarc
CodeNarc analyzes Groovy code for defects, bad practices, inconsistencies, style issues and more. A flexible framework for rules, rulesets and custom rules means it's easy to configure CodeNarc to fit into your project.

CodeNarc 👮‍‍

            make lint
        
            ...
INFO Scanned 613 files
ERROR src/main/groovy/util/Versions.groovy:33:
    SpaceAfterOpeningBrace: [empty message]
ERROR src/main/groovy/util/Versions.groovy:33:
    SpaceBeforeClosingBrace: [empty message]
ERROR Found 2 violation(s)
make: *** [lint] Error 1
        

Future Ruleset Improvements

Future Ruleset Improvements

Future Ruleset Improvements

Next Steps 📈

Thank you!

Questions?