editorconfig-gradle-plugin icon indicating copy to clipboard operation
editorconfig-gradle-plugin copied to clipboard

A Gradle plugin for checking whether project files comply with format rules defined in .editorconfig files and eventually also for fixing the violations

ifdef::env-github[] :warning-caption: :warning: endif::[]

= editorconfig-gradle-plugin

image:https://img.shields.io/badge/license-Apache--2.0-blue[https://github.com/ec4j/editorconfig-gradle-plugin/blob/master/LICENSE] image:https://img.shields.io/github/checks-status/ec4j/editorconfig-gradle-plugin/master?label=build[https://github.com/ec4j/editorconfig-gradle-plugin/actions]

editorconfig-gradle-plugin is a Gradle plugin for checking whether project files comply with format rules defined in http://editorconfig.org/[.editorconfig] files and eventually also for fixing the violations.

WARNING: editorconfig-gradle-plugin is new. Expect issues of all kinds and you should definitely https://github.com/ec4j/editorconfig-gradle-plugin/issues[report] them!

== Basic usage

editorconfig-gradle-plugin requires Java 8+ and Gradle 4.1+.

To apply the plugin, add the following to your project:

[source,gradle]

plugins { ... // Check the latest version at https://plugins.gradle.org/plugin/org.ec4j.editorconfig id 'org.ec4j.editorconfig' version '...' }

After that, you can check whether your source files comply with .editorconfig rules:

[source,shell]

./gradlew editorconfigCheck

In case any violations are detected, you may want to fix them automagically by running

[source,shell]

./gradlew editorconfigFormat

You also may want to bind the editorconfigCheck to some other task existing in your project. E.g. if you have java plugin in your project, binding to check task is quite natural:

[source,gradle]

// build.gradle plugins { id 'java' id 'org.ec4j.editorconfig' version '...' } check.dependsOn editorconfigCheck

== Configuration

There is editorconfig extension object. Its properties are documented in the https://github.com/ec4j/editorconfig-gradle-plugin/tree/master/src/main/java/org/ec4j/gradle/EditorconfigExtension.java[EditorconfigExtension] class.

[source,gradle]

editorconfig {

All files are included by default. Paths or patterns must be relative to the the project root directory.

includes = ['src/**', 'build.gradle']

Exlude some files in addition to the default excludes

Paths or patterns must be relative to the the project root directory.

excludes = ['derby.log', 'LICENSE']

}

== How it works

editorconfig-gradle-plugin is using the same libraries as its sibling editorconfig-maven-plugin: org.ec4j.maven:ec4j-lint-api and org.ec4j.maven:ec4j-linters. They are designed around the Linter interface. https://github.com/ec4j/editorconfig-maven-plugin/blob/master/ec4j-lint-api/src/main/java/org/ec4j/maven/lint/api/Linter.java[Linter] is a processor specialized for some particular file format (such as YAML or XML) for which it can detect whether some particular .editorconfig properties are satisfied and eventually propose a https://github.com/ec4j/editorconfig-maven-plugin/blob/master/ec4j-lint-api/src/main/java/org/ec4j/maven/lint/api/Edit.java[fix] that can be applied automatically.

.Linters available by default: |=== |Class name |Default includes|Default excludes |Supported .editorconfig properties

|https://github.com/ec4j/editorconfig-maven-plugin/blob/master/ec4j-linters/src/main/java/org/ec4j/maven/linters/TextLinter.java[TextLinter] |pass:[**/*] | |https://github.com/editorconfig/editorconfig/wiki/EditorConfig-Properties#end_of_line[end_of_line], https://github.com/editorconfig/editorconfig/wiki/EditorConfig-Properties#trim_trailing_whitespace[trim_trailing_whitespace], https://github.com/editorconfig/editorconfig/wiki/EditorConfig-Properties#insert_final_newline[insert_final_newline]

|https://github.com/ec4j/editorconfig-maven-plugin/blob/master/ec4j-linters/src/main/java/org/ec4j/maven/linters/XmlLinter.java[XmlLinter] |pass:[**/*.xml], pass:[**/*.xsl] | |https://github.com/editorconfig/editorconfig/wiki/EditorConfig-Properties#indent_style[indent_style], https://github.com/editorconfig/editorconfig/wiki/EditorConfig-Properties#indent_size[indent_size] |===

Contributions of further Linters are highly welcome! Please https://github.com/ec4j/editorconfig-maven-plugin/issues[open an issue] when you start working on something to avoid duplicate work.

== How to build

Prerequisites:

  • Java 8+

The most common build with unit tests:

[source,shell]

./gradlew clean build

On Windows:

[source,shell]

.\gradlew.bat clean build

== How to release

[source,shell]

Make sure you are no master

git status

relVersion=... sed -i "s/version = '[^']'/version = '${relVersion}'/" build.gradle.kts git add -A git commit -m "Release ${relVersion}" git tag ${relVersion} ./gradlew publishPlugins --no-daemon --stacktrace git push upstream master git push upstream ${relVersion}

== Misc.

  • All code and contributions are under link:/LICENSE[Apache License]
  • Issues and Discussions: https://github.com/ec4j/editorconfig-gradle-plugin/issues