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

java: implement checkstyle #4599

Merged
merged 10 commits into from
Feb 12, 2019
Merged

java: implement checkstyle #4599

merged 10 commits into from
Feb 12, 2019

Conversation

zklapow
Copy link
Contributor

@zklapow zklapow commented Feb 7, 2019

Apologies for the enormous diff.

This PR adds checkstyle linting to the java codebase based on google's checkstyle rules (googles defaults were chosen because A) they are included with checkstyle B) they are widely used and thus have good IDE support and C) this was originally a youtube project)

The pom has been updated to fail the build on checkstyle violations, and all of the existing code has been updated to conform to checkstyle so that it will build.

This PR contains a huge number of whitespace changes (because these files were inconsistently using tabs/spaces) as well as a number of other minor refactorings (renaming single letter variables, moving oddly placed variable declarations) but no logic has been changed.

This should make working on and contributing to this project much easier.

@zklapow zklapow requested a review from sougou as a code owner February 7, 2019 15:30
Copy link
Member

@deepthi deepthi left a comment

Choose a reason for hiding this comment

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

LGTM

@harshit-gangal
Copy link
Member

It will be good to enable git pre commit checkstyle java linter plugin. Can you also add this as part of this PR?

Signed-off-by: Ze'ev Klapow <[email protected]>
Signed-off-by: Ze'ev Klapow <[email protected]>
@zklapow
Copy link
Contributor Author

zklapow commented Feb 8, 2019

👍 definitely, just added a pre commit hook that looks for modified files in the java client and runs checkstyle:check for affected modules.

Copy link
Member

@harshit-gangal harshit-gangal left a comment

Choose a reason for hiding this comment

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

Looks Good.
Thanks for adding git hook.

@sougou
Copy link
Contributor

sougou commented Feb 12, 2019

Can you resolve the conflicts?

@zklapow
Copy link
Contributor Author

zklapow commented Feb 12, 2019

just resolved the conflicts, should be good to go now.

Signed-off-by: Ze'ev Klapow <[email protected]>
@sougou sougou merged commit 50209fc into vitessio:master Feb 12, 2019
@deepthi
Copy link
Member

deepthi commented Feb 19, 2019

@zklapow there is now an error from the pre-commit hooks:

Not a git repository
To compare two paths outside a working tree:
usage: git diff [--no-index] <path> <path>

This is coming from the checkstyle hook (confirmed by removing it in my local workspace before trying to commit). Can you please look into and fix this?

@leoxlin
Copy link

leoxlin commented Feb 19, 2019

I'm unable to repro @deepthi, can you give me the

@zklapow
Copy link
Contributor Author

zklapow commented Feb 20, 2019

@deepthi the above info would be very useful. I also can't repro this behavior, but would be happy to do some more digging if I had a better idea of what your setup is like.

@deepthi
Copy link
Member

deepthi commented Feb 20, 2019 via email

@zklapow
Copy link
Contributor Author

zklapow commented Feb 21, 2019

@deepthi can you try applying this patch to the git hook and see if that fixes things? I think my cd'ing might be overly naive and this should help:

diff --git a/misc/git/hooks/checkstyle b/misc/git/hooks/checkstyle
index 777dd5124..e603222c5 100755
--- a/misc/git/hooks/checkstyle
+++ b/misc/git/hooks/checkstyle
@@ -15,7 +15,8 @@ function get_module() {
   done
 }

-cd java;
+DIR=$(PWD)
+cd $DIR/java;

 modules=();

@@ -41,4 +42,4 @@ export MAVEN_OPTS="-client

 mvn -q -pl "$modules_arg" checkstyle:check;

-cd -;
+cd $DIR;

If that works for you I can PR that in. Sorry for the inconvenience!

@deepthi
Copy link
Member

deepthi commented Feb 21, 2019

I had to try it slightly differently: $(pwd) instead of $(PWD) but it still errors out:

++ pwd
+ DIR=/home/deepthi/go/src/vitess.io/vitess
+ cd /home/deepthi/go/src/vitess.io/vitess/java
+ modules=()
++ git diff --relative --name-only --cached '*.java'
Not a git repository
To compare two paths outside a working tree:
usage: git diff [--no-index] <path> <path>
+ '[' 0 -eq 0 ']'
+ exit

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants