45 Commits

Author SHA1 Message Date
Toshiaki Kameyama
5d6ee2f43e NamedArguments: don't count trailing lambda argument (#5002) 2022-06-28 11:43:31 +02:00
Dominic Zirbel
89f6ec1586 Add CascadingCallWrapping style rule (#4979)
Add a new rule CascadingCallWrapping which requires that if a chained call is placed on a newline then all subsequent calls must be as well, improving readability of long chains.
2022-06-22 18:18:52 +02:00
Peter
8e27a307ee NestedScopeFunctions - Add rule for nested scope functions (#4788) 2022-06-02 13:18:16 +01:00
Brais Gabín
5fcc0e8902 Improve issue description and smell message of NamedArguments (#4796) 2022-05-07 21:18:27 -07:00
Brais Gabín
a2734b18c1 Remove Unnecesary @Nested (#4740) 2022-04-25 23:04:26 +02: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
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
Toshiaki Kameyama
1269b9b5ac NamedArguments: Ignore when argument values are the same as the parameter name (#4613)
* NamedArguments: Ignore when argument values are the same as the parameter names

* Add tests
2022-03-10 11:49:30 +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
Matthew Haughton
780849fc09 Migrate detekt-rules-complexity tests to JUnit (#4566) 2022-02-07 21:41:02 +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
c94a5d94da Extend VarCouldBeVal to include analysis of file- and class-level properties (#4424)
* First draft of refactoring VarCouldBeVal to scan file- and class-level properties; Added checks in VarCouldBeVal to avoid flagging escaped object literals

* Added more tests and fixed failing ones

* Addressing PR comments

* Added @Parameter to ignore list for internal Detekt scanning; Fixed Detekt issues

* Addressing PR comment
2022-01-05 08:50:19 -08:00
M Schalk
1f26c47cb2 Formulate rule/complexity descriptions consistently (#4417)
* Formulate rule/complexity descriptions consistently

reference #4384

* Apply suggestions from code review for msg

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

Co-authored-by: Chao Zhang <zhangchao6865@gmail.com>
2021-12-28 02:13:09 +01:00
Matthew Haughton
897961d6d7 Update Kotlin docs URL (#4217) 2021-10-31 21:56:25 -07: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
marschwar
7962979fb3 Use reference in fallback property delegate (#3982)
Co-authored-by: Markus Schwarz <post@markus-schwarz.net>
Co-authored-by: Brais <braisgabin@gmail.com>
2021-09-14 14:12:49 +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
Brais Gabín
66049c5bb0 Sort config lists (#4014) 2021-08-11 17:11:58 +02: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
e512a1f023 mark configWithFallback as unstable (#4028)
Co-authored-by: Markus Schwarz <post@markus-schwarz.net>
2021-08-10 16:40:02 +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
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
Toshiaki Kameyama
703487ea1f LongMethod: add 'ignoreAnnotated' configuration option (#3892)
* LongMethod: add 'ignoreAnnotated' configuration option

* Check annotations in visitNamedFunction

* Create AnnotationExcluder instance in visitKtFile

* Remove defalut value of ignoreAnnotated

* Remove defalut value of ignoreAnnotated in FunctionNaming
2021-06-24 19:08:15 +02:00
André Paz
85533a0dbd Improve LongParameterList rule by supporting ignoring annotated parameters (#3879) 2021-06-19 12:29:24 +01:00
marschwar
9494780455 Use annotations to configure rules in rules-complexity (#3768)
* Change definition order in ComplexMethod

* Use annotation in ComplexCondition

* Use annotation in ComplexInterface

* Use annotation in LabeledExpression

* Use annotation in LargeClass

* Use annotation in LongMethod

* Use annotation in LongParameterList

* Use annotation in MethodOverloading

* Use annotation in NamedArguments

The issue message had to be changed as the issue is used to
extract the rule id which is used to lookup the threshold from
the config.

* Use annotation in NestedBlockDepth

* Use annotation in TooManyFunctions

* Use annotation in StringLiteralDuplication

* replace removeSurrounding with removePrefix.removeSuffix

* inline default thresholds to improve readability

Co-authored-by: Markus Schwarz <post@markus-schwarz.net>
2021-05-22 14:47:05 +02:00
marschwar
f6a15f73e0 Add support for transformer function in config property delegate (#3676)
Co-authored-by: Markus Schwarz <post@markus-schwarz.net>
2021-05-12 12:26:57 -07:00
Matthew Haughton
dc2f3d801c Enable Gradle's type-safe project accessors (#3742) 2021-05-06 20:59:44 +02:00
Toshiaki Kameyama
3fb459cd14 NamedArguments rule: fix false positive with trailing lambda (#3661) 2021-04-11 14:01:57 -07:00
marschwar
cbee5e7e2e Rule Configuration using annotations (#3637)
* Create initial idea for @Configuration annotation
* Use config parameter constants again
* Generate documentation from @Configuration
* Introduce config delegate and extract default value from it
* Exclude rules configured with annotation from checks
* Remove support for factory methods in RuleSetProviderCollector
* Add support for lists that are empty by default
* Update documentation for rule contribution
* Restrict config delegate to supported types
* Update .github/CONTRIBUTING.md

Co-authored-by: Brais Gabín <braisgabin@gmail.com>
Co-authored-by: Markus Schwarz <post@markus-schwarz.net>
Co-authored-by: Chao Zhang <zhangchao6865@gmail.com>
2021-04-08 16:34:22 -07:00
marschwar
36edd4c528 Replace @active KDoc tag with @ActiveByDefault annotation (#3592)
* Add @ActiveByDefault annotation

* Add support for @ActiveByDefault annotation

* Use annotation for all activated in v1.2.0

* Use annotation for all activated after v1.2.0

* Use annotation for all activated in v1.0.0

* Update documentation with regard to RuleSetProvider

* Update documentation

* Remove leading 'v' from version in annotation

* Use named parameter 'since' for @ActiveByDefault

* check version matches semantic version pattern.

* Fix typo and correct version format

* Fix merge errors

Co-authored-by: Markus Schwarz <post@markus-schwarz.net>
Co-authored-by: Chao Zhang <zhangchao6865@gmail.com>
2021-03-28 11:21:09 -07: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
marschwar
7c4a690014 Replace @requiresTypeResolution kdoc tag with @RequiresTypeResolution annotation (#3579)
* Change indentation according to ktlint

* Add test case to verify requiresTypeResolution flag

* Add RequiresTypeResolution annotation

* Generate documentation based on RequiresTypeResolution annotation

* Use @RequiresTypeResolution instead of kdoc tag

* Update documentation for @RequiresTypeResolution

* Remove support for @requiresTypeResolution kdoc tag

* Add @RequiresTypeResolution to public api

* Move extension functions to separate files

* Remove @RequiresOptIn from public api

* Update annotation comment

Co-authored-by: Markus Schwarz <post@markus-schwarz.net>
2021-03-26 22:33:53 -07: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
Toshiaki Kameyama
37f0a1d006 NamedArguments: fix false positive with varargs (#3294) 2020-12-18 18:04:00 +01:00
Toshiaki Kameyama
2e89bd4eeb NamedArguments: fix false positive with java method call (#3290)
* NamedArguments: fix false positive with java method call

* Update detekt-rules-complexity/src/test/kotlin/io/gitlab/arturbosch/detekt/rules/complexity/NamedArgumentsSpec.kt

Co-authored-by: M Schalk <30376729+schalkms@users.noreply.github.com>
2020-12-16 18:34:38 +01:00
Sowmya Viswanathan
b6d298a6ad Introduce NamedArguments rule (#3167)
* Introduce NamedArguments rule when function is invoked with more than default number of non-named parameters

* Change the documentation to make the intent of default threshold clear

* Add compliant and non-compliant code documentation. Add tests for constructor
2020-10-26 12:44:55 +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
ef3914beab New rule: ReplaceSafeCallChainWithRun (#3089)
* Add ReplaceSafeCallChainWithRun rule

* Fix issues found by ReplaceSafeCallChainWithRun rule

* Improve rule documentation

* Simplify implementation

* Remove duplicated test
2020-09-26 07:59:25 +02: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
5c335157c6 Reduce test discovery for rules-complexity module (#2949) 2020-08-09 17:50:27 +02:00
Artur Bosch
b6e88a95a1 Split rules module into a module per rule set (#2865)
* Split rules module into a module per rule set

This significantly improves build and test times.

* Directly instantiate a kotlin scripting engine
2020-07-13 19:26:57 +02:00