Repository navigation
Java code linting - #1593
Java code linting#1593
Conversation
sjwarner-bp
left a comment
There was a problem hiding this comment.
Hi @mirkoperillo - thanks for picking this one up.
I've never used FindBugs, so please correct me if I am wrong, but I think this plugin is normally used to flag possible exceptions etc. and runs against byte code.
When the idea of linting was proposed, I think it was more geared towards coding style and convention than anything else.
What do you think @exercism/java ? 🙂
|
Hi @sjwarner-bp , findbugs runs on byte code and try to found smell code, if you prefer focus on coding style I'll try to give a check to Checkstyle |
|
Thanks for this work @mirkoperillo! It's great that someone wants to help us with this 😄 I think I agree with @sjwarner-bp that linting (e.g. something like CheckStyle) is what we'd prefer to focus on. And I think the code we'd prefer to focus on having checked is the test code and the reference solution. After all the user impemented solution will be reviewed by mentors and it might be confusing for beginners to have to deal with linting. Do you agree @sjwarner-bp @mirkoperillo? 🙂 |
|
That's exactly right @FridaTveit - I think that we only have to worry about things internal to this repo so we end up with a bit more consistency (and hopefully it will pick up common small issues in code to give maintainers better focus on the actual logic)! 🙂 |
|
@FridaTveit @sjwarner-bp now I understand what you need. |
|
Added checkstyle plugin and removed findbugs one. |
Smarticles101
left a comment
There was a problem hiding this comment.
Is there a way for it to print directly to the console instead of generating a report?
|
@Smarticles101 the plugin does both things, do you intend that the report should not be created ? |
FridaTveit
left a comment
There was a problem hiding this comment.
This is looking promising @mirkoperillo, thanks for taking the time to do this! 😄
My main issue with it at the moment is that I believe the build.gradle file inside each exercise gets delivered to the users when they download the exercise. So I'd rather that file didn't mention checkstyle at all, so as to not confuse the users. Maybe we could add a checkstyle task to the build.gradle file in the exercises directory instead? To add a step that will be run as part of the travis build and preferably that contributors can run on its own as well if possible? 🙂
|
@FridaTveit ok, I'll work on this. |
|
Good question @mirkoperillo 🙂 I believe that config folder contains config for what to display on the exercism website for this track, so that might not be the best place for it. I would suggest either the exercises directory or the root of this repo. What do you think @sjwarner-bp @Smarticles101 @mirkoperillo? 🙂 |
FridaTveit
left a comment
There was a problem hiding this comment.
This is looking great @mirkoperillo! 😄 I've gone through the rules and added some thoughts and questions. Let me know what you think! 🙂
| --> | ||
| <property name="format" value="((//.*)|(\*.*))TODO[^: (]" /> | ||
| <property name="message" value='All TODOs should be named. e.g. "TODO: (ENG-123) - Refactor when v2 is released."' /> | ||
| </module> |
There was a problem hiding this comment.
I'm not sure we care about the two rules above. What do you think @sjwarner-bp @Smarticles101 @mirkoperillo? 🙂
There was a problem hiding this comment.
yes you are right, I think it is too strict to the example I found online
| <!--<!– Checks that each Java package has a Javadoc file used for commenting.--> | ||
| <!--Only allows a package-info.java, not package.html. –>--> | ||
| <!--<property name="severity" value="warning"/>--> | ||
| <!--</module>--> |
There was a problem hiding this comment.
Please remove the rule above instead of commenting it out 🙂
| <property name="severity" value="error" /> | ||
| </module> | ||
|
|
||
| <module name="RedundantImport"> |
There was a problem hiding this comment.
Great, this rule and the unused import one should make our lives much easier! I always forget to look for unused imports in PRs 🙂
|
|
||
| --> | ||
|
|
||
| <module name="AvoidStarImport"> |
There was a problem hiding this comment.
I'm not sure I agree with this rule? I don't think star imports are necessarily bad? Thoughts @sjwarner-bp @Smarticles101 @mirkoperillo? 🙂
There was a problem hiding this comment.
yes you are right
| <property name="severity" value="error" /> | ||
| </module> | ||
|
|
||
| <module name="ImportOrder"> |
There was a problem hiding this comment.
I'm not sure I care too much about import order? Thoughts @mirkoperillo @sjwarner-bp @Smarticles101? 🙂
| <property name="severity" value="error" /> | ||
| </module> | ||
|
|
||
| <module name="RightCurly"> |
There was a problem hiding this comment.
Great, this rule should be really useful! 😄
| </module> | ||
|
|
||
| <!-- Checks for braces around if and else blocks --> | ||
| <module name="NeedBraces"> |
There was a problem hiding this comment.
This should also be really useful! 😄
| <property name="format" value="e\.printStackTrace\(\)" /> | ||
| <property name="illegalPattern" value="true" /> | ||
| </module> | ||
| </module> |
There was a problem hiding this comment.
I don't think we need the rules above? I don't think it'll come up, no one should need to add them. But I also don't think there should be rules against it. Thoughts @mirkoperillo @Smarticles101 @sjwarner-bp? 🙂
|
|
||
| <!--module name="SuppressionFilter"> | ||
| <property name="file" value="suppressions.xml"/> | ||
| </module--> |
There was a problem hiding this comment.
Please remove the rule above instead of commenting it out 🙂
|
|
||
| <module name="Checker"> | ||
|
|
||
| <module name="FileTabCharacter"> |
There was a problem hiding this comment.
Is it possible to add a rule to check that files are indented correctly with four spaces? 🙂
There was a problem hiding this comment.
I'll give a look to rule syntax, but I imagine that it's possible
|
I have a proposal where to move |
|
Since it's just one file I don't think it needs to be in its own folder. I think just putting checkstyle.xml in the exercises folder is fine 🙂 What do you think @sjwarner-bp @Smarticles101 @mirkoperillo? 🙂 |
|
Yes thinking in a lean mode you are right: it's a single file so there is no need of a folder, thinking in a more structured way a folder can be used for future shared plugins configurations. I think there isn't a best solution, you are the mantainers so you have to choose the more suitable solution for you 😄 |
|
Good point 🙂 I think just a single file in the exercises folder for now and then we can always create a separate folder for it later if we realise we need more config files 🙂 |
FridaTveit
left a comment
There was a problem hiding this comment.
This is looking really great @mirkoperillo! 😄
I've left one comment about a couple of rules that I think can be removed 🙂 Apart from that I think the only thing left to do is fix the linting errors. Unfortunately that will need to be done before this can be merged so that the build will pass.
If you would prefer it I could look through the errors and open issues for them for anyone to solve so that you don't have to do it all 🙂 That will mean that this PR could be open for a while though until all the issues have been fixed. But that's fine if you would prefer that 🙂 Or you could fix the errors and add those changes to the PR (or do separate PRs for them), it's up to you 🙂
| <!-- . matches any character, so we need to escape it and use \. to match dots. --> | ||
| <property name="format" value="System\.err\.println" /> | ||
| <property name="illegalPattern" value="true" /> | ||
| </module> |
There was a problem hiding this comment.
I think the two rules above can be removed as well? 🙂
|
Also is it possible at the moment for contributors to run just the checkstyle linter locally @mirkoperillo? If so then we should probably document how to do that somewhere 🙂 But I'm happy to open another issue for adding that functionality (if it doesn't exist) and documenting it 🙂 |
|
@FridaTveit I have some issues with some validations. Actually
Validation wants something like this LocalFinalVariableName validation MemberNameCheck What I have to do ? |
|
Good question @mirkoperillo 🙂 Is there any reason all those variables can't be |
|
@FridaTveit Any reasons, I changed them as Last problem: one test in I fix it on my machine putting |
|
This is looking amazing, thanks @mirkoperillo! 😄 For the out of memory error, no I haven't seen that before. So I think as long as the travis build doesn't fail we don't have to make any changes for it 🙂 The only thing left to do I think is to rebase your changes on master (or merge master into your branch) as there are a few conflicting changes at the moment. Does that sound okay? 🙂 Thanks again for your amazing effort in making all these changes! 😄 |
|
@FridaTveit ok, I'll merge master in a couple of days |
|
merged the master |
FridaTveit
left a comment
There was a problem hiding this comment.
This looks great @mirkoperillo! Thanks again for this amazing effort, it should make a great difference to us as maintainers and everyone wanting to contribute! 😄
This is a early proposal for issue #1006.
I used
robot-simulatorexercise to this spike adding findbugs plugin to gradle.Actually the build fails every findbugs best practise warning during the check task
Yo can try it adding something bad to
RobotTest.java, i.eA HTML report file is produces in
build/reports/findbugsfolder.The findbugs analyzes the main e test code (not the reference implementation for the moment)
Is this the right way ?
Reviewer Resources:
Track Policies