Skip to content

Commit

Permalink
Add spotless code formatter configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
dai0304 committed Jul 14, 2016
1 parent 725e964 commit 9f1c8c4
Show file tree
Hide file tree
Showing 5 changed files with 383 additions and 24 deletions.
54 changes: 43 additions & 11 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@ buildscript {
maven { url "https://plugins.gradle.org/m2/" }
}
dependencies {
classpath 'nl.javadude.gradle.plugins:license-gradle-plugin:0.7.0'
classpath "com.jfrog.bintray.gradle:gradle-bintray-plugin:1.2"
classpath "com.gradle.publish:plugin-publish-plugin:0.9.1"
classpath "com.diffplug.gradle.spotless:spotless:1.3.3"
}
}

apply plugin: "com.gradle.plugin-publish"
apply plugin: "com.diffplug.gradle.spotless"
apply plugin: "java"
apply plugin: "license"
apply plugin: "eclipse"
apply plugin: "idea"

Expand All @@ -32,6 +32,47 @@ ext {
defaultEncoding = "UTF-8"
}

// ======== spotless ========

spotless {
java {
licenseHeaderFile 'gradle/spotless.license.java'
importOrderFile 'gradle/spotless.importorder'
eclipseFormatFile 'gradle/spotless.eclipseformat.xml'

// Eclipse formatter screws up long literals with underscores inside of annotations (see issue #14)
// @Max(value = 9_999_999 L) // what Eclipse does
// @Max(value = 9_999_999L) // what I wish Eclipse did
custom 'Long literal fix', { it.replaceAll('([0-9_]+) [Ll]', '$1L') }

// Eclipse formatter puts excess whitespace after lambda blocks
// funcThatTakesLambdas(x -> {} , y -> {} ) // what Eclipse does
// funcThatTakesLambdas(x -> {}, y -> {}) // what I wish Eclipse did
custom 'Lambda fix', { it.replace('} )', '})').replace('} ,', '},') }

indentWithTabs()
endWithNewline()

customReplaceRegex 'Add space before comment asterisk', '^(\\t*)\\*', '$1 *'
// customReplaceRegex 'Remove indent before line comment', '^\\t*//', '//'
}

// this will create two tasks: spotlessMiscCheck and spotlessMiscApply
format 'misc', {
// target determines which files this format will apply to
// - if you pass a string or a list of strings, they will be treated
// as 'include' parameters to a fileTree in the root directory
// - if you pass a FileCollection, it will pass through untouched
// e.g. project.files('build.gradle', 'settings.gradle')
// - if you pass anything else, it will be sent to project.files(yourArg)
target '**/*.gradle', '**/*.md', '**/.gitignore'

// spotless has built-in rules for the most basic formatting tasks
indentWithTabs() // or spaces. Takes an integer argument if you don't like 4
endWithNewline()
}
}

// ======== create source and javadoc bundles ========

task sourcesJar(type: Jar, dependsOn: classes) {
Expand Down Expand Up @@ -113,15 +154,6 @@ task wrapper(type: Wrapper) {
gradleVersion = "2.5"
}

// ======== License =======
license {
ext.year = Calendar.getInstance().get(Calendar.YEAR)
header file("copyright/HEADER")
strictCheck true
mapping {
java = "SLASHSTAR_STYLE"
}
}

// ======== IDE ========
eclipse {
Expand Down
13 changes: 0 additions & 13 deletions copyright/HEADER

This file was deleted.

Loading

0 comments on commit 9f1c8c4

Please sign in to comment.