Skip to content

add checkstyle (no tabs, left curly) and usage docs #5075#5106

Merged
kcondon merged 3 commits intodevelopfrom
5075-add-checkstyle
Sep 28, 2018
Merged

add checkstyle (no tabs, left curly) and usage docs #5075#5106
kcondon merged 3 commits intodevelopfrom
5075-add-checkstyle

Conversation

@pdurbin
Copy link
Member

@pdurbin pdurbin commented Sep 27, 2018

connects to #5075

checkstyle.xml Outdated

<!--

Checkstyle configuration that checks the sun coding conventions from:
Copy link
Contributor

Choose a reason for hiding this comment

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

Code says "sun conventions"; docs say "default Netbeans formatting settings". Are these different, and if so which one is authoritative?

Copy link
Member Author

Choose a reason for hiding this comment

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

Hmm. Good point. Maybe I'll take this whole section out. It's confusing. Thanks.

Copy link
Member Author

Choose a reason for hiding this comment

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

Removed in 80334fc


To check the entire project:

``mvn checkstyle:checkstyle``
Copy link
Contributor

Choose a reason for hiding this comment

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

If possible, html checkstyle reports might be more readable than xml reports.

Copy link
Member Author

Choose a reason for hiding this comment

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

It's a great idea to have HTML reports from Checkstyle but from a quick look at https://stackoverflow.com/questions/6342211/how-to-generate-checkstyle-reports we might be able to use mvn site to create the HTML for. I played with mvn site 6 or so years ago at https://github.com/dvn/dvn-mavensitepoc


To check a single file:

``mvn checkstyle:checkstyle -Dcheckstyle.includes=**\/SystemConfig*.java``
Copy link
Contributor

Choose a reason for hiding this comment

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

Does checkstyle support reformatting (either individual files, or ideally "only reformat code you've changed")?

Copy link
Member Author

Choose a reason for hiding this comment

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

I don't know.

Copy link
Contributor

Choose a reason for hiding this comment

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

Nope. It will only validate things, not fix it for you.

Copy link
Member Author

Choose a reason for hiding this comment

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

If we switch to Go, we can use gofmt, which will reformat as well. 😄 See https://groups.google.com/d/msg/dataverse-dev/y2Jpk3szTf8/rckKmP6-BgAJ

<artifactId>maven-checkstyle-plugin</artifactId>
<version>3.0.0</version>
<configuration>
<configLocation>checkstyle.xml</configLocation>
Copy link
Contributor

Choose a reason for hiding this comment

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

Is the convention for checkstyle.xml to live at the top-level, or should it live somewhere else (conf/? )?

Copy link
Contributor

Choose a reason for hiding this comment

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

That depends on your personal opinion. From the Java projects I know, people just place it at the same level as the pom.xml.

Copy link
Member Author

Choose a reason for hiding this comment

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

I like it when I find certain files at the top level, including:

  • README.md
  • LICENSE.md
  • CONTRIBUTING.md
  • Dockerfile
  • Vagrantfle

and for Java projects, seeing checkstyle.xml at the top level seems nice. 😄

Copy link
Member

@qqmyers qqmyers left a comment

Choose a reason for hiding this comment

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

I cherry-picked this commit and was able to run the check - only ~200 errors! Never-the-less, I agree this is a good place to start and this is a good add.

FWIW, the three issues I'm seeing where my code differs from what's there (which has its own variations) are

  • tabs instead of spaces, and it looks like the standard indent is 4 spaces (not 2 as it said in the docs somewhere)
  • Line length - mostly it appears that lines can be as long as necessary although there are some that have been split
  • brace placement, though this is less prevalent.

I use eclipse rather than netbeans, but, after learning from @pdurbin that spaces were preferred, I was able to find how to change to four spaces. If it is possible to get a standard for how long a line can be before it wraps, I can probably match netbeans there too. I'll look into curly braces - the new doc shows how they should be and that may be the eclipse default already.

I guess one point in that is that giving specifics in the docs beyond just 'as netbeans does it' is helpful.

In terms of cleaning things up, it may be worth a run through the code (happy to help) but having a one-way policy for new code, i.e. if you submit ill-formatted code, others can reformat it without asking (or you may be required to fix the PR) and, if you find ill-formatted code, you're allowed to add fixes to your PR, could be helpful too. If things like the tab issues weren't so widespread now, I might suggest just starting with a one-way policy, but it would definitely make the first few PRs hard to read.

We should add this to Checkstyle too.
@pdurbin
Copy link
Member Author

pdurbin commented Sep 27, 2018

@qqmyers thanks for all of your thoughts on this. In 6ca8617 I specified 4 spaces for Java. For Bash I said 2 spaces in pull request #5063.


<!-- Checks for Naming Conventions. -->
<!-- See http://checkstyle.sf.net/config_naming.html -->
<!--
Copy link
Member

Choose a reason for hiding this comment

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

Should we enable these? I think we're in pretty good shape in this area, but it's good to have this enforces, especially when people with non-Java (=no camelCase) background contribute.

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.

6 participants