tipsy / j2html

Java to HTML generator. Enjoy typesafe HTML generation.
https://j2html.com/
Apache License 2.0
765 stars 137 forks source link

Source Code formatting #89

Closed kicktipp closed 5 years ago

kicktipp commented 6 years ago
  1. Not all Source files are formatted the same. This leads to many unintended changes as my IDE Eclipse usually formats the source code as soon as I save the file I am editing (Save Actions)

  2. I would like to upload a formatting configuration for eclipse which every developer can use. I would just use eclipse standards with longer lines and some tweaks for special cases. But if you can export yours to the root folder would be fine, too.

  3. Then I would like to format the complete source code with this formatting configuration to have everything formatted with the same rules.

tipsy commented 6 years ago

On my better formatted projects I use these formatting rules:

<code_scheme name="tipsy-format">
  <option name="CLASS_COUNT_TO_USE_IMPORT_ON_DEMAND" value="99" />
  <option name="NAMES_COUNT_TO_USE_IMPORT_ON_DEMAND" value="99" />
  <option name="PACKAGES_TO_USE_IMPORT_ON_DEMAND">
    <value />
  </option>
  <option name="IMPORT_LAYOUT_TABLE">
    <value>
      <package name="" withSubpackages="true" static="false" />
      <package name="" withSubpackages="true" static="true" />
    </value>
  </option>
  <option name="RIGHT_MARGIN" value="200" />
  <codeStyleSettings language="JAVA">
    <indentOptions>
      <option name="CONTINUATION_INDENT_SIZE" value="4" />
    </indentOptions>
  </codeStyleSettings>
</code_scheme>

They're (probably) IntelliJ specific though.

I can do a full format after we merge #88.

tipsy commented 6 years ago

We could try using editorconfig.

tipsy commented 6 years ago

Or we could just attach one config for eclipse and one for IntelliJ.. Probably simpler, since editorconfig seems to need a plugin in eclipse.

kicktipp commented 6 years ago

I have no problem with editorconfig. Its fine for me. Can you export your favourite formatting as editorconfig?

Regards Janning

Am 1. Dezember 2017 20:38:26 schrieb David notifications@github.com:

Or we could just attach one config for eclipse and one for IntelliJ.. Probably simpler, since editorconfig seems to need a plugin in eclipse.

-- You are receiving this because you authored the thread. Reply to this email directly or view it on GitHub: https://github.com/tipsy/j2html/issues/89#issuecomment-348594435

tipsy commented 6 years ago

I've merged all the settings that were available in the editorconfig-spec now.

tipsy commented 6 years ago

Two differences in our formatters now

  1. Imports should be strictly alphabetical (no special treatment/grouping for java imports)
  2. Javadoc param doc should be on the same line as param
// mine
* @param writer the current writer
// yours
* @param writer
*            the current writer
kicktipp commented 6 years ago

There are still many other small glitches and this is really annoying. There must be a good way to share a common codestyle. But at the moment it seems to be better to attach one config for eclipse and one for IntelliJ as you proposed. And I try to adapt my formatting as we go...

tipsy commented 6 years ago

Two more differences based on the last PR:

  1. There should be an empty line before javadoc
  2. Javadoc param doc should be aligned:
    * @param writer            the current writer
    * @param model             a model object to provide data for children to render
    * @param someLongParamName some doc
tipsy commented 6 years ago

@kicktipp can this be closed now?

niko-dunixi commented 6 years ago

@tipsy I'm running into the same issue, plus I think you're developing on windows which is committing different new-line characters my mac (I think). How would you feel about the the Google-Java-Format? I ask because it'd be easy to just add a maven plugin to enforce code-style regardless of IDE.

If you prefer your style I wouldn't mind trying to find/configure a maven plugin for you as well. How do you feel about it?

EDIT: I found your .editorconfig file has the setting for end_of_line character set, but my intellij doesn't seem to be respecting it. Not sure what to do about that, so I guess disregard that part for the time being.

niko-dunixi commented 6 years ago

I've opened a pull-request to proof of concept what I mean, feel free to hold-off/reject if you have another preference

kicktipp commented 6 years ago

Absolutely great that you take care of it. I tried before and failed. I wonder why it is so complicated to get the same formatting rules across IDE/OS. This topic must be relevant in each open source project with more than two developers.

kicktipp commented 6 years ago

By the way: I am developing with Ubuntu/Eclipse/STS So I can test your setup.

niko-dunixi commented 6 years ago

Nice! We'll get a good mix of setups that way :)

As far as why it's difficult, I think that's a hard question to answer for a few reasons. The main one is that there's no one size fits all setup for a lot of things. Especially with code being an almost direct representation of how you think and approach problem solving, if something in that setup is counter intuitive for a person (or just out-right gets in the way) it won't be a good fit for that project.

tipsy commented 6 years ago

@tipsy I'm running into the same issue, plus I think you're developing on windows which is committing different new-line characters my mac (I think). How would you feel about the the Google-Java-Format? I ask because it'd be easy to just add a maven plugin to enforce code-style regardless of IDE.

If you prefer your style I wouldn't mind trying to find/configure a maven plugin for you as well. How do you feel about it?

A maven plugin to enforce the code-style would be great. I really like the IntelliJ default code-style, but I'm not super picky. I can have a look tomorrow.

Naxos84 commented 6 years ago

You could try the checkstyle plugin. available for intellij, eclipse and maven.