CleanThat
Cleanthat is a project enabling automatic code cleaning, from formatting to refactoring.
Beware CleanThat currently refers to 2 sub-projects:
Cleanthat Refactorer
: A library enabling Java linting rules/mutatorsCleanthat HouseKeeper
: A GitHub App enabling automatic house-keeping of your Git
repository, for various languages, given external linting engines (e.g. Spotless
, OpenRewrite
, Cleanthat Refactorer
, etc)The point of this project is to enable automatic cleaning of your code-base. By cleaning, we include :
As of 2022-12, it focuses on Java projects, but enabling formatting various languages through Spotless.
Related projects:
See CHANGES.MD
Cleanthat HouseKeeper
)Cleanthat HouseKeeper
is currently compatible with the following languages:
see FormatterFactory
Cleanthat Refactorer
)Cleanthat Refactorer
is currently compatible with the following languages:
Type
resolution. This enables cleaning files on a per-impacted-file basis (e.g. in a Github Pull-Request).cleanthat-maven-plugin
(TODO)UTF-8
mvn
plugin (for pure mvn
users)mvn
integration is available through Spotless: https://github.com/diffplug/spotless/tree/main/plugin-maven#cleanthat
One can then clean its codebase with mvn spotless:apply
mvn
plugin (for GitHub App users)See README: https://github.com/solven-eu/cleanthat/tree/master/maven
(https://mvnrepository.com/artifact/io.github.solven-eu.cleanthat/cleanthat-maven-plugin)
Features :
.cleanthat
configurationOne liner (even without a pom.xml
):
mvn io.github.solven-eu.cleanthat:cleanthat-maven-plugin:cleanthat
or simply mvn cleanthat:apply
gradle
integration is available through Spotless: https://github.com/diffplug/spotless/tree/main/plugin-gradle#cleanthat
If your repository is hosted by Github.com, get zero-configuration cleaning with our Github App on Github marketplace.
It can configured through a /.cleanthat/cleanthat.yaml
file at the root of the repository (e.g. https://github.com/solven-eu/cleanthat/blob/master/.cleanthat/cleanthat.yaml).
It differs from mvn/gradle integration by fetching only relevant (e.g. modified) files, based on Github Events.
If you integrated Cleanthat through its maven or gradle options, you can get automatic remote cleaning with:
./mvnw spotless:check || ./mvnw spotless:apply && git commit -m"Spotless" && git push
By default, we rely on a safe and consensual configuration. This composite mutators should be integrated by all projects as most projects would benefit from these rules, and most developers would agree this is better style.
Spotless:
cleanthat()
[...]
.addMutator('SafeAndConsensual')
Most integrations enable:
isDraft
mutators (which is false
by default, not to include not-production-ready mutators)Spotless:
cleanthat()
[...]
.addMutator('SafeAndConsensual')
.includeMutator('StreamForEachNestingForLoopToFlatMap')
.excludeMutator('UseCollectionIsEmpty')
.includeDraft(true)
SafeButNotConsensualMutators relates to SafeAndConsensualMutators, but it includes also some rules which may be rejected by a minority of developers.
Spotless:
cleanthat()
[...]
.addMutator('SafeAndConsensual')
.addMutator('SafeButNotConsensual')
SafeButControversialMutators relates to SafeButNotConsensualMutators, but it includes also some rules which may be rejected by a majority of developers. This may be due to eager use of new language syntax.
Spotless:
cleanthat()
[...]
.addMutator('SafeAndConsensual')
.addMutator('SafeButNotConsensual')
.addMutator('SafeButControversial')
One may switch to activate all mutators. This can be achieved through:
Spotless:
cleanthat()
[...]
.addMutator('SafeAndConsensual')
.addMutator('SafeButNotConsensual')
.addMutator('SafeButControversial')
.includeDraft(true)
As of 2022-12, this projects focuses on typical JVM projects. Hence, it enables:
per-single-source file
basisOne major goal of this project is to enable incremental refactoring on a per Pull-Request basis. Hence, the availability of the whole code-base and related binaries (e.g. mvn
dependencies) is limited. Cleanthat focuses on cleaning individual source files.
Limitations :
While we work on integrating CleanThat into Spotless, the Github CleanThat App does not rely on existing Maven (https://github.com/diffplug/spotless/tree/main/plugin-maven) and Gradle (https://github.com/diffplug/spotless/tree/main/plugin-gradle) plugins. The main reason for that is security. Indeed, while it would enable very setup over a project already integrating Spotless, it would open dangerous security breach as one could easily inject custom code as dependency of the maven/gradle plugin, which would enable one to extract CleanThat secrets (Github token, GPG key, etc).
Refactoring .java files would break the code conventions. Hence, any refactoring operation should be followed by a formatting operation. With mvn integration, once should follow the cleanthat step with some mvn formatter step. With github integration, once may rely on CleanThat own .java formatting abilities.
There is multiple good options for formatting Java files:
This software is provided WITHOUT ANY WARRANTY, and is available under the Apache License, Version 2. Any code loss caused by using this plugin is not the responsibility of the author(s). Be sure to use some source repository management system such as GIT before using this plugin.
Contributions are welcome.
An alternative to spring_formatter is eclipse_formatter. It takes as parameter an url like:
A public http(s) URL:
https://raw.githubusercontent.com/solven-eu/pepper/master/static/src/main/resources/eclipse/eclipse_java_code_formatter.xml
A file in local repository (root being assumed based on Git root/Maven top module)
code:/static/src/main/resources/eclipse/eclipse_java_code_formatter.xml
Eclipse Stylesheets can exported to XML through:
CleanThat will accept only configuration with a single profile in them. If multiple profiles are found, we will rely on the first profile.
The maven plugin enables generating an Eclipse Stylesheet minimizing changes over a clean repository:
mvn io.github.solven-eu.cleanthat:cleanthat-maven-plugin:eclipse_formatter-stylesheet
see maven/README.MD
cleanthat
is fairly new. While it is tested on many large projects, you may encounter issues of all kinds. Please report them.