Skip to content

[Feature][style] Add spotless maven plugin for automatic style fix.#11272

Merged
EricGao888 merged 14 commits intoapache:devfrom
EricGao888:Fix-10963
Aug 6, 2022
Merged

[Feature][style] Add spotless maven plugin for automatic style fix.#11272
EricGao888 merged 14 commits intoapache:devfrom
EricGao888:Fix-10963

Conversation

@EricGao888
Copy link
Copy Markdown
Member

@EricGao888 EricGao888 commented Aug 3, 2022

Purpose of the pull request

Brief change log

  • Add spotless maven plugin in pom.xml.
  • Add eclipse style check for spotless plugin.
  • Spotless only checks and fixes formatting errors for difference with HEAD.

Verify this pull request

  • Verified by manual tests.

@EricGao888 EricGao888 changed the title Fix 10963 [Feature][style] Add spotless maven task plugin for automatic style fix. Aug 3, 2022
@EricGao888 EricGao888 changed the title [Feature][style] Add spotless maven task plugin for automatic style fix. [Feature][style] Add spotless maven plugin for automatic style fix. Aug 3, 2022
@EricGao888
Copy link
Copy Markdown
Member Author

Actually we could keep both Spotless and Checkstyle as long as we make the requirements of those two compatible. We will use Spotless for fixing style errors automatically and use Checkstyle in CI for double-check.

@EricGao888
Copy link
Copy Markdown
Member Author

Actually we could keep both Spotless and Checkstyle as long as we make the requirements of those two compatible. We will use Spotless for fixing style errors automatically and use Checkstyle in CI for double-check.

AFAIK. Apache ShardingSphere is using this method, FYI:

https://github.com/apache/shardingsphere/blob/19265081c966cb0a839267b060593b258b0883b4/pom.xml#L1001-L1045

https://github.com/apache/shardingsphere/tree/master/src/resources

Also here is a related instructions written in Chinese:

https://shardingsphere.apache.org/blog/cn/material/spotless/

@codecov-commenter
Copy link
Copy Markdown

codecov-commenter commented Aug 3, 2022

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 40.26%. Comparing base (bf5f7a8) to head (a4553be).
Report is 1604 commits behind head on dev.

Additional details and impacted files
@@            Coverage Diff            @@
##                dev   #11272   +/-   ##
=========================================
  Coverage     40.26%   40.26%           
+ Complexity     4843     4842    -1     
=========================================
  Files           974      974           
  Lines         37323    37323           
  Branches       4142     4142           
=========================================
  Hits          15028    15028           
+ Misses        20749    20748    -1     
- Partials       1546     1547    +1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@EricGao888 EricGao888 marked this pull request as ready for review August 3, 2022 07:33
Copy link
Copy Markdown
Member

@ruanwenjun ruanwenjun left a comment

Choose a reason for hiding this comment

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

Can we set the import order?
And please change the related doc.

@EricGao888
Copy link
Copy Markdown
Member Author

EricGao888 commented Aug 3, 2022

Can we set the import order? And please change the related doc.

I've tested locally and it seems it does check the import order and fix it automatically, although I haven't figured it out how it does it. Anyway I will double check it. Thx

@EricGao888 EricGao888 added the miss:docs missing documents in PR label Aug 3, 2022
@EricGao888
Copy link
Copy Markdown
Member Author

I will update the related docs in the following commits of this PR.

@EricGao888 EricGao888 added this to the 3.1.0-alpha milestone Aug 3, 2022
@kezhenxu94
Copy link
Copy Markdown
Member

Can we set the import order? And please change the related doc.

I've tested locally and it seems it does check the import order and fix it automatically, although I haven't figured it out how it does it. Anyway I will double check it. Thx

I think spotless by default sorts the imports in alphabetical order unless we want to sort in another order we don't need extra configuration maybe

@ruanwenjun
Copy link
Copy Markdown
Member

Can we set the import order? And please change the related doc.

I've tested locally and it seems it does check the import order and fix it automatically, although I haven't figured it out how it does it. Anyway I will double check it. Thx

I think spotless by default sorts the imports in alphabetical order unless we want to sort in another order we don't need extra configuration maybe

Ok, in fact, we have our own order of imports, but it's ok for me if we change to alphabetical order.

@EricGao888
Copy link
Copy Markdown
Member Author

EricGao888 commented Aug 4, 2022

For developer's convenience, I suggest setting Spotless executions configuration as follows:

<executions>
  <execution>
      <goals>
          <goal>apply</goal>
      </goals>
      <phase>compile</phase>
  </execution>
</executions>

In this way, Spotless will automatically fix the style / formatting issues when compiling the project. However, we need to keep Checkstyle so that CI could make sure the style is correct in case developers do not compile and test the code before pushing it to remote repo.

Another way is to use git pre-commit hook and remove Checkstyle. WDYT @kezhenxu94 @ruanwenjun

@kezhenxu94
Copy link
Copy Markdown
Member

For developer's convenience, I suggest setting Spotless executions configuration as follows:

