Skip to content

Java, XML, JSON and yaml formatter based on Intellij CE formatter with editorconfig support. Available as CLI or ec4j linter for Maven and Gradle integration

License

Notifications You must be signed in to change notification settings

kamil-perczynski/javalint

Repository files navigation

Banner

Javalint

Java, XML, JSON and YAML formatter based on Intellij CE formatter, inspired by ktlint.

Distributed as command-line cli tool and a Linter implementation compatible with editorconfig-maven-plugin, editorconfig-gradle-plugin.

Key features

  • .editorconfig support
  • Compatibility with all settings present in Intellij CE
  • Maven and Gradle integration with editorconfig-maven-plugin, editorconfig-gradle-plugin
  • Executable jar
  • No configuration required

CLI usage

CLI provides similar API as Ktlint CLI.

Basic usage:

$ javalint               # checks formatting for all the files in this directory
$ javalint src/**/*.java  # checks all *.java files in src directory
$ javalint -F            # fixes formatting for all the files in this directory
$ javalint --help        # print detailed usage information

Maven integration

Code sample

Following configuration will check all files formatting (except target, build, node_modules folders).

<project>
  <!-- Add ec4j maven plugin -->
  <plugins>
    <plugin>
      <groupId>org.ec4j.maven</groupId>
      <artifactId>editorconfig-maven-plugin</artifactId>
      <version>0.1.3</version>

      <!-- Add javalint-ec4j-linter -->
      <dependencies>
        <dependency>
          <groupId>io.github.kamil-perczynski</groupId>
          <artifactId>javalint-ec4j-linter</artifactId>
          <version>1.3</version>
        </dependency>
      </dependencies>

      <executions>
        <execution>
          <id>check</id>
          <phase>validate</phase>
          <goals>
            <goal>check</goal>
          </goals>
        </execution>
      </executions>

      <!-- Disable default linters from ec4j -->
      <configuration>
        <linters>
          <linter>
            <id>org.ec4j.linters.TextLinter</id>
            <enabled>false</enabled>
          </linter>
          <linter>
            <id>org.ec4j.linters.XmlLinter</id>
            <enabled>false</enabled>
          </linter>
        </linters>
      </configuration>
    </plugin>
  </plugins>
</project>

Gradle integration

// build.gradle.kts

// add editorconfig plugin
plugins {
  java
  application
  id("org.ec4j.editorconfig") version "0.1.0"
}

dependencies {
  // other dependencies...
  // add javalint-ec4j-linter dependency in editorconfig scope
  editorconfig("io.github.kamil-perczynski:javalint-ec4j-linter:1.3")
}

// disable default ec4j linters
// optional: disable linting of the .profileconfig.json file
editorconfig {
  excludes = listOf(".profileconfig.json")
  linters = listOf(
    LinterConfig().also {
      it.isEnabled = false
      it.className = "org.ec4j.linters.TextLinter"
    },
    LinterConfig().also {
      it.isEnabled = false
      it.className = "org.ec4j.linters.XmlLinter"
    }
  )
}

tasks.check {
  dependsOn("editorconfigCheck")
}

Legal Notices

This software includes code from IntelliJ IDEA CE Copyright (C) JetBrains s.r.o. https://www.jetbrains.com/idea/


This project is not affiliated with JetBrains.

About

Java, XML, JSON and yaml formatter based on Intellij CE formatter with editorconfig support. Available as CLI or ec4j linter for Maven and Gradle integration

Topics

Resources

License

Stars

Watchers

Forks