Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Non deterministic output. False positives on Indentation rule #1633

Closed
hick209 opened this issue May 1, 2019 · 10 comments
Closed

Non deterministic output. False positives on Indentation rule #1633

hick209 opened this issue May 1, 2019 · 10 comments

Comments

@hick209
Copy link
Contributor

hick209 commented May 1, 2019

It looks like KtLint sometimes does not pick up indentation rules

Expected Behavior

When running an analysis on a file more than once, the output should be the same if the file contents have not changed.

Observed Behavior

Sometimes it outputs cleanly, no issues, 0 debt
image

Every now and then (and it's not at all rare) if you run the analysis again without touching the file, it will output a whole bunch of Indentation errors.
image

Steps to Reproduce

Create a configuration file with indentation != 4, for example

autoCorrect: false

processors:
  active: false

output-reports:
  active: false

console-reports:
  active: true
  exclude:
  - 'ProjectStatisticsReport'
  - 'ComplexityReport'
  - 'NotificationReport'
  #  - 'FindingsReport'
  - 'BuildFailureReport'

formatting:
  active: true
  android: true
  autoCorrect: true
  Indentation:
    active: true
    autoCorrect: true
    indentSize: 2
    continuationIndentSize: 4
  ParameterListWrapping:
    active: true
    autoCorrect: true
    indentSize: 4

Test in a file that is compliant to the rules, like:

class EmptyBlocks {
  class EmptyClass {}

  fun exceptionHandling() {
    try {
    } finally {
    }
  }
}

Make sure you're adding the formatting plugin, for example, I ran the following commands:

./gradlew detekt-cli:shadowJar detekt-formatting:jar
java -jar detekt-cli/build/libs/detekt-cli-1.0.0-RC14-all.jar -c linter-config.yml -p detekt-formatting/build/libs/detekt-formatting-1.0.0-RC14.jar -i EmptyBlocks.kt

Context

Making sure the output is deterministic and there are no false positives on Indentation issues.

Your Environment

  • Version of detekt used: 1.0.0.RC14 (tested on master as well)
  • Version of Gradle used (if applicable): N/A
  • Operating System and version: macOS
  • Link to your project (if it's a public repository): N/A
@3flex
Copy link
Member

3flex commented May 2, 2019

Can I ask if you can replicate using ktlint directly?

@hick209
Copy link
Contributor Author

hick209 commented May 2, 2019

I've tried but could not reproduce this on KtLint, it always obeyed the provided .editorconfig (tried on the version we're using on 1.0.0.RC14)

@arturbosch
Copy link
Member

Could you post a screenshot with the line and column markers?
If it's 1:1 this could be fixed in master already.

@artem-zinnatullin
Copy link
Contributor

We're hitting same issue on Detekt 1.0.0-RC16

Here is reproducible example with just one file being checked that sometimes passes and sometimes fails on multiple machines in our team: artem-zinnatullin/envoy-mobile@622d501

Passes:

ci/detekt
.

1 kotlin file was analyzed.

Ruleset: comments
Ruleset: complexity
Ruleset: empty-blocks
Ruleset: exceptions
Ruleset: formatting
Ruleset: naming
Ruleset: performance
Ruleset: potential-bugs
Ruleset: style

Complexity Report:
	- 100 lines of code (loc)
	- 81 source lines of code (sloc)
	- 54 logical lines of code (lloc)
	- 4 comment lines of code (cloc)
	- 11 McCabe complexity (mcc)
	- 0 number of total code smells
	- 4 % comment source ratio
	- 203 mcc per 1000 lloc
	- 0 code smells per 1000 lloc

Project Statistics:
	- number of properties: 17
	- number of functions: 6
	- number of classes: 1
	- number of packages: 1
	- number of kt files: 1


detekt finished in 988 ms.

Fails:

ci/detekt
.

1 kotlin file was analyzed.

Ruleset: comments
Ruleset: complexity
Ruleset: empty-blocks
Ruleset: exceptions
Ruleset: formatting - 4h 10min debt
	Indentation - [PsiWhiteSpace] at /Users/azinnatullin/projects/lyft.com/envoy-mobile/examples/kotlin/hello_world/MainActivity.kt:24:34
	Indentation - [PsiWhiteSpace] at /Users/azinnatullin/projects/lyft.com/envoy-mobile/examples/kotlin/hello_world/MainActivity.kt:25:50
	Indentation - [PsiWhiteSpace] at /Users/azinnatullin/projects/lyft.com/envoy-mobile/examples/kotlin/hello_world/MainActivity.kt:26:66
	Indentation - [PsiWhiteSpace] at /Users/azinnatullin/projects/lyft.com/envoy-mobile/examples/kotlin/hello_world/MainActivity.kt:27:36
	Indentation - [PsiWhiteSpace] at /Users/azinnatullin/projects/lyft.com/envoy-mobile/examples/kotlin/hello_world/MainActivity.kt:29:55
	Indentation - [PsiWhiteSpace] at /Users/azinnatullin/projects/lyft.com/envoy-mobile/examples/kotlin/hello_world/MainActivity.kt:30:39
	Indentation - [PsiWhiteSpace] at /Users/azinnatullin/projects/lyft.com/envoy-mobile/examples/kotlin/hello_world/MainActivity.kt:31:43
	Indentation - [PsiWhiteSpace] at /Users/azinnatullin/projects/lyft.com/envoy-mobile/examples/kotlin/hello_world/MainActivity.kt:33:28
	Indentation - [PsiWhiteSpace] at /Users/azinnatullin/projects/lyft.com/envoy-mobile/examples/kotlin/hello_world/MainActivity.kt:35:42
	Indentation - [PsiWhiteSpace] at /Users/azinnatullin/projects/lyft.com/envoy-mobile/examples/kotlin/hello_world/MainActivity.kt:36:19
	Indentation - [PsiWhiteSpace] at /Users/azinnatullin/projects/lyft.com/envoy-mobile/examples/kotlin/hello_world/MainActivity.kt:37:19
	Indentation - [PsiWhiteSpace] at /Users/azinnatullin/projects/lyft.com/envoy-mobile/examples/kotlin/hello_world/MainActivity.kt:38:50
	Indentation - [PsiWhiteSpace] at /Users/azinnatullin/projects/lyft.com/envoy-mobile/examples/kotlin/hello_world/MainActivity.kt:40:68
	Indentation - [PsiWhiteSpace] at /Users/azinnatullin/projects/lyft.com/envoy-mobile/examples/kotlin/hello_world/MainActivity.kt:41:59
	Indentation - [PsiWhiteSpace] at /Users/azinnatullin/projects/lyft.com/envoy-mobile/examples/kotlin/hello_world/MainActivity.kt:43:48
	Indentation - [PsiWhiteSpace] at /Users/azinnatullin/projects/lyft.com/envoy-mobile/examples/kotlin/hello_world/MainActivity.kt:44:35
	Indentation - [PsiWhiteSpace] at /Users/azinnatullin/projects/lyft.com/envoy-mobile/examples/kotlin/hello_world/MainActivity.kt:45:108
	Indentation - [PsiWhiteSpace] at /Users/azinnatullin/projects/lyft.com/envoy-mobile/examples/kotlin/hello_world/MainActivity.kt:46:58
	Indentation - [PsiWhiteSpace] at /Users/azinnatullin/projects/lyft.com/envoy-mobile/examples/kotlin/hello_world/MainActivity.kt:47:19
	Indentation - [PsiWhiteSpace] at /Users/azinnatullin/projects/lyft.com/envoy-mobile/examples/kotlin/hello_world/MainActivity.kt:48:41
	Indentation - [PsiWhiteSpace] at /Users/azinnatullin/projects/lyft.com/envoy-mobile/examples/kotlin/hello_world/MainActivity.kt:50:55
	Indentation - [PsiWhiteSpace] at /Users/azinnatullin/projects/lyft.com/envoy-mobile/examples/kotlin/hello_world/MainActivity.kt:51:44
	Indentation - [PsiWhiteSpace] at /Users/azinnatullin/projects/lyft.com/envoy-mobile/examples/kotlin/hello_world/MainActivity.kt:52:27
	Indentation - [PsiWhiteSpace] at /Users/azinnatullin/projects/lyft.com/envoy-mobile/examples/kotlin/hello_world/MainActivity.kt:53:14
	Indentation - [PsiWhiteSpace] at /Users/azinnatullin/projects/lyft.com/envoy-mobile/examples/kotlin/hello_world/MainActivity.kt:54:39
	Indentation - [PsiWhiteSpace] at /Users/azinnatullin/projects/lyft.com/envoy-mobile/examples/kotlin/hello_world/MainActivity.kt:56:35
	Indentation - [PsiWhiteSpace] at /Users/azinnatullin/projects/lyft.com/envoy-mobile/examples/kotlin/hello_world/MainActivity.kt:58:10
	Indentation - [PsiWhiteSpace] at /Users/azinnatullin/projects/lyft.com/envoy-mobile/examples/kotlin/hello_world/MainActivity.kt:60:29
	Indentation - [PsiWhiteSpace] at /Users/azinnatullin/projects/lyft.com/envoy-mobile/examples/kotlin/hello_world/MainActivity.kt:64:4
	Indentation - [PsiWhiteSpace] at /Users/azinnatullin/projects/lyft.com/envoy-mobile/examples/kotlin/hello_world/MainActivity.kt:66:29
	Indentation - [PsiWhiteSpace] at /Users/azinnatullin/projects/lyft.com/envoy-mobile/examples/kotlin/hello_world/MainActivity.kt:67:22
	Indentation - [PsiWhiteSpace] at /Users/azinnatullin/projects/lyft.com/envoy-mobile/examples/kotlin/hello_world/MainActivity.kt:69:4
	Indentation - [PsiWhiteSpace] at /Users/azinnatullin/projects/lyft.com/envoy-mobile/examples/kotlin/hello_world/MainActivity.kt:71:40
	Indentation - [PsiWhiteSpace] at /Users/azinnatullin/projects/lyft.com/envoy-mobile/examples/kotlin/hello_world/MainActivity.kt:72:17
	Indentation - [PsiWhiteSpace] at /Users/azinnatullin/projects/lyft.com/envoy-mobile/examples/kotlin/hello_world/MainActivity.kt:73:30
	Indentation - [PsiWhiteSpace] at /Users/azinnatullin/projects/lyft.com/envoy-mobile/examples/kotlin/hello_world/MainActivity.kt:74:76
	Indentation - [PsiWhiteSpace] at /Users/azinnatullin/projects/lyft.com/envoy-mobile/examples/kotlin/hello_world/MainActivity.kt:75:65
	Indentation - [PsiWhiteSpace] at /Users/azinnatullin/projects/lyft.com/envoy-mobile/examples/kotlin/hello_world/MainActivity.kt:76:43
	Indentation - [PsiWhiteSpace] at /Users/azinnatullin/projects/lyft.com/envoy-mobile/examples/kotlin/hello_world/MainActivity.kt:77:27
	Indentation - [PsiWhiteSpace] at /Users/azinnatullin/projects/lyft.com/envoy-mobile/examples/kotlin/hello_world/MainActivity.kt:78:77
	Indentation - [PsiWhiteSpace] at /Users/azinnatullin/projects/lyft.com/envoy-mobile/examples/kotlin/hello_world/MainActivity.kt:79:49
	Indentation - [PsiWhiteSpace] at /Users/azinnatullin/projects/lyft.com/envoy-mobile/examples/kotlin/hello_world/MainActivity.kt:80:44
	Indentation - [PsiWhiteSpace] at /Users/azinnatullin/projects/lyft.com/envoy-mobile/examples/kotlin/hello_world/MainActivity.kt:81:28
	Indentation - [PsiWhiteSpace] at /Users/azinnatullin/projects/lyft.com/envoy-mobile/examples/kotlin/hello_world/MainActivity.kt:83:15
	Indentation - [PsiWhiteSpace] at /Users/azinnatullin/projects/lyft.com/envoy-mobile/examples/kotlin/hello_world/MainActivity.kt:86:31
	Indentation - [PsiWhiteSpace] at /Users/azinnatullin/projects/lyft.com/envoy-mobile/examples/kotlin/hello_world/MainActivity.kt:89:4
	Indentation - [PsiWhiteSpace] at /Users/azinnatullin/projects/lyft.com/envoy-mobile/examples/kotlin/hello_world/MainActivity.kt:91:62
	Indentation - [PsiWhiteSpace] at /Users/azinnatullin/projects/lyft.com/envoy-mobile/examples/kotlin/hello_world/MainActivity.kt:93:4
	Indentation - [PsiWhiteSpace] at /Users/azinnatullin/projects/lyft.com/envoy-mobile/examples/kotlin/hello_world/MainActivity.kt:95:81
	Indentation - [PsiWhiteSpace] at /Users/azinnatullin/projects/lyft.com/envoy-mobile/examples/kotlin/hello_world/MainActivity.kt:96:79
Ruleset: naming
Ruleset: performance
Ruleset: potential-bugs
Ruleset: style

Overall debt: 4h 10min

Complexity Report:
	- 100 lines of code (loc)
	- 81 source lines of code (sloc)
	- 54 logical lines of code (lloc)
	- 4 comment lines of code (cloc)
	- 11 McCabe complexity (mcc)
	- 50 number of total code smells
	- 4 % comment source ratio
	- 203 mcc per 1000 lloc
	- 925 code smells per 1000 lloc

Project Statistics:
	- number of properties: 17
	- number of functions: 6
	- number of classes: 1
	- number of packages: 1
	- number of kt files: 1

Build failed with 50 weighted issues (threshold defined was 0).
io.gitlab.arturbosch.detekt.cli.console.BuildFailure: Build failed with 50 weighted issues (threshold defined was 0).

@buildbreaker
Copy link

Are there any updates on this issue? I am looking into integrating detekt with our repo and ci (https://github.com/lyft/envoy-mobile) more 🙂

If you have a workaround for this, I could give that a shot too!

@arturbosch
Copy link
Member

So this is still present for you in newest detekt version?

@hick209
Copy link
Contributor Author

hick209 commented Nov 27, 2019

I'm going to take a look and see if it still repro. I'll give an update about this before the end of the week.

@hick209
Copy link
Contributor Author

hick209 commented Nov 28, 2019

I've just updated to 1.2.0 and this issue is still present, @arturbosch.

Note: I only was able to reproduce it once I tried to lint more than one file. That means:

# All good:
> detekt File1.kt
> detekt File2.kt

# Fails
> detekt File1.kt File2.kt

@arturbosch
Copy link
Member

@hick209 thanks for confirming this. Does it print valid lines/columns for you or just 1:1?
Do you have the same non deterministic results when running the cli of KtLint ?

@arturbosch
Copy link
Member

Possible fixed by #2709.
Feel free to reopen this issue when 1.10.0 is out and the issue is still present.

@arturbosch arturbosch added this to the 1.10.0 milestone May 18, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants