42 Commits

Author SHA1 Message Date
Brais Gabín
a2734b18c1 Remove Unnecesary @Nested (#4740) 2022-04-25 23:04:26 +02:00
Stieglitz
14c0f11e44 Bump KtLint to 0.44.0 and add UnnecessaryParenthesesBeforeTrailingLamda rule (#4630)
* Bump KtLint to 0.44.0 and add UnnecessaryParenthesesBeforeTrailingLambda rule

* implement new RunAsLateAsPossible and RunOnRootNodeOnly annotations

* use internal ruleShouldOnlyRunOnFileNode method

* revoke line wrap

* fix indentation errors

* deprecate indentSize in ParameterListWrapping.kt

* implement microutilsKotlinLoggingJvm and fake EDITOR_CONFIG_USER_DATA_KEY

* remove duplicate
2022-03-19 12:59:56 +01:00
marschwar
743706fb45 Clean up gradle files for modules migrated to junit (#4516)
Co-authored-by: Markus Schwarz <post@markus-schwarz.net>
2022-01-24 09:21:24 +01:00
marschwar
a1823e6b09 Migrate tests in detekt-metrics to junit (#4511)
* migrate tests in detekt-metrics to junit

* fix compiler warning about possible problems on windows

Co-authored-by: Markus Schwarz <post@markus-schwarz.net>
2022-01-23 22:48:02 +01:00
severn-everett
31520dadf2 Added rule UnnecessaryInnerClass (#4394)
* Added rule UnnecessaryInnerClass

* Addressed Detekt issues; Added test case

* Removed unnecessary code

* Addressing PR comment

* Enabled rule for self-tests on the Detekt library

* Fixing inner class issue in CognitiveComplexity

* Updated code comment
2022-01-22 17:53:01 -08:00
M Schalk
10e8bf55a3 Remove unnecessary map lambda in test code (#4397) 2021-12-26 21:24:21 +01:00
Matthew Haughton
327f1d0022 Use Kotlin's ArrayDeque implementation (#4218) 2021-11-01 20:08:46 +11:00
Steven Jeuris
2f755ea904 ExplicitCollectionElementAccessMethod rule fixes (#4201)
* Include custom get/set operators to ExplicitCollectionElementAccessMethod rule

This actually simplifies code, since any get/set operator can be treated the same; no need to look up type names. `Map.put()` is a type-specific edge case, which can be replaced by `set`, and thus indexed access, when the return value is not needed.

Right now, no check is done whether the return value is use. For both `set` and `put` no code smell should be reported if this is the case.

* Fix #4122: false positive ExplicitCollectionElementAccessMethod for used return values

* Fix new issues raised due to more exhaustive ExplicitElementAccessMethod

Also fixed other tests that were failing on build server.

* Additional edge case tests for ExplicitCollectionElementAccessMethod

This also includes an early out in case types can't be resolved, rather than iterating over supertypes.

* ExplicitCollectionElementAccessMethod rule requires types resolution
2021-10-29 17:50:52 +02:00
Chao Zhang
7b9ee707b7 Report SwallowedException on catchParameter (#4158)
* Report SwallowedException on catchParameter

This improves the ergonomics so that users can minimize the suppression scope.
2021-10-17 17:43:25 -07:00
Chao Zhang
edabb6f2b9 Enable binary compatibility validator for detekt-test and detekt-test-api (#4157)
* Enable binary compatibility validator for detekt-test and detekt-test-api

* Move BaseRule from internal to public API
2021-10-16 16:50:17 +02:00
Matthew Haughton
3e1d7c350d Drop junit-platform-launcher dependency (#4115)
Modern versions of IntelliJ and Gradle do not require this explicit
dependency to be added to the project.
2021-09-20 11:50:35 +10:00
Matthew Haughton
e0aed91293 Remove detekt-bom module (#4043) 2021-09-11 07:27:16 +10:00
Matthew Haughton
fd0cb9096e Migrate buildSrc to composite build (#4090)
This will help reduce build times when changes are made to the precompiled
script plugins used in the build. This is because a change in buildSrc
causes the whole project to become out-of-date [0]. Using an included build
instead works around this problem.

[0] https://docs.gradle.org/7.2/userguide/organizing_gradle_projects.html#sec:build_sources
2021-09-04 23:09:59 +10:00
marschwar
28830b8db5 Enable UnnecessaryLet rule for detekt code base (#4024)
* Enable UnnecessaryLet rule for detekt code base

* baseline parser does not work with new lines

* replace let with private extension function to improve readability

Co-authored-by: Markus Schwarz <post@markus-schwarz.net>
2021-08-10 16:44:31 +02:00
marschwar
53371a29e6 enable those rules from the style rule set that have not violation or obvious fixes (#3998)
* enable those rules from the style rule set that have not violation or obvious fixes

* Enable UseIfEmptyOrIfBlank

Co-authored-by: Markus Schwarz <post@markus-schwarz.net>
2021-08-06 17:54:55 +02:00
marschwar
c356897858 Enable UseEmptyCounterpart for detekt code base (#4000)
Co-authored-by: Markus Schwarz <post@markus-schwarz.net>
2021-08-03 11:36:31 +02:00
marschwar
d81d6a2979 Update mockk (#3937)
Co-authored-by: Markus Schwarz <post@markus-schwarz.net>
2021-07-11 11:55:37 +02:00
M Schalk
3056e069a3 Rename Tests to Spec (#3906)
* Rename Tests to Spec

* Rename DetektMultiplatformSpecTest to Spec

* Use Spek memoization when declaring non trivial types

* Use Spek memoization when declaring non trivial types

* Apply correct code formatting

* Apply correct indentation
2021-06-28 17:10:02 +02:00
dependabot[bot]
5e9a0ad492 Bump byte-buddy from 1.11.2 to 1.11.5 (#3886)
Bumps [byte-buddy](https://github.com/raphw/byte-buddy) from 1.11.2 to 1.11.5.
- [Release notes](https://github.com/raphw/byte-buddy/releases)
- [Changelog](https://github.com/raphw/byte-buddy/blob/master/release-notes.md)
- [Commits](https://github.com/raphw/byte-buddy/compare/byte-buddy-1.11.2...byte-buddy-1.11.5)

---
updated-dependencies:
- dependency-name: net.bytebuddy:byte-buddy
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2021-06-22 12:16:07 +02:00
dependabot[bot]
8f5de1b40a Bump byte-buddy from 1.11.1 to 1.11.2 (#3872)
Bumps [byte-buddy](https://github.com/raphw/byte-buddy) from 1.11.1 to 1.11.2.
- [Release notes](https://github.com/raphw/byte-buddy/releases)
- [Changelog](https://github.com/raphw/byte-buddy/blob/master/release-notes.md)
- [Commits](https://github.com/raphw/byte-buddy/compare/byte-buddy-1.11.1...byte-buddy-1.11.2)

---
updated-dependencies:
- dependency-name: net.bytebuddy:byte-buddy
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2021-06-16 14:37:22 +02:00
dependabot[bot]
155ebec28a Bump byte-buddy from 1.11.0 to 1.11.1 (#3861)
Bumps [byte-buddy](https://github.com/raphw/byte-buddy) from 1.11.0 to 1.11.1.
- [Release notes](https://github.com/raphw/byte-buddy/releases)
- [Changelog](https://github.com/raphw/byte-buddy/blob/master/release-notes.md)
- [Commits](https://github.com/raphw/byte-buddy/compare/byte-buddy-1.11.0...byte-buddy-1.11.1)

---
updated-dependencies:
- dependency-name: net.bytebuddy:byte-buddy
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2021-06-07 11:26:14 +02:00
Matthew Haughton
459d467c43 Build & test on Java 16 (#3698)
* Update Byte Buddy

This transitive dependency of mockk is updated to a version that supports
Java 16

* Skip Android tests on JDK 16+

Required until a compatible version of Android Gradle Plugin is released.

* Build & test on Java 16
2021-05-22 08:19:04 +10:00
Eliezer Graber
22eec6322c Update Kotlin to 1.5 (#3718)
* Update Kotlin to 1.5
* Add workaround for Kotlin 1.5 memory leak in Gradle
* API changes
* Don't treat warnings as errors on the detekt-gradle-plugin module
2021-05-20 23:14:16 -07:00
Matthew Haughton
dc2f3d801c Enable Gradle's type-safe project accessors (#3742) 2021-05-06 20:59:44 +02:00
Brais Gabín
92b6a01903 Apply more formatting rules to our code (#3615)
* Update formatting configuration

* Apply autocorrect to the project

* Format using ktlint 0.41 --experimental

* Minor manual improvements
2021-03-28 10:00:03 -07:00
Brais Gabín
b120ffb058 Don't use deprecated functions (#3452)
* Don't use deprecated api in our samples

* Don't use deprecated functions
2021-02-08 08:36:49 +01:00
Chao Zhang
192697203e Silence IndexOutOfBoundsException in getLineAndColumnInPsiFile() (#3446)
* Silence IndexOutOfBoundsException in getLineAndColumnInPsiFile()

* Suppress detekt errors
2021-02-07 09:37:51 -08:00
Artur Bosch
a04171a1d8 Update Kotlin to 1.4.21 (#3254)
* Update Kotlin to 1.4.20

* Update assertj to 3.18.1

* Fix type V but V!! expected compilation errors with 1.4.20

* Remove workaround for old dokka plugin

* Update to Kotlin 1.4.21

* Use jdk8 compatible mockk version

* Update mock to version 1.10.4

* Specify source and target 1.8 java version for KotlinCompile tasks

* Remove shadowJarExecutable as it does not work with newest Kotlin compiler (1.4.20+)

* Simplify copying jars for CI by reusing copy task

* Update cli guide to always use the zip distribution

* fixup! Simplify copying jars for CI by reusing copy task

Co-authored-by: M Schalk <30376729+schalkms@users.noreply.github.com>
2021-01-19 21:17:58 +01:00
Brais Gabín
945f075af1 Simplify our buildSrc (#3322)
* Move cli gradle configuration to its build.gradle.kts

* Create plugin module so we can add it to each module
2021-01-05 00:06:10 +01:00
M Schalk
2a2d756b53 Remove unnecessary .trimIndent() - housekeeping (#3307)
This statement only added noise to the test specification.
2020-12-19 23:51:58 +01:00
Matthew Haughton
eb11cdfff1 Update RedundantVisibilityModifierRule to find redundant internal modifiers (#3092)
* Report redundant internal modifier on declarations in private or local objects and classes

* Enable RedundantVisibilityModifierRule for detekt self-scans

* Use simpler test example

Co-authored-by: Nicola Corti <corti.nico@gmail.com>

Co-authored-by: Nicola Corti <corti.nico@gmail.com>
2020-09-26 09:34:06 +02:00
Matthew Haughton
be9bc2469b New rule: ClassOrdering (#3088)
* Add ClassOrdering rule
* Enable ClassOrdering rule in detekt
2020-09-20 11:37:40 +10:00
Artur Bosch
e79228638d Run detekt with type resolution analysis on CI (#3015)
* Fix unsafe call issues or use cleaner preconditions

* Run detekt with type resolution analysis on CI

* Update detekt-test/src/main/kotlin/io/gitlab/arturbosch/detekt/test/FindingsAssertions.kt

* Run detekt with type resolution analysis on CI

* Let detekt run only in separate CI job

* Revert change to open; instead suppress issue
2020-08-25 19:50:59 +02:00
Artur Bosch
ce7715f9ce Reduce test discovery for metrics module (#2953) 2020-08-09 17:49:47 +02:00
Artur Bosch
c526ec63f5 Test performance improvements (#2921)
* Use max 4 workers, test discovery slows down parallel workers

* Use a spek snapshot to improve test discovery time

* Introduce an api test fixture for modules needing just an analysis result

* Use api test fixture in html module

* Use api test fixtures in report-xml module

* Use api test fixtures in metrics module

* Use api test fixtures in core module

* Use single-threaded classpath scanning

* Do not create a kotlin environment upfront

* Move mockk usage to execution phase

* Move KtCompiler creation to execution phase

* Move setup code to execution phase in api module

* Move setup code to execution phase in core module

* Move setup code to execution phase in rules-empty module
2020-08-02 12:32:29 +02:00
Artur Bosch
c45791768d Add bindingContext function to FileProcessListener - #2872 (#2900)
* Introduce binding context aware members for FileProcessListener

* Use FileProcessListener with binding context everywhere

* Move deprecation on function level
2020-07-28 08:05:16 +02:00
Artur Bosch
65a49589e4 Extract xml and html reports to own modules (#2750)
* Move xml report to own module

* Extract common complexity report logic to metrics module

This allows to share complexity report logic between the console report and a report-html module.

* Move whichXXX functions from DebugUtils to api module for now

More modules use the detekt version at runtime
and it is nice to have it in plugins as the IntelliJ or Sonar plugin. We should later move this helpers to the tooling-api.

* Extract html report to own module

* Merge all service files when packaging cli fatJar

* Write the detekt version to all jar manifest files

This allows to retrieve the detekt version from any jar at runtime.

* Extract txt report to own module
2020-05-31 15:35:38 +02:00
Artur Bosch
4e65b86cd0 Add cognitive complexity in complexity report (#2727)
* Add metric processor for cognitive complexity

* Add cognitive complexity to complexity report
2020-05-25 12:20:58 +02:00
Artur Bosch
c99f10930b Remove own collectByType function as Kotlin's does not crash anymore (#2726) 2020-05-24 16:06:48 +02:00
Artur Bosch
26465e5078 Move processors to metrics module (#2725)
* Move metric processors to metrics module

* Remove obsolete test files in core resources

* Inline metric test files
2020-05-24 15:18:05 +02:00
Artur Bosch
fdebbc475d Modularize test module (#2720)
* Extract KtCompiler to detekt-parser preparing a minimal test utils module

* Fix potential memory leak in tests not closing settings

* Move parsing and generic test utils to own module

* Do not depend on test module for metrics, gradle plugin and generator modules

* Exclude test-utils from coverage report as we do with test module

* Explicitly depend on core-module in tests
2020-05-23 19:51:26 +02:00
Artur Bosch
5a1cd25a7c Introduce metrics module / implement cognitive complexity (#2679)
* Create new metrics module

* Move lines of code an cyclomatic complexity to metrics module

* Implement cognitive complexity part 1

* Implement cognitive complexity part 2

* Implement cognitive complexity part 3

* Implement cognitive complexity part 4

* Remove trimming to make use of language in string functionality of IDEA
2020-05-15 00:31:04 +02:00