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

Create a checkstyle config for java #12

Open
bmarwell opened this issue Apr 1, 2019 · 5 comments
Open

Create a checkstyle config for java #12

bmarwell opened this issue Apr 1, 2019 · 5 comments
Assignees
Milestone

Comments

@bmarwell
Copy link

bmarwell commented Apr 1, 2019

Create a checkstyle.xml which looks a lot like @scream3r's style.

  • 4 spaces
  • No tabs
  • opening brace on the same line
  • line length? (he uses unlimited chars, but I'd keep it to let's say 140 or so).
  • Unix line breaks
  • UTF-8 source code files.
  • Avoid escaped unicode chars.
  • No empty blocks (also for catch).
  • No empty catch blocks, i.e. Exceptions must either be logged or rethrown (the history may not be lost). Thus, we might need a logging framework (slf4j).
  • right curly brace alone on it's own line
  • Whitespace around round parantheses in for and if statements.
  • One statement per line
  • no ternary operator ( expression ? true : false).
  • Empty line at EOF.
  • enforce sane member and class names.
  • do not use finalizer (deprecated anyway).
  • comments are intended on the same level as code and are in their own line (not trailing).
  • No star (asterisk) imports, might pose security risk.
  • Import order: Static imports, separator, own imports, separator, 3rd party imports, separator, java imports, javax imports.
  • utility classes (only static methods) are final and have a private constructor.
  • modifier order: As in the Java Language Specification (http://checkstyle.sourceforge.net/config_modifier.html#ModifierOrder).
  • switch case's fall throughs must have a comment that this is intentional.

Most of these rules are standard Java rules.

@tresf
Copy link

tresf commented Apr 1, 2019

Thanks.

  • Ternary is very useful. Don't blacklist.
  • There's more than just Java source.
  • This should be a long-term goal

@tresf
Copy link

tresf commented Apr 1, 2019

Avoid escaped unicode chars.

No! We're dealing with serial after all (STX/ETX)

@bmarwell
Copy link
Author

bmarwell commented Apr 1, 2019

| | Avoid escaped unicode chars.
| No! We're dealing with serial after all (STX/ETX)

I'm only talking about constant Strings in the java source code. There is no difference between writing

  String unitAbbrev = "μs"; | Best: perfectly clear even without a comment.
  String unitAbbrev = "\u03bcs"// "μs"

The data which would go over the wire would be the same in either case. Can you please elaborate why you would prefer the latter version? I'd only use unicode literals for invisible characters.

I agree on everything said in #12 (comment). Just don't overuse ternary in Java code. However, this issue is just for the java code.

@tresf
Copy link

tresf commented Apr 1, 2019

I'd only use unicode literals for invisible characters.

Agreed. STX/ETX are both examples of invisible characters.

@bmarwell
Copy link
Author

Now in the other issue we talked about the formatter-plugin. I really like this idea, and we could do one or more of the following:

  • Git commit hooks on checkstyle (never tried that).
  • Git commit hook on the formatter plugin using https://github.com/Cosium/maven-git-code-format.
  • There is this maven plugin. It will automatically execute whenever source files are processed. In IDEs, this is whenever you press 'save', on the command line it is whenever you compile (just before you compile).

To cite from Google:

Note: There is no configurability as to the formatter's algorithm for formatting. This is a deliberate design decision to unify our code formatting on a single format.

I like this idea, because there can not be any discussions. The use the same enforcements in gofmt and they just work fine.

@bmarwell bmarwell added this to the Release 4.0.0 milestone Apr 14, 2019
@bmarwell bmarwell modified the milestones: 4.0.0, 5.0.0 Jan 25, 2020
@bmarwell bmarwell self-assigned this Jan 25, 2020
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

2 participants