bazel-contrib / bazel-contrib/rules_jvm

FR: Test rule for running google-java-format check

Open
#23 3 comments 0 reactions 0 assignees View on GitHub
Dominant language
Go
Stars
54
Forks
98
Avg merge
6d 2h
Merged PRs (30d)
7

Description

Currently we are doing this outside of the build, e.g. with this alias:

```
$ alias gjf
alias gjf='git show --diff-filter=AMR --pretty="" --name-only HEAD | grep java$ | xargs -r /home/davido/projects/gerrit/tools/format/google-java-format-1.7 -i'
```

On Slack @shs96c commented how this test rule could be implemented:

```
We’ve not got a rule for that yet, but the process of writing one is simple enough:

o Create a java_google_format_test rule (it’s important that it’s a test rule!)

o Hook it into _create_lint_tests (the pattern should be obvious)

o Optionally create a rule that when run will actually do the reformatting

o Create either a config rule or just allow people to set True as the value for the workspace’s lint_setup

Once that’s done, anyone using the java_library, java_binary, java_test or java_export rules from contrib_rules_jvm can opt into the linting framework and have the google java formatter be part of their regular test suites.
```

*Update*

Linting can be disabled by adding a `no-lint` tag to any rule that needs it.
And for everything in a build file by using `package_lint_config(linters = {})`.

It was also pointed out, that there is another PR was uploaded [upstream](https://github.com/google/google-java-format/pull/216).

Contributor guide

Open the contributing guide

Research direction

Start by reading the existing lint-rule pattern around _create_lint_tests and the java_library, java_binary, java_test, and java_export rules in contrib_rules_jvm. Check the upstream google-java-format PR for related context, then run the existing build and lint tests. Done means a java_google_format_test rule can be opted into by those rules and respects the documented no-lint and package_lint_config exclusions.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
build-system, tooling
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.