Skip to content

Commit

Permalink
Update documentation and migration for milestone 12 - #105
Browse files Browse the repository at this point in the history
  • Loading branch information
arturbosch committed Jun 22, 2017
1 parent df7ff15 commit 87fc840
Show file tree
Hide file tree
Showing 5 changed files with 134 additions and 43 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

#### M12

- Suppress for TooManyFunctions is not considered in detekt - [#108](https://api.github.com/repos/arturbosch/detekt/issues/108)
- Update documentation and migration guide for M12 - [#105](https://api.github.com/repos/arturbosch/detekt/issues/105)
- NoDocOverPublicClass always reported for objects - [#104](https://api.github.com/repos/arturbosch/detekt/issues/104)
- Script to generate release notes from milestone - [#102](https://api.github.com/repos/arturbosch/detekt/issues/102)
- Encapsulate common fields of Rule and Finding in Issue class - [#97](https://api.github.com/repos/arturbosch/detekt/issues/97)
- Separate findings logic from rule logic - [#93](https://api.github.com/repos/arturbosch/detekt/issues/93)
Expand All @@ -14,6 +17,8 @@
- Not all return keywords are removed when using ExpressionBodySyntax quickfix - [#58](https://api.github.com/repos/arturbosch/detekt/issues/58)
- Rule: Max line length - [#56](https://api.github.com/repos/arturbosch/detekt/issues/56)
- Rule: SingleExpression statements with multiple return paths - [#45](https://api.github.com/repos/arturbosch/detekt/issues/45)
- Allow different naming conventions for tests - [#24](https://api.github.com/repos/arturbosch/detekt/issues/24)


See all issues at: [M12](https://api.github.com/repos/arturbosch/detekt/milestones/8)

Expand Down
66 changes: 65 additions & 1 deletion MIGRATION_GUIDE.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,73 @@
# Migration Guide

### M11 -> M12

##### CLI

- No break just extra notification that you can pass now more than one configuration file within the `--config` and `--config-resource` parameters

This allows overriding certain configuration parameters in the base configuration (left-most config)

##### Gradle Plugin

- the detekt extension is now aware of `configuration profiles`
- non default or 'main' profile, needs to be specified like `gradle detektCheck -Ddetekt.profile=[profile-name]`

Instead of writing something like

```groovy
detekt {
version = "1.0.0.M11"
input = "$project.projectDir/src"
filters = '.*/test/.*'
config = "$project.projectDir/detekt-config.yml"
output = "$project.projectDir/output.xml"
idea {
path = "$USER_HOME/.idea"
codeStyleScheme = "$USER_HOME/.idea/idea-code-style.xml"
inspectionsProfile = "$USER_HOME/.idea/inspect.xml"
mask = "*.kt,"
}
}
```

you have to put a `profile`-closure around the parameters

```groovy
detekt {
profile("main") {
version = "1.0.0.M11"
input = "$project.projectDir/src"
filters = '.*/test/.*'
config = "$project.projectDir/detekt-config.yml"
output = "$project.projectDir/output.xml"
}
profile("test") {
filters = ".*/src/main/kotlin/.*"
config = "$project.projectDir/detekt-test-config.yml"
}
idea {
path = "$USER_HOME/.idea"
codeStyleScheme = "$USER_HOME/.idea/idea-code-style.xml"
inspectionsProfile = "$USER_HOME/.idea/inspect.xml"
mask = "*.kt,"
}
}
```

This allows you too configure `detekt-rules` specific for each module. Also allowing to have different configurations for production or test code.

##### Renamings

- `NoDocOverPublicClass` -> `UndocumentedPublicClass`
- `NoDocOverPublicMethod` -> `UndocumentedPublicFunction`

Rename this id's in your configuration

### M10 -> M11

- `detekt` task was renamed to `detektCheck` (gradle-plugin)

### M9 -> M10

- code-smell rule set was renamed to complexity rule set (config)
- `code-smell` rule set was renamed to `complexity` rule set (config)
100 changes: 61 additions & 39 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,9 @@ It operates on the abstract syntax tree provided by the Kotlin compiler.
- extensible by own rule sets and `FileProcessListener's`
- format your code with the formatting rule set
- code Smell baseline and ignore lists for legacy projects
- **NEW** - [gradle plugin](#gradleplugin) for code analysis, formatting and import migration

- [gradle plugin](#gradleplugin) for code analysis, formatting and import migration
- **NEW** - gradle tasks to use local `intellij` distribution for [formatting and inspecting](#idea) kotlin code
- **NEW** - optionally configure detekt for each sub module by using [profiles](#closure) (gradle-plugin)

### Table of contents
1. [Commandline interface](#build)
Expand Down Expand Up @@ -64,6 +65,9 @@ Usage: detekt [options]
Path to the config file (path/to/config.yml).
--config-resource, -cr
Path to the config resource on detekt's classpath (path/to/config.yml).
--create-baseline, -cb
Treats current analysis findings as a smell baseline for further detekt runs.
Default: false
--debug, -d
Debugs given ktFile by printing its elements.
Default: false
Expand Down Expand Up @@ -100,8 +104,8 @@ Usage: detekt [options]
Default: false
```

`project` can either be a directory or a single Kotlin file.
The currently only supported configuration format is yaml. `config` should point to one.
`--project` can either be a directory or a single Kotlin file.
The currently only supported configuration format is yaml. `--config` should point to one. Generating a default configuration file is as easy as using the `--generate-config` parameter.
`filters` can be used for example to exclude all test directories.
With `rules` you can point to additional ruleset.jar's creating by yourself or others.
More on this topic see section _Custom RuleSets_.
Expand All @@ -126,9 +130,11 @@ plugins {
detekt {
version = "1.0.0.[version]"
input = "$input/src/main/kotlin"
config = "project.projectDir/detekt.yml"
filters = ".*test.*,.*/resources/.*,.*/tmp/.*"
profile("main") {
input = "$input/src/main/kotlin"
config = "project.projectDir/detekt.yml"
filters = ".*test.*,.*/resources/.*,.*/tmp/.*"
}
}
```

Expand All @@ -149,9 +155,11 @@ apply plugin: "io.gitlab.arturbosch.detekt"
detekt {
version = "1.0.0.[version]"
input = "$input/src/main/kotlin"
config = "$project.projectDir/detekt.yml"
filters = ".*test.*,.*/resources/.*,.*/tmp/.*"
profile("main") {
input = "$input/src/main/kotlin"
config = "project.projectDir/detekt.yml"
filters = ".*test.*,.*/resources/.*,.*/tmp/.*"
}
}
```

Expand All @@ -172,9 +180,11 @@ plugins {

configure<DetektExtension> {
version = "1.0.0.[version]"
input = "$input/src/main/kotlin"
config = "${project.projectDir}/detekt.yml"
filters = ".*test.*,.*/resources/.*,.*/tmp/.*"
profile("main") {
input = "$input/src/main/kotlin"
config = "${project.projectDir}/detekt.yml"
filters = ".*test.*,.*/resources/.*,.*/tmp/.*"
}
}
```

Expand All @@ -188,7 +198,37 @@ configure<DetektExtension> {
- `detektIdeaFormat` - Uses a local `idea` installation to format your kotlin (and other) code according to the specified `code-style.xml`.
- `detektIdeaInspect` Uses a local `idea` installation to run inspections on your kotlin (and other) code according to the specified `inspections.xml` profile.

##### Configure a local idea for detekt
##### <a name="closure">Options for detekt configuration closure</a>

```groovy
detekt {
version = "1.0.0.[version]" // Specify latest detekt version, when unspecified plugins default version is used
// A profile basically abstracts over the argument vector passed to detekt.
// Different profiles can be specified and used for different sub modules or testing code.
profile("main") {
input = "$input/src/main/kotlin" // input is pre configured to 'project.projectDir.absolutePath'
config = "$project.projectDir/detekt.yml" // Use $project.projectDir or to navigate inside your project
configResource = "/detekt.yml" // Use this parameter instead of config if your detekt yaml file is inside your resources. Is needed for multi project maven tasks.
filters = ".*test.*, .*/resources/.*" // What paths to exclude? Use comma oder semicolon to separate
rulesets = "other/optional/ruleset.jar" // Custom rule sets can be linked to this, use comma oder semicolon to separate, remove if unused.
disableDefaultRuleSets = false // Disables the default rule set. Just use detekt as the detection engine with your custom rule sets.
output = "$project.projectDir/reports/detekt.xml" // If present, prints all findings into that file.
outputFormat = "xml" // Can be either 'xml' or 'plain', default is 'xml'
baseline = "$project.projectDir/reports/baseline.xml" // If present all current findings are saved in a baseline.xml to only consider new code smells for further runs.
parallel = true // Use this flag if your project has more than 200 files.
useTabs = false // Turns off the indentation check for spaces if true, default is false and does not need to be specified
}
// Definines a secondary profile `gradle detektCheck -Ddetekt.profile=override` will use this profile.
// The main profile gets always loaded but specified profiles override main profiles parameters.
profile("override") {
config = "$project.projectDir/detekt-test-config.yml"
}
}
```

##### <a name="idea">Configure a local idea for detekt</a>

- download the community edition of [intellij](https://www.jetbrains.com/idea/download/)
- extract the file to your preferred location eg. `~/.idea`
Expand All @@ -200,42 +240,24 @@ configure<DetektExtension> {
```groovy
String USER_HOME = System.getProperty("user.home")
detekt {
input = "$input/src/main/kotlin"
output = "$input/reports/report.xml"
outputFormat = "xml"
detekt {
profile("main") {
input = "$project.projectDir/src/main/kotlin"
output = "$project.projectDir/reports/report.xml"
outputFormat = "xml"
}
idea {
path = "$USER_HOME/.idea"
codeStyleScheme = "$USER_HOME/.idea/idea-code-style.xml"
inspectionsProfile = "$USER_HOME/.idea/inspect.xml"
report = "$input/reports"
report = "project.projectDir/reports"
mask = "*.kt,"
}
}
```

For more information on using idea as a headless formatting/inspection tool see [here](https://www.jetbrains.com/help/idea/working-with-intellij-idea-features-from-command-line.html).

##### <a name="closure">Options for detekt configuration closure</a>

```groovy
detekt {
version = "1.0.0.[version]" // Specify latest detekt version, when unspecified plugins default version is used
input = "$input/src/main/kotlin" // input is pre configured to 'project.projectDir.absolutePath'
config = "$project.projectDir/detekt.yml" // Use $project.projectDir or to navigate inside your project
configResource = "/detekt.yml" // Use this parameter instead of config if your detekt yaml file is inside your resources. Is needed for multi project maven tasks.
filters = ".*test.*, .*/resources/.*" // What paths to exclude? Use comma oder semicolon to separate
rulesets = "other/optional/ruleset.jar" // Custom rule sets can be linked to this, use comma oder semicolon to separate, remove if unused.
disableDefaultRuleSets = false // Disables the default rule set. Just use detekt as the detection engine with your custom rule sets.
output = "$project.projectDir/reports/detekt.xml" // If present, prints all findings into that file.
outputFormat = "xml" // Can be either 'xml' or 'plain'
baseline = "$project.projectDir/reports/baseline.xml" // If present all current findings are saved in a baseline.xml to only consider new code smells for further runs.
parallel = true // Use this flag if your project has more than 200 files.
useTabs = false // Turns of indentation check for spaces if true, default is false and does not need to be specified
generateConfig = true // Use this flag to generate a default configuration yaml file which can be used for further tuning detekt. Remove this after the generation
}
```

##### <a name="migration">Migration</a>

Migration rules can be configured in your `detekt.yml` file. For now only migration of imports is supported.
Expand Down
2 changes: 1 addition & 1 deletion github-milestone-report.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -42,5 +42,5 @@ println(footer)

println()
def tempFile = File.createTempFile(repo, "_$milestone.title")
tempFile.write("$section\n$issuesString\nfooter")
tempFile.write("$section\n$issuesString\n$footer")
println("Content saved to $tempFile.path")
4 changes: 2 additions & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
detektVersion=1.0.0.M12-SNAPSHOT
detektGradleVersion=1.0.0.M12-SNAPSHOT
detektVersion=1.0.0.M12
detektGradleVersion=1.0.0.M12
usedDetektGradlePlugin=1.0.0.M11
kotlinVersion=1.1.2
spekVersion=1.1.1
Expand Down

0 comments on commit 87fc840

Please sign in to comment.