Giter Club home page Giter Club logo

cleanthat's Introduction

CleanThat

Purpose

Cleanthat is a project enabling automatic code cleaning, from formatting to refactoring.

List of mutators

javadoc

MUTATORS.generated.MD

Motivation

The point of this project is to enable automatic cleaning of your code-base. By cleaning, we include :

  1. formatting (with an Eclipse stylesheet, Google-Java-Format, etc)
  2. linting (given any IMutator)
  3. refactoring (WIP)
  4. migrating (from JUnit4 to JUnit5)

As of 2022-12, it focuses on Java projects, but enabling formatting various languages through Spotless.

Related projects:

Changes

See CHANGES.MD

  • 2023-03-23: 2.12 Latest release
  • ...
  • 2023-02-06: 2.0 Major Release leveraging from/to Spotless
  • ...
  • 2021-08-12: 1.0 Initial Release

Language Coverage

As a Robot

Cleanthat Robot is currently compatible with the following languages:

  • java (Spotless and OpenRewrite)
  • pom.xml (Spotless)
  • json (Spotless)
  • xml (Spotless)
  • yaml (Spotless)
  • kotlin (Spotless)

see FormatterFactory

As a library

Cleanthat Refactorer is currently compatible with the following languages:

  • java (Cleanthat)
  • java (OpenRewrite)
  • java (Eclipse Cleanup)

Limitations

  • CleanThat processes files individually, which indices limited Type resolution. This enables cleaning files on a per-impacted-file basis (e.g. in a Github Pull-Request).
  • The type resolution may be lifted through cleanthat-maven-plugin (TODO)
  • The project jhas poor support of charset others than UTF-8

Installation

Maven (Free)

Spotless mvn plugin (for pure mvn users)

mvn integration is available through Spotless: https://github.com/diffplug/spotless/tree/main/plugin-maven#cleanthat

Maven central

One can then clean its codebase with mvn spotless:apply

Cleanthat mvn plugin (for GitHub App users)

See README: https://github.com/solven-eu/cleanthat/tree/master/maven

Maven Central(https://mvnrepository.com/artifact/io.github.solven-eu.cleanthat/cleanthat-maven-plugin)

Features :

  • Apply full refactoring as it would be executed by the Github App, based on .cleanthat configuration
  • Generate automatically an optimal Eclipse stylesheet based on your code-case

One liner (even without a pom.xml):

    mvn io.github.solven-eu.cleanthat:cleanthat-maven-plugin:cleanthat

or simply mvn cleanthat:apply

Gradle (Free)

gradle integration is available through Spotless: https://github.com/diffplug/spotless/tree/main/plugin-gradle#cleanthat

Gradle plugin

Github App (Free+Paid)

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.

Key Features

  • Automatic generation of the initial configuration
  • Clean branches which are not protected and head of a PullRequest

Example configurations of happy Users:

CI/CD (Github Actions, CircleCI, Jenkins, etc)

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

Key design decisions

As of 2022-12, this projects focuses on typical JVM projects. Hence, it enables:

  • Advanced Linting of .java files
  • Advanced Formatting of .java files (through Spotless)
  • Advanced Formatting of pom.xml files (through Spotless)
  • Basic Formatting of .json, .xml, etc files (through Spotless)

Refactoring on a per-single-source file basis

One 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 :

  • Can not refactor based on multiple source files information (e.g. type definition in a different file)
  • Can not refactor based on binaries information (e.g. type definition from dependencies)
  • Can refactor based on standard JRE classpath

Github App does not rely on Maven and Gradle

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).

About Advanced Formatting of .java files

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:

Last considerations

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.

Using Eclipse Formatter

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:

  • Go into Preferences
  • Select Java > Code Style > Formatter
  • Click on 'Export All'

CleanThat will accept only configuration with a single profile in them. If multiple profiles are found, we will rely on the first profile.

Automatic generation of Eclipse Stylesheet

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

Disclaimer

cleanthat is fairly new. While it is tested on many large projects, you may encounter issues of all kinds. Please report them.

codecov

cleanthat's People

Contributors

blacelle avatar renovate-bot avatar renovate[bot] avatar cleanthat[bot] avatar benoitmitrust avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.