<executions>

  <execution>

      <goals>

          <goal>apply</goal>

      </goals>

      <phase>compile</phase>

  </execution>

</executions>

In this way, Spotless will automatically fix the style / formatting issues when compiling the project. However, we need to keep Checkstyle so that CI could make sure the style is correct in case developers do not compile and test the code before pushing it to remote repo.

Another way is to use git pre-commit hook and remove Checkstyle. WDYT @kezhenxu94 @ruanwenjun

I personally used pre-commit hook in my own project and I prefer to use this. Also even we have the hook we should still keep the style check in CI because that can be skipped in developers' local machine.

@kezhenxu94
Copy link
Copy Markdown
Member

For developer's convenience, I suggest setting Spotless executions configuration as follows:

<executions>

  <execution>

      <goals>

          <goal>apply</goal>

      </goals>

      <phase>compile</phase>

  </execution>

</executions>

Also, developers might skip running maven compile if they develop in an IDE (mostly)

kezhenxu94
kezhenxu94 previously approved these changes Aug 5, 2022
Copy link
Copy Markdown
Member

@kezhenxu94 kezhenxu94 left a comment

Choose a reason for hiding this comment

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

Can you please also update this ?

- name: Check License Header
uses: apache/skywalking-eyes@30367d8286e324d5efc58de4c70c37ea3648306d
- uses: ./.github/actions/reviewdog-setup
with:
reviewdog_version: v0.10.2
- shell: bash
run: ./mvnw -B -q checkstyle:checkstyle-aggregate
- shell: bash
env:
REVIEWDOG_GITHUB_API_TOKEN: ${{ inputs.token }}
run: |
if [[ -n "${{ inputs.token }}" ]]; then
reviewdog -f=checkstyle \
-reporter="github-pr-review" \
-filter-mode="added" \
-fail-on-error="true" < target/checkstyle-result.xml
fi

@EricGao888
Copy link
Copy Markdown
Member Author

Can you please also update this ?

- name: Check License Header
uses: apache/skywalking-eyes@30367d8286e324d5efc58de4c70c37ea3648306d
- uses: ./.github/actions/reviewdog-setup
with:
reviewdog_version: v0.10.2
- shell: bash
run: ./mvnw -B -q checkstyle:checkstyle-aggregate
- shell: bash
env:
REVIEWDOG_GITHUB_API_TOKEN: ${{ inputs.token }}
run: |
if [[ -n "${{ inputs.token }}" ]]; then
reviewdog -f=checkstyle \
-reporter="github-pr-review" \
-filter-mode="added" \
-fail-on-error="true" < target/checkstyle-result.xml
fi

Sure, just for confirmation, I'm supposed to update this with Spotless related stuff instead of simply removing it, correct?

@kezhenxu94
Copy link
Copy Markdown
Member

Can you please also update this ?

- name: Check License Header
uses: apache/skywalking-eyes@30367d8286e324d5efc58de4c70c37ea3648306d
- uses: ./.github/actions/reviewdog-setup
with:
reviewdog_version: v0.10.2
- shell: bash
run: ./mvnw -B -q checkstyle:checkstyle-aggregate
- shell: bash
env:
REVIEWDOG_GITHUB_API_TOKEN: ${{ inputs.token }}
run: |
if [[ -n "${{ inputs.token }}" ]]; then
reviewdog -f=checkstyle \
-reporter="github-pr-review" \
-filter-mode="added" \
-fail-on-error="true" < target/checkstyle-result.xml
fi

Sure, just for confirmation, I'm supposed to update this with Spotless related stuff instead of simply removing it, correct?

Yes right

@sonarqubecloud
Copy link
Copy Markdown

sonarqubecloud bot commented Aug 5, 2022

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

No Coverage information No Coverage information
0.0% 0.0% Duplication

@EricGao888 EricGao888 added improvement make more easy to user or prompt friendly and removed miss:docs missing documents in PR labels Aug 6, 2022
@EricGao888 EricGao888 merged commit 6a02870 into apache:dev Aug 6, 2022
zhongjiajie added a commit that referenced this pull request Aug 9, 2022
checkstyle file remove in #11272
ruanwenjun added a commit to ruanwenjun/dolphinscheduler that referenced this pull request Sep 7, 2022
* [Feature][style] Add spotless maven plugin for automatic style fix. (apache#11272)

* [Feature][style] Add spotless maven plugin for automatic style fix (apache#10963)

* Fix spotless ratchet configuration

* Remove license-check and decrease line length threshold value

* Update related docs

* Remove checkstyle and add pre-commit hook

* Test updated pre-commit hook

* Replace checkstyle with spotless in CI

* Remove reviewdog

(cherry picked from commit 6a02870)

* Cp spotless

Co-authored-by: Eric Gao <ericgao.apache@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backend CI&CD document feature new feature improvement make more easy to user or prompt friendly test

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature][style] Replace checkstyle plugin with spotless to automatically fix formatting errors

5 participants