Skip to content

[HUDI-296] Explore use of spotless to auto fix formatting errors#945

Merged
vinothchandar merged 3 commits intoapache:masterfrom
leesf:HUDI-296
Oct 10, 2019
Merged

[HUDI-296] Explore use of spotless to auto fix formatting errors#945
vinothchandar merged 3 commits intoapache:masterfrom
leesf:HUDI-296

Conversation

@leesf
Copy link
Copy Markdown
Contributor

@leesf leesf commented Oct 8, 2019

see jira: https://jira.apache.org/jira/projects/HUDI/issues/HUDI-296

The main changes are described below:
[1]. Add spotless plugin to the project by reference to the usage of jrtom and avro. We would run mvn spotless:check to check style and mvn spotless:apply to fix style errors.
[2]. Change the base of eclipse-java-google-style.xml to https://github.com/google/styleguide/blob/gh-pages/eclipse-java-google-style.xml and have some minor modifications.
[3]. Change max property of LineLength in checkstyle.xml for the lack of strict limit of eclipse-java-google-style.xml
[4]. Add SuppressionFilter module to handle violation between checkstyle plugin and eclipse-java-google-style.xml.
[5]. Add AvoidNestedBlocks module to checkstyle.xml to handle indentation in case statement.
[6]. Add RealtimeUnmergedRecordReader.java to checkstyle-suppressions.xml to handle indentation violation between checkstyle plugin and eclipse-java-google-style.xml.

CC @vinothchandar Please review when you get a chance. Thanks.

@leesf
Copy link
Copy Markdown
Contributor Author

leesf commented Oct 9, 2019

@vinothchandar I can't restart the build in travis page, see travis-page-snapshot. It seems that only committers would restart?

@vinothchandar
Copy link
Copy Markdown
Member

ah. really?.. Then better to run these locally to iterate? It seems to fail from some spotless issue.

Also can we make this work with our checkstyle rules that are already in place?

@vinothchandar
Copy link
Copy Markdown
Member

we spent a bunch of time tweaking it for our needs and got it consistent with code styling. So love to make minimal one-time formatting changes to this setup if possible cc @bvaradar

@leesf
Copy link
Copy Markdown
Contributor Author

leesf commented Oct 9, 2019

@vinothchandar @bvaradar Please restart the build due to the exception(The forked VM terminated without properly saying goodbye. VM crash or System.exit called), travis log link(https://api.travis-ci.org/v3/job/595435352/log.txt).
PS: The exception has been seen many times before, any solutions or suggestions?

@leesf
Copy link
Copy Markdown
Contributor Author

leesf commented Oct 9, 2019

This PR uses both the existing checkstyle.xml(used by maven checkstyle plugin) and eclipse-java-google-format.xml(used by spotless plugin) placed in /style folder to check code style.
After this one-time formatting, we would then benefit from spotless plugin which auto fixes formatting errors by running mvn spotless:apply. CC @vinothchandar @bvaradar

@vinothchandar
Copy link
Copy Markdown
Member

@bvaradar what do you think? I am okay if this is one time.

Option.ofNullable(sortByField.isEmpty() ? null : sortByField),
Option.ofNullable(isDescending),
Option.ofNullable(limit <= 0 ? null : limit)).addAllRows(rows).flip();
Table table =
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

kind of dislike that we are wasting the first line.. Can we fix it so that we use line 62 as well?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This is split by spotless plugin, and the line length is defined to 120(org.eclipse.jdt.core.formatter.lineSplit) in eclipse-java-google-format.xml, we need to make org.eclipse.jdt.core.formatter.lineSplit a little larger than 120(such as 200?) to use the above line 62. But IMHO, 120 is a proper length and just let spotless plugin formats the code style, WDYT?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Okay fair enough. We can leave it as is.

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<checkstyle.skip>true</checkstyle.skip>
<main.basedir>${project.parent.parent.basedir}</main.basedir>
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

please test once if you are able to indepdently run a mvn command from one of the sub modules. i.e cd hudi-cli; mvn clean install should work..

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Good catch.
Before this PR(such as in master branch), we could run mvn clean install -pl hudi-client in project root dir to install specified module but not run mvn clean install in sub modules dirs i.e hudi-client(Unable to find configuration file
at location F:/community/incubator-hudi/hudi-client/style/scalastyle-config.xml). I just updated this PR to make it works and verified mvn clean install -DskipTests in sub modules(hudi-cli, hudi-client, hudi-spark..).

Copy link
Copy Markdown
Contributor Author

@leesf leesf Oct 10, 2019

Choose a reason for hiding this comment

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

And maybe we would seperate the commit to another PR(should be the basis of this PR) since it is not so relative to this PR. WDYT?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

ideally yes. but as long as building independent modules work, I am okay for this PR. your call. Let me know how you want to proceed

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I was thinking to open another PR (may also need to define main.basedir as this PR does) to make mvn clean install works in sub modules(just a minor git history improvement). However, it would also be done in this PR. So please merge this PR if there is no other concern.

@vinothchandar
Copy link
Copy Markdown
Member

vinothchandar commented Oct 10, 2019

btw spotbugs might be a good thing to explore as well. https://spotbugs.github.io general comment. not related to this PR

Copy link
Copy Markdown
Contributor

@bvaradar bvaradar left a comment

Choose a reason for hiding this comment

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

@vinothchandar @leesf : Agree with the idea. Good to have command line lint fixing capability.

Looks good overall.

@vinothchandar vinothchandar merged commit b19bed4 into apache:master Oct 10, 2019
@leesf leesf deleted the HUDI-296 branch October 10, 2019 14:39
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.

3 participants