Commit Graph

4301 Commits

Author SHA1 Message Date
Matthew Haughton
e33878ce7b Drop dependency-analysis plugin (#4946)
This is blocking update to Kotlin 1.7.0 (#4821)
2022-06-12 08:31:28 +10:00
renovate[bot]
2f75d2c318 Update plugin com.gradle.enterprise to v3.10.2 (#4939)
Co-authored-by: Renovate Bot <bot@renovateapp.com>
2022-06-09 20:14:57 -07:00
Artur Bosch
7c485f5c3d Provide a priority field for DetektProvider so tools can easier choose their provider implemention in tests for example (#4923) 2022-06-09 00:34:47 +02:00
renovate[bot]
cdf487a94b Update plugin dependencyAnalysis to v1.5.0 (#4933)
Co-authored-by: Renovate Bot <bot@renovateapp.com>
2022-06-08 08:52:22 +02:00
Brais Gabín
15012d716c Add missing redirect (#4931) 2022-06-07 22:30:59 +01:00
Toshiaki Kameyama
0ecebd4f61 UnusedPrivateMember: highlight declaration name (#4928) 2022-06-07 21:14:51 +02:00
Nicola Corti
9146e4d1f6 Fix various rendering problem on the formatting ruleset (#4911) 2022-06-04 13:02:11 +01:00
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
renovate[bot]
ae7b41b571 Update plugin com.gradle.common-custom-user-data-gradle-plugin to v1.7.2 (#4897)
Co-authored-by: Renovate Bot <bot@renovateapp.com>
2022-06-04 13:23:37 +02:00
Gabriel Freitas Vasconcelos
5baf1f6955 Creates ForbiddenSuppress rule (#4899)
This rule is based on discussion #4890.

Checks for suppression of one or more rules that have been decided to
never be suppressed within a code base. For example, if we've set
MaximumLineLength to a value, every file must be compliant, and if there
is a special case where compliance is discouraged, we can simply exclude
this file within YML configuration.

This rule cannot prevent itself from being suppressed, but should serve
to discourage the over use of `@Suppress` annotations.
2022-06-03 17:19:23 +01:00
Nicola Corti
1eaa34b30d Cleanup the githubRelease task (#4903) 2022-06-03 15:02:41 +02:00
Nicola Corti
010f5edaf2 Remove the docs folder as it's unnecessary (#4904) 2022-06-03 15:01:42 +02:00
Nicola Corti
ad9ef16bb9 Correct the Rules Documentation label (#4901) 2022-06-03 01:11:56 +02:00
Nicola Corti
6d477cbb2e Prepare 1.21.0-RC1 (#4900) v1.21.0-RC1 2022-06-03 01:10:29 +02:00
renovate[bot]
fae633bab1 Update plugin dependencyAnalysis to v1.4.0 (#4898)
Co-authored-by: Renovate Bot <bot@renovateapp.com>
2022-06-03 08:24:24 +10:00
schalkms
c4fc4ff1b5 Remove unused code (#4902) 2022-06-02 22:57:18 +02:00
Matthew Haughton
1258c2fe82 Add dependency-analysis plugin and implement some recommendations (#4798)
Co-authored-by: schalkms <30376729+schalkms@users.noreply.github.com>
2022-06-02 13:19:44 +01:00
Peter
8e27a307ee NestedScopeFunctions - Add rule for nested scope functions (#4788) 2022-06-02 13:18:16 +01:00
marschwar
23a03e190d Allow additionalJavaSourceRootPaths to be defined on @KotlinCoreEnvironmentTest (#4771)
* Allow additionalJavaSourceRootPaths to be defined on @KotlinCoreEnvironmentTest

* update api

* Rename top level nested classes to WithDefaultSources and WithAdditionalJavaSources

* fix compilation error in java < 11

* fix upstream merge

* fix: do not attempt to compile snippet with java class from resource

* manually fix indentation of test snippets

Co-authored-by: Markus Schwarz <post@markus-schwarz.net>
2022-06-02 00:07:49 +02:00
schalkms
eb7c335f9e Reformat Markdown files to comply with the spec (#4891) 2022-06-02 00:00:56 +02:00
schalkms
4cc4051706 Declare nested test classes as non-static (#4894)
The @Nested annotation cannot be used on static classes.
2022-06-01 23:51:44 +02:00
schalkms
5c41ebb2b6 Simplify regular expressions (#4893)
* Simplify regular expressions

* Inline class declaration

Co-authored-by: Brais Gabín <braisgabin@gmail.com>
2022-06-01 23:38:45 +02:00
schalkms
8b365028ec Remove redundant character escape in RegExp (#4892) 2022-06-01 23:08:27 +02:00
Brais Gabín
6d2933dc42 Active rules by default (#4875) 2022-06-01 23:02:12 +02:00
schalkms
8fbcf20591 Remove deprecated usages in gradle-plugin test (#4889) 2022-06-01 22:57:37 +02:00
marschwar
16b66586bc Allow users and rule authors to specify a reason per configured value (#4611)
* implement first idea on values with reasons

* have ExplainedValues implement List by delegation

* Parse explained value defaults

* fix error message

* [WIP] support ExplainedValues in yaml

* print markdown value in DefaultValue directly

* quote values in yaml maps

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

Co-authored-by: Brais Gabín <braisgabin@gmail.com>

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

Co-authored-by: Brais Gabín <braisgabin@gmail.com>

* add test case for missing reason

* fail fast in case of invalid configuration

* rename explainedValues to valuesWithReason

* add api documentation

* resolve and suppress code smells

* suppress UNCHECKED_CAST

* merge RuleCollectorSpec

* reformat spec

* fix indentation of test code

Co-authored-by: Markus Schwarz <post@markus-schwarz.net>
Co-authored-by: Brais Gabín <braisgabin@gmail.com>
2022-06-01 21:19:28 +02:00
Vitaly V. Pinchuk
fe03b6dd26 Improve exception message (#4823)
* Improve exception message

Report detailed location of an error.

* Add test case

* Split tests

* Improve error location message presentation
2022-06-01 20:07:44 +02:00
Dominic Zirbel
db0b4b5b06 UselessCallOnNotNull: fix false positive for unresolved types (#4880)
Fix an issue where UselessCallOnNotNull would report issues when some of the argument types resolved as ErrorType. While it correctly handles cases where the BindingContext cannot resolve a type (the first test case), in cases where a call is made on an unknown type (the second test case, e.g. via takeIf{}) the BindingContext will report it as an ErrorType. Since ErrorType.isNullable() apparently returns false we need to make an exception to ensure the rule behaves as expected.
2022-06-01 20:03:45 +02:00
Toshiaki Kameyama
05cd79612f UnnecessaryInnerClass: fix false negative with this references (#4884) 2022-06-01 18:55:51 +02:00
Matthew Haughton
80bae4bdc5 Revert "Display dynamic --jvm-target values when using --help flag (#4694)" (#4816) 2022-06-01 14:26:11 +01:00
Marie Katrine Ekeberg
a949686e71 Add new rule CouldBeSequence (#4855)
* Add new rule CouldBeSequence

* Add test case for CouldBeSequence

* Fix inconsistency in compliant example for CoudlBeSequence
2022-06-01 10:59:46 +02:00
schalkms
f66a3217b9 Update MagicNumber rule to exclude .kts files (#4877)
* Update MagicNumber rule to exclude .kts files

The MagicNumber rule should not be enforced in script files,
because you cannot have constants in these files.

Closes #4863

* Adapt Exclusion.kt for MagicNumber rule
2022-05-31 22:04:03 +01:00
renovate[bot]
b2ef7a6345 Update docusaurus monorepo to v2.0.0-beta.21 (#4869)
Co-authored-by: Renovate Bot <bot@renovateapp.com>
2022-05-31 17:37:40 +01:00
Dominic Zirbel
d958fbf5f5 CanBeNonNullable: fix false positives for parameterized types (#4870)
CanBeNonNullable reports that properties of parameterized types can be marked as non-nullable even when this is impossible, just because the parameterized type is itself nullable (i.e. does not inherit from a non-nullable type). Instead, the rule should only report cases where a property is explicitly marked nullable but does not need to be.
2022-05-30 22:26:55 +02:00
Dominic Zirbel
233b4a686c Add NullableBooleanCheck rule (#4872)
Add a new rule which enforces the recommendation of the Kotlin coding conventions to prefer `==` over `?:` when converting a `Boolean?` into a `Boolean`: https://kotlinlang.org/docs/coding-conventions.html#nullable-boolean-values-in-conditions. This is simple to implement and enforces consistency for the two essentially equivalent methods of coalescing nullable boolean values.

The coding conventions only specify this preference for usages "in a conditional statement" but the same rationale applies to any statement which converts a Boolean? to a Boolean, so I have implemented it for any situation. An alternative is to add a configuration setting to toggle application only in if statements.

Unfortunately, this rule requires type resolution since there are technically valid usages of e.g. `value ?: true` for cases where `value` is not a `Boolean?` but an `Any?`. Running without type resolution will not be able to distinguish between these valid usages and ones which could be converted to `== false`.
2022-05-30 10:33:13 +02:00
davidburstrom
a8cde4fb35 Use ConTester to prove that the synchronized block is required (#4672)
Relates to PR https://github.com/detekt/detekt/pull/4631
2022-05-29 17:32:01 +02:00
Dominic Zirbel
2f5b8f5933 UnnecessaryInnerClass: fix false positives labeled expression to outer class (#4865)
* UnnecessaryInnerClass: fix false positives labeled expression to outer class

Fix an issue where inner classes which reference their outer class via a labeled
expression would still be reported as unnecessary. This seems to be due to a
missing visitExpressionWithLabel() check which resolves the label name: if the
label is referencing a parent class, then the nested class must be `inner`.

I wasn't able to find a way to resolve the labeled expression as a ClassId to
match the existing class check from KtReferenceExpression, so I settled for
using the class name instead, which is easy to obtain. This means there's a fair
bit of duplication in overriden checkForOuterUsage() methods to check parent
classes which could probably be removed, but I didn't see a particularly clean
way to do so.

* UnnecessaryInnerClass: add test for double-nested inner classes using labeled expressions
2022-05-29 11:52:17 +02:00
renovate[bot]
da653c8fbc Update dependency org.jetbrains.kotlinx:kotlinx-coroutines-core to v1.6.2 (#4868)
Co-authored-by: Renovate Bot <bot@renovateapp.com>
2022-05-28 22:49:15 +02:00
Dominic Zirbel
c54453dc8a Remove reference to contributor list (#4871)
It appears that the contributor list in the readme has been replaced by an autogenerated image of the contributors; the contribution guide should no longer suggest contributors add their name there.
2022-05-28 20:48:52 +02:00
Dominic Zirbel
2e2d4711c2 UnnecessaryInnerClass: add test for safe qualified expressions (#4864)
Add a unit test for a bug in which safe qualified references to a nullable field
in the parent class (i.e. as `?.`) would not be marked as warnings in release
1.20.0. This issue has been inadvertently fixed by
https://github.com/detekt/detekt/pull/4738, but adding a unit test will guard
against future regressions.

I was able to confirm this test fails by checking out the 1.20.0 tag and running
the unit test; against that tag the fix was to override the
visitSafeQualifiedExpression() function with the same logic as
visitCallExpression().
2022-05-27 09:16:34 +02:00
renovate[bot]
fcd9c48159 Update dependency com.android.tools.build:gradle to v7.2.1 (#4861)
Co-authored-by: Renovate Bot <bot@renovateapp.com>
2022-05-25 23:59:19 +01:00
Naveen
6e74b5465b chore: renovate bot setting to pin actions to a full length commit SHA (#4846)
- https://docs.renovatebot.com/modules/manager/github-actions/#additional-information

- Pinned actions by SHA https://github.com/ossf/scorecard/blob/main/docs/checks.md#pinned-dependencies

>Pin actions to a full length commit SHA

>Pinning an action to a full length commit SHA is currently the only way to use an action as an immutable release.
> Pinning to a particular SHA helps mitigate the risk of a bad actor adding a backdoor to the action's repository,
> as they would need to generate a SHA-1 collision for a valid Git object payload.

- https://docs.github.com/en/actions/security-guides/security-hardening-for-github-actions#using-third-party-actions
- b0c3aa85ef/default.json (L13)
2022-05-25 13:30:43 +02:00
Vitaly V. Pinchuk
4dd9ac4bf5 Report KDoc comments that refer to non-public properties of a class (#4768)
* Report KDoc comments that refer to encapsulated properties of a class

New rule to address the issue of breaking encapsulation principle when KDoc comments have references to encapsulated (private) properties.
Clients do not need to know the implementation details.

* Rename rule to 'KDocReferencesNonPublicProperty' and fix naming

* Set 'protected' modifier as allowed

* Improve tests

* Fix rule documentation
2022-05-22 18:11:36 +02:00
Brais Gabín
a066c7fe18 detektGenerateConfig adds the configuration of plugins (#4844) 2022-05-22 17:56:22 +02:00
Nicola Corti
486c894a9e Fix a confusing Regex in the Compose webpage (#4852) 2022-05-21 23:25:14 +02:00
Tim Oltjenbruns
ee2e9a07b2 Search in all versions.properties, not just the first one #4830 (#4831)
* Fix multiple versions.properties files #4830

* Improve build error when multiple Detekt versions are present

Co-authored-by: Tim Oltjenbruns <tim.oltjenbruns@softvision.com>
2022-05-21 13:23:58 +02:00
Toshiaki Kameyama
5f491f1da6 ExplicitCollectionElementAccessMethod: fix false positive for get operators with type parameters (#4803) 2022-05-21 11:43:18 +02:00
Nicola Corti
fe275049e4 Fix edit URLs for the website (#4850)
* Fix edit URLs for the website

Fixes #4845

* Update blog URL
2022-05-21 11:41:48 +02:00
renovate[bot]
1997ea3937 Update plugin com.gradle.common-custom-user-data-gradle-plugin to v1.7 (#4849)
Co-authored-by: Renovate Bot <bot@renovateapp.com>
2022-05-20 17:28:48 +01:00
renovate[bot]
8d9c35766f Update plugin com.gradle.enterprise to v3.10.1 (#4848)
Co-authored-by: Renovate Bot <bot@renovateapp.com>
2022-05-20 20:04:50 +10:00