Skip to content

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

License

Apache-2.0, Unknown licenses found

Licenses found

Apache-2.0
LICENSE
Unknown
license-header-template.txt
Notifications You must be signed in to change notification settings

schowave/editorconfig-gradle-plugin

 
 

Repository files navigation

editorconfig-gradle-plugin

License Travis CI build status AppVeyor Windows CI build status

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

⚠️
editorconfig-gradle-plugin is new. Expect issues of all kinds and you should definitely report them!

Basic usage

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

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

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:

./gradlew editorconfigCheck

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

./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:

// 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 EditorconfigExtension class.

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. 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 fix that can be applied automatically.

Table 1. Linters available by default:
Class name Default includes Default excludes Supported .editorconfig properties

TextLinter

**/*

end_of_line, trim_trailing_whitespace, insert_final_newline

XmlLinter

**/*.xml, **/*.xsl

indent_style, indent_size

Contributions of further Linters are highly welcome! Please open an issue when you start working on something to avoid duplicate work.

How to build

Prerequisites:

  • Java 7+

The most common build with unit tests:

./gradlew clean build

On Windows:

.\gradlew.bat clean build

How to release

# Make sure you are no master
git status

relVersion=...
sed -i "s/version = '[^']'/version = '${relVersion}'/" build.gradle
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.

About

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

Resources

License

Apache-2.0, Unknown licenses found

Licenses found

Apache-2.0
LICENSE
Unknown
license-header-template.txt

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Java 100.0%