100 Commits

Author SHA1 Message Date
Dominic Zirbel
4b30c6be87 CastToNullableType: allow casting null keyword (#4907)
Fix a false positive for CastToNullableType for casting a literal `null` to a nullable type. This can be necessary when providing null as a function argument where the incoming type is parameterized. In this case using e.g. `null as? String` is less meaningful and generates a compiler warning that the cast cannot succeed.
2022-06-04 13:25:06 +02:00
Nicola Corti
6d477cbb2e Prepare 1.21.0-RC1 (#4900) 2022-06-03 01:10:29 +02:00
Brais Gabín
6d2933dc42 Active rules by default (#4875) 2022-06-01 23:02:12 +02:00
Brais Gabín
a2734b18c1 Remove Unnecesary @Nested (#4740) 2022-04-25 23:04:26 +02:00
Matthew Haughton
be979a0e42 Add missing Test annotations (#4699) 2022-04-09 14:43:06 +01:00
renovate[bot]
ed8b0890c3 Update org.jetbrains.kotlin to v1.6.20 (#4665)
* Update org.jetbrains.kotlin to v1.6.20

* Replace non-exhaustive when with boolean expression

* Replace deprecated imports

* Use -opt-in instead of deprecated -Xopt-in

Co-authored-by: Renovate Bot <bot@renovateapp.com>
Co-authored-by: Matthew Haughton <3flex@users.noreply.github.com>
2022-04-07 08:54:51 +10:00
Thomas Wirth
93d1f4360c Add ElseCaseInsteadOfExhaustiveWhen rule (#4632)
* Add ElseCaseInEnumOrSealedWhen rule

* Adapt to new rule by replacing else cases

* Change rule name, support booleans, improve docs

* Change variable name of boolean condition

* Rename rule to ElseCaseInsteadOfExhaustiveWhen

* Improve rule descriptions

* Suppress rule for outdated documentation method

* Not report sealed class subjects that have an expect modifier

* Fix sample code syntax and not compile mulitplatform code
2022-03-23 19:39:56 +01:00
marschwar
481b3b2428 Fix typo in AvoidReferentialEquality rule description (#4644)
Co-authored-by: Markus Schwarz <post@markus-schwarz.net>
2022-03-19 18:08:13 +00: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
Brais Gabín
dd80d61348 AnnotationSuppressor now resolves Full Qualified Annotation Names without type solving (#4570)
* Simplify AnnotationExcluderSpec

* Improve tests

* Improve tests

* Fix FullQualifiedNameGuesser

* Allow List<Regex> inside AnnotationExcluder to give more options to the callers

* Test with and without type-solving

* Make AnnotationExcluder use the BindingContext when available

* AnnotationSuppressor works with Full Qualified names without type solving

* Address PR comments

* Update detekt-psi-utils/src/test/kotlin/io/github/detekt/psi/internal/FullQualifiedNameGuesserSpec.kt

Co-authored-by: M Schalk <30376729+schalkms@users.noreply.github.com>

* Support star imports

* Improve readability

Co-authored-by: M Schalk <30376729+schalkms@users.noreply.github.com>
2022-02-24 00:03:15 +01:00
Raman Gupta
c854a2ec1f Make DoubleMutabilityForCollection configurable and set a DoubleMutability alias (#4541)
* Configurable double mutability rule

Resolves #4501

* Update default config

* Additional tests via factory and calculation functions

* Add property delegation double mutability negative tests

* Fix import order in dbl mutability test

* Fix code snippet compilation
2022-02-01 23:50:04 +01:00
marschwar
c34f5faec1 Migrate tests in detekt-rules-errorprone to junit (#4523)
* Migrate tests in detekt-rules-errorprone to junit

* change names of classes and function that may be a problem on windows

* WIP: remove test class that is causing issues

* re-add IgnoredReturnValueSpec.kt

* Fix merge

Co-authored-by: Markus Schwarz <post@markus-schwarz.net>
2022-02-01 07:24:31 +01:00
Brais Gabín
2d00cab368 Fix AnnotationExcluder (#4518)
* Implement FullQualifiedNameGuesser

* Remove bad test

* Refactor tests

* Fix AnnotationExcluder

* More exhaustive list of default import classes

* Handle PR comments
2022-01-31 10:19:08 +01:00
marschwar
5176e41200 Fix MaxLineLength violation in IgnoredReturnValue rule (#4539)
Co-authored-by: Markus Schwarz <post@markus-schwarz.net>
2022-01-29 00:38:13 +01:00
Artem Zinnatullin :slowpoke
90ae9ecb07 Add list of functions to skip in IgnoredReturnValue rule (#4434)
* Add list of functions to skip in IgnoredReturnValue rule

* Fix formatting

* Regenerate default detekt config

* Switch to FunctionMatcher, rename property to ignoreFunctionCall

* Update test

* style

* Damn it IJ

* remove testing version

* Update detekt-rules-errorprone/src/main/kotlin/io/gitlab/arturbosch/detekt/rules/bugs/IgnoredReturnValue.kt

Co-authored-by: Chao Zhang <zhangchao6865@gmail.com>

Co-authored-by: Brais Gabín <braisgabin@gmail.com>
Co-authored-by: Chao Zhang <zhangchao6865@gmail.com>
2022-01-28 17:43:48 +01:00
Brais Gabín
a6c84354e6 Improve AnnotationExcluder tests (#4368)
* Add missing deprecation

* Simplify AnnotationExcluder

* Improve tests making them more exhaustive

* Handle the globbing inside AnnotationExcluder

* Update detekt-api/src/main/kotlin/io/gitlab/arturbosch/detekt/api/AnnotationExcluder.kt

Co-authored-by: Chao Zhang <zhangchao6865@gmail.com>

Co-authored-by: Chao Zhang <zhangchao6865@gmail.com>
2022-01-23 10:47:23 -08:00
severn-everett
27205a13f8 Extend CanBeNonNullable rule to check function params (#4431) 2022-01-12 09:54:37 +00:00
Brais Gabín
dcc715d528 Force that no one uses Assertions.assertThat() (#4437) 2022-01-02 21:00:36 +01:00
severn-everett
f6440e3358 [NullCheckOnMutableProperty] Created rule for when a null-check is performed on a mutable property (#4353)
* Created rule for when a null-check is performed on a mutable property

* Fixed Detekt issue

* Added tests to improve code coverage

* Fixed Detekt issues

* Rule will now only fire when the candidate variable is actually referenced within the if-expression block; Moved all relevant inspection code to within a private class to ensure resource cleanup after visiting a Kotlin file

* Consolidated null-checking on candidateFqName

* More consolidation within visitIfExpression; Fixed Detekt issue in NullCheckOnMutablePropertySpec

* Switch to interface type specification in declaration of candidateProperties

* Added checks for multi-clause if-expressions

* Fixed Detekt issue

* Added check for val properties that have getters that return potentially-nullable values

* Address Detekt issue

* Fix failures in test compilation

* Simplified check on getter - will now only report if a val property possesses a getter

* Addressing PR comments

* Fixed typo
2021-12-31 15:17:57 +01:00
M Schalk
634d29a9cb Formulate rule/bugs descriptions consistently (#4418)
* Formulate rule/bugs descriptions consistently

reference #4384

* Apply code review suggestion for msg

Co-authored-by: Chao Zhang <zhangchao6865@gmail.com>

Co-authored-by: Chao Zhang <zhangchao6865@gmail.com>
2021-12-28 02:13:01 +01:00
Brais Gabín
296fbd002d Enable UseAnyOrNoneInsteadOfFind (#4362) 2021-12-17 09:23:53 +11:00
Brais Gabín
d1892dc3e7 Rename DoubleMutabilityInCollectionSpec to DoubleMutabilityForCollectionSpec (#4251) 2021-11-09 18:52:09 +01:00
Matthew Haughton
327f1d0022 Use Kotlin's ArrayDeque implementation (#4218) 2021-11-01 20:08:46 +11:00
Matthew Haughton
7d46753d24 Fix typos and grammar in rule descriptions (#4219) 2021-10-31 21:58:35 -07:00
Matthew Haughton
8e9373439b Simplify where casts used unnecessarily (#4213) 2021-10-31 23:31:25 +11:00
Brais Gabín
63dc501b8c Split InvalidPackageDeclaration to create MissingPackageDeclaration (#4149) 2021-10-15 23:36:04 +01:00
Matthew Haughton
7e4ff22232 Don't report on platform types in NullableToStringCall (#4180)
Fixes #4059
2021-10-13 18:34:21 +11:00
Michał Sikora
0a36aa91d8 Enhance UnconditionalJumpStatementInLoop for breaks and elvis (#4150)
- Do not report break statements
- Do not report conditional assignments
- Don ot report conditional expressions
2021-10-04 20:03:03 +02:00
Brais Gabín
f12697d700 Implement ignoreAnnotated as a core feature (#4102)
* Add missing tests

* Add AnnotationSuppressor

* Use ignoreAnnotated instead of the custom ones from our rules

* Rename LongParameter.ignoreAnnotated to not clash with the general suppression
2021-10-02 10:47:12 +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
Nicola Corti
1e37dfe527 Remove UnnecessarySafeCall safeguard against ErrorType (#3439) 2021-09-17 12:43:44 +02:00
Brais Gabín
cc74174873 Remove annotations from LateinitUsage noncompliant block (#4100) 2021-09-13 15:47:19 +02: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
George Jacob
023fbc697d Fix issue IDs for ReferentialEquality and DoubleMutability (#4040) 2021-08-16 16:20:22 +02:00
Brais Gabín
66049c5bb0 Sort config lists (#4014) 2021-08-11 17:11:58 +02:00
Toshiaki Kameyama
a3ba379720 ImplicitUnitReturnType: don't report when expression body is 'Unit' (#4011) 2021-08-07 13:22:59 +02:00
marschwar
458e786e53 Enable UseOrEmpty (#3999)
Co-authored-by: Markus Schwarz <post@markus-schwarz.net>
Co-authored-by: Nicola Corti <corti.nico@gmail.com>
Co-authored-by: Brais Gabín <braisgabin@gmail.com>
2021-08-06 18:57:24 +01: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
Toshiaki Kameyama
dc4ab03af3 IgnoredReturnValue: fix false negative when annotation is on the class (#3979)
* IgnoredReturnValue: fix false negative when annotation is on the class

* Add a test for nested class
2021-08-01 10:48:04 +02:00
Chao Zhang
6258385fe2 Fix compilation (#3968) 2021-07-23 07:09:09 +02:00
marschwar
1cf138d34c Add AvoidReferentialEquality rule (#3924)
* Add ReferentialEquality rule

* add rule to provider

* update default-detekt-config.yml

* extract method to enable guard clauses

* Update detekt-rules-errorprone/src/main/kotlin/io/gitlab/arturbosch/detekt/rules/bugs/ReferentialEquality.kt

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

* Update detekt-rules-errorprone/src/main/kotlin/io/gitlab/arturbosch/detekt/rules/bugs/ReferentialEquality.kt

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

* fix name of test

* improve tests

* rename rule to AvoidReferentialEquality

* introduce SimpleGlob

* rename config property to forbiddenTypePatterns

* remove debug code

* Add test

* update config property in yaml

* add description to issue

* use quotes in default config

Co-authored-by: Markus Schwarz <post@markus-schwarz.net>
Co-authored-by: Nicola Corti <corti.nico@gmail.com>
2021-07-22 21:40:29 +01:00
marschwar
c5850c4f53 Add config delegate to public api (#3891)
* move ConfigProperty to public api

* add config to api

* use config property in example rule

* remove ThresholdRule from extension guide

* mark LazyRegex as deprecated

* suppress deprecation warning

Co-authored-by: Markus Schwarz <post@markus-schwarz.net>
2021-07-18 13:43:50 -07:00
Nicola Corti
0ad69d5f5f Bump Kotlin to 1.5.21 (#3956) 2021-07-14 12:36:10 +02:00
Nicola Corti
2a9bbd0e2d Revert "Bump Kotlin to v1.5.20 (#3921)" (#3941)
This reverts commit 7f2a4787a9.
2021-07-07 23:48:17 +02:00
M Schalk
7f2a4787a9 Bump Kotlin to v1.5.20 (#3921) 2021-06-30 11:18:47 +02:00
Toshiaki Kameyama
2191a1aebf Fix Deprecation rule message (#3885) 2021-06-22 12:15:27 +02:00
Nicola Corti
158744fd2a Rename MapGetWithNotNullAsserSpec to follow test convention (#3878) 2021-06-16 23:43:51 +02:00
Chao Zhang
36bc5f5e56 Use @Configuration for rules-errorprone (#3772) 2021-05-16 14:42:20 -07:00
Nicola Corti
1c1dd07126 Fix crash for DontDowncastCollectionTypes on Synthetic types (#3776) 2021-05-14 12:59:53 +02:00