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

JavaCheckstyle and Scalastyle #366

Closed
szafirov opened this issue Apr 18, 2016 · 8 comments
Closed

JavaCheckstyle and Scalastyle #366

szafirov opened this issue Apr 18, 2016 · 8 comments

Comments

@szafirov
Copy link

szafirov commented Apr 18, 2016

I can't seem to get the same errors when running the pre-commit hook and with the command line directly. I don't know if it's a bug or my setup is wrong.

File .overcommit.yml content:

PreCommit:
  Scalastyle:
    enabled: true
    on_warn: fail
    flags: ['-c', 'buildtools/src/main/resources/conventions/scalastyle_config.xml']

Invoking overcommit:

$ overcommit --version
  overcommit 0.33.0
$ overcommit --sign
$ git add .
$ git status
 On branch test
 Changes to be committed:
  (use "git reset HEAD <file>..." to unstage)
     modified:  src/main/scala/ch/hsr/geohash/util/BoundingBoxGeoHashCreator.scala

$ overcommit --run
 Running pre-commit hooks
 Analyze with Scalastyle..................................[Scalastyle] OK

 ✓ All pre-commit hooks passed

When running directly with scalastyle command line:

$ scalastyle -w -c ./buildtools/src/main/resources/conventions/scalastyle_config.xml .
 warning file=src/main/scala/ch/hsr/geohash/util/BoundingBoxGeoHashCreator.scala message=Header does not match expected text line=1
 warning file=src/main/scala/ch/hsr/geohash/util/BoundingBoxGeoHashCreator.scala message=File must end with newline character

Some errors do show, such as if I add a println statement, it will get caught by both.

@sds
Copy link
Owner

sds commented Apr 19, 2016

Hey @szafirov,

What does running OVERCOMMIT_DEBUG=1 overcommit --run give you?

@szafirov
Copy link
Author

szafirov commented Apr 19, 2016

szafirov in ~/Repo/gaia on feature/cw ● ● λ overcommit --sign
Updating signature for configuration file...
szafirov in ~/Repo/gaia on feature/cw ● ● λ OVERCOMMIT_DEBUG=1 overcommit --run
git config --local --get overcommit.configuration.signature
EXIT STATUS: 0
STDOUT: "241e8aa0dfb04595e3926be453eb9c7625593989ad27ae53de12da8bb9523f71\n"
STDERR: ""
git config --local --get overcommit.configuration.signature
EXIT STATUS: 0
STDOUT: "241e8aa0dfb04595e3926be453eb9c7625593989ad27ae53de12da8bb9523f71\n"
STDERR: ""
Running pre-commit hooks
git config --get user.name
git config --get user.email
EXIT STATUS: 0
EXIT STATUS: 0STDOUT: "Stephane Zafirov\n"

STDOUT: "szafirov@expedia.com\n"
STDERR: ""
STDERR: ""
scalastyle -c buildtools/src/main/resources/conventions/scalastyle_config.xml ... (1 splittable args)
grep -IHn ^<<<<<<<[     ] ... (7599 splittable args)
git rev-parse HEAD
EXIT STATUS: 0
STDOUT: "d66187801b9c0f8b43f8c084929a8f240e6f79fd\n"
STDERR: ""
EXIT STATUS: 0
STDOUT: "warning file=/Users/szafirov/Repo/gaia/thirdparty/src/main/scala/com/expedia/gps/geo/thirdparty/ch/hsr/geohash/util/BoundingBoxGeoHashCreator.scala message=Magic Number line=24 column=8\nwarning file=/Users/szafirov/Repo/gaia/thirdparty/src/main/scala/com/expedia/gps/geo/thirdparty/ch/hsr/geohash/util/BoundingBoxGeoHashCreator.scala message=Regular expression matched 'println' line=24 column=0\nwarning file=/Users/szafirov/Repo/gaia/thirdparty/src/main/scala/com/expedia/gps/geo/thirdparty/ch/hsr/geohash/util/BoundingBoxGeoHashCreator.scala message=File must end with newline character\nProcessed 1 file(s)\nFound 0 errors\nFound 3 warnings\nFinished in 543 ms\n"
STDERR: ""
Analyze with Scalastyle..................................[Scalastyle] FAILED
Warnings on modified lines:
warning file=/Users/szafirov/Repo/gaia/thirdparty/src/main/scala/com/expedia/gps/geo/thirdparty/ch/hsr/geohash/util/BoundingBoxGeoHashCreator.scala message=Magic Number line=24 column=8
warning file=/Users/szafirov/Repo/gaia/thirdparty/src/main/scala/com/expedia/gps/geo/thirdparty/ch/hsr/geohash/util/BoundingBoxGeoHashCreator.scala message=Regular expression matched 'println' line=24 column=0

EXIT STATUS: 1
STDOUT: ""
STDERR: ""

✗ One or more pre-commit hooks failed

szafirov in ~/Repo/gaia on feature/cw ● ● λ scalastyle -x '.*Test.*' -c ./buildtools/src/main/resources/conventions/scalastyle_config.xml .
warning file=/Users/szafirov/Repo/gaia/./thirdparty/src/main/scala/com/expedia/gps/geo/thirdparty/ch/hsr/geohash/util/BoundingBoxGeoHashCreator.scala message=Magic Number line=24 column=8
warning file=/Users/szafirov/Repo/gaia/./thirdparty/src/main/scala/com/expedia/gps/geo/thirdparty/ch/hsr/geohash/util/BoundingBoxGeoHashCreator.scala message=Regular expression matched 'println' line=24 column=0
warning file=/Users/szafirov/Repo/gaia/./thirdparty/src/main/scala/com/expedia/gps/geo/thirdparty/ch/hsr/geohash/util/BoundingBoxGeoHashCreator.scala message=File must end with newline character
Processed 1 file(s)
Found 0 errors
Found 3 warnings
Finished in 2844 ms

It seems to ignore the last error, which is what was happening when I only had that.

Perhaps I should include the scalastyle_config.xml, so here it is:
scalastyle_config.xml.txt

Thanks!

@jawshooah
Copy link
Collaborator

Looks like you've configured Overcommit to use scalastyle_config-test.xml rather than scalastyle_config.xml. Could that be the issue?

@szafirov
Copy link
Author

You are right, I made a mistake the first time and edited my comment. Please check the latest above.
But I think that's another issue when I was trying to have two scalastyle hooks, one for the main code and one for the tests. I don't think that is supported currently, is it?

@jawshooah
Copy link
Collaborator

Do you have problem_on_unmodified_line set to ignore? In case you missed it, the hook options are listed in the readme.

@jawshooah
Copy link
Collaborator

And no, you can't specify different config files for different file patterns through Overcommit. You could create a custom hook that does this, though.

@szafirov
Copy link
Author

Ok, I think the problem is specifically with the rule:

<check level="warning" class="org.scalastyle.file.WhitespaceEndOfLineChecker" enabled="true">

This rule tries to enforce an empty line at the end of the file, but because it is missing, overcommit might not be marking it as a line that can be reported on and skips it. That's my hypothesis anyway.

If you examine the output while debugging:

STDOUT: "warning file=/Users/szafirov/Repo/gaia/thirdparty/src/main/scala/com/expedia/gps/geo/thirdparty/ch/hsr/geohash/util/BoundingBoxGeoHashCreator.scala message=Magic Number line=24 column=8
\nwarning file=/Users/szafirov/Repo/gaia/thirdparty/src/main/scala/com/expedia/gps/geo/thirdparty/ch/hsr/geohash/util/BoundingBoxGeoHashCreator.scala message=Regular expression matched 'println' line=24 column=0
\nwarning file=/Users/szafirov/Repo/gaia/thirdparty/src/main/scala/com/expedia/gps/geo/thirdparty/ch/hsr/geohash/util/BoundingBoxGeoHashCreator.scala message=File must end with newline character
\nProcessed 1 file(s)\nFound 0 errors
\nFound 3 warnings
\nFinished in 543 ms
\n"
STDERR: ""
Analyze with Scalastyle..................................[Scalastyle] FAILED
Warnings on modified lines:
warning file=/Users/szafirov/Repo/gaia/thirdparty/src/main/scala/com/expedia/gps/geo/thirdparty/ch/hsr/geohash/util/BoundingBoxGeoHashCreator2.scala message=Magic Number line=25 column=12
warning file=/Users/szafirov/Repo/gaia/thirdparty/src/main/scala/com/expedia/gps/geo/thirdparty/ch/hsr/geohash/util/BoundingBoxGeoHashCreator2.scala message=Regular expression matched 'println' line=25 column=4

EXIT STATUS: 1

For now I will remove that rule from my scalastyle to avoid the issue.

Thanks.

@jawshooah
Copy link
Collaborator

You're right, we were skipping over messages with no line number. #368 should fix it.

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

No branches or pull requests

3 participants