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

Added source code linting to Groovy code and Jenkinsfile #325

Open
wants to merge 13 commits into
base: main
Choose a base branch
from

Conversation

chawinphat
Copy link

@chawinphat chawinphat commented Oct 15, 2023

Description

Describe what this change achieves.
Created a pre-commit hook to run a linter for groovy and jenkinsfiles.

I used npm-groovy-lint and the pre-commit framework. The pre-commit hook will run after calling git commit and will run commands specified on the .pre-commit-config.yaml file. . In this case, we will run npm-groovy-lint on all directories specified in the 'entry' field.

Screenshot below shows the result on linting tests/jenkins, src/jenkins, and /vars.
image

I also fixed each error in tests/jenkins, vars, and src/jenkins.

Issues Resolved

#320

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
For more information on following Developer Certificate of Origin and signing off your commits, please check here.

@codecov
Copy link

codecov bot commented Oct 16, 2023

Codecov Report

Merging #325 (7de60cf) into main (d19c684) will not change coverage.
The diff coverage is n/a.

❗ Current head 7de60cf differs from pull request most recent head 4757649. Consider uploading reports for the commit 4757649 to get more accurate results

@@            Coverage Diff            @@
##               main     #325   +/-   ##
=========================================
  Coverage     87.43%   87.43%           
  Complexity       29       29           
=========================================
  Files            81       81           
  Lines           207      207           
  Branches         11       11           
=========================================
  Hits            181      181           
  Misses           19       19           
  Partials          7        7           

@gaiksaya
Copy link
Member

Hi @chawinphat

Thank you for the contribution. We also have (most of the) groovy code living in vars folder. Please include that too.
Also can you elaborate a bit on how this is supposed to work? Maybe adding a working snippet?
Thanks!

Copy link
Member

@gaiksaya gaiksaya left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for contributing this feature @chawinphat .
Couple of questions mentioned below. Overall looks good.

@@ -1,5 +1,5 @@
{
"extends": "recommended",
"extends": "recommended-jenkinsfile",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the difference between recommended and recommended-jenkinsfile?

Copy link
Author

@chawinphat chawinphat Oct 31, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's the linter's recommended format which lints jenkinsfiles too. When using just 'recommended' the linter catches errors that are not actually errors and breaks the program.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you provide some examples what failures are you encountering? I am doubtful what to use as well. On high level looks like recommended is best path for groovy. recommended-jenkinsfile seems to be applicable for jenkinsFiles specifically? Please correct me if I am wrong.

Adding @prudhvigodithi @peterzhuamazon @dblock to get some input.

Copy link
Author

@chawinphat chawinphat Nov 4, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One error I saw was that the linter complained that 'variable x was not used in the file' even when x was referenced inside a string in that file.

Running the linter's automatic fixing caused tests to fail if I used the 'jenkins' setting while it was able to build and test fine with 'jenkins-file'

.pre-commit-config.yaml Show resolved Hide resolved
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: No status
Development

Successfully merging this pull request may close these issues.

2 participants