1317 Commits

Author SHA1 Message Date
Brais Gabín
a2734b18c1 Remove Unnecesary @Nested (#4740) 2022-04-25 23:04:26 +02:00
Matthew Haughton
c74d714f6b Migrate detekt-rules tests to JUnit (#4514) 2022-01-23 22:09:33 -08: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
Brais Gabín
4d3b2292e0 Disable UnsafeCallOnNullableType on tests (#4123)
* Disable UnsafeCallOnNullableType on tests by default
* Remove unnecessary @Suppress
2021-09-28 09:26:55 -07: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
80401c5910 Don't unnecessarily propogate opt-in requirement (#4116)
Opt-in doesn't need to be propogated in test code, or in detekt-core which
is not public API.

https://kotlinlang.org/docs/opt-in-requirements.html#non-propagating-opt-in

> In modules that don't expose their own API, such as applications, you can
> opt in to using APIs without propagating the opt-in requirement to your
> code. In this case, mark your declaration with @OptIn passing the opt-in
> requirement annotation as its argument.
2021-09-20 11:49:09 +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
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
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
Matthew Haughton
3c84797662 Decouple Gradle projects (#3611)
* Decouple Gradle projects

* Refactor

* Remove unneeded explicit stdlib dependency
2021-03-28 14:40:22 +11: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
Artur Bosch
5a0fe624e5 Introduce tooling api module (#2861)
* Prototype a configuration dsl

* Implement a service returning the default configuration

* Implement a service returning the runtime detekt version

* Add logging and issues specific configuration to ProcessingSpec

* Define interfaces to load detekt instances during runtime

* Use new DetektProvider in cli Runner for detekt analysis

* Rename IssuesSpec to RulesSpec

* Support to run chosen single or multiple rules via spec api

* Move logic to check for build error to core

Add tooling support for MaxIssuePolicy.

* Make Runner config validation testcases independent of possible build failure logic

* Simplify test runner creation

* Make KtFileModifier a FileProcessListener

Removes special treatment inside DetektFacade

* Allow to add a reason UnstableApi annotation

* Remove unnecessary DetektFacade.create factory functions

* Implement remaining DetektFacade functions based on a new Lifecycle class

* Fix using excludes

* Fix using given BindingContext instead of creating one

* Rename to AnalysisFacade and Analyzer for core classes

* Support running a single from core module

* Unwrap the unexpected error before throwing it

* Move LicenceHeader test to rules module where it is declared

* Finalize migration to loading Config from Spec instead of CliArgs by moving and reworking existing test cases

* Move --run-rule test cases to runner as there is no SingleRuleRunner anymore

* Implement a default configuration provider

* Deprecate obsolete methods to retrieve the default configuration

* Implement a default version provider

* Support excludeCorrectable for RulesSpec which should make the config property obsolete

* Simplify loading ConfigValidators

* Use ReportsSpec.Report in core and move ReportsPath to cli again

* Create an abstraction for build>maxIssues config part based on MaxIssuePolicy

* Remove core dependency for formatting by moving top level auto correct test

* Make local test-only rules private

* Extract measuring performance logic into a dedicated class

* Remove unnecessary side-effects from parsing arguments

* Reimplement cli logic based on new DetektCli interface

* Remove all trailing comma leftovers from testing with 1.4 language version

* Introduce NonSpecified MaxIssuePolicy to make it explicit when to use legacy build section from the config

* Change output and error channel types to Appendable

* Share ProcessingSpec in ProcessingSettings

This is the first step to migrate ProcessingSettings properties usages to spec.

* Move PathFilters out of ProcessingSettings

They were just referenced in KtTreeCompiler.

* Extract common logging logic from ProcessingSettings into a separate class

* Extract common properties logic from ProcessingSettings into a PropertiesFacade class

* Remove output and error channels from ProcessingSettings

* Extract Kotlin environment logic to a dedicated class

* Pass buildUponDefaultConfig from cli to core module

* Extract plugin and extension logic from ProcessingSettings

* Remove excludeDefaultRuleSets from ProcessingSettings

* Remove parallel property from ProcessingSettings

* Remove autoCorrect property from ProcessingSettings

* Remove executorService property from ProcessingSettings

* Remove inputPaths property from ProcessingSettings

* Move configUris outside the constructor

* Allow extensions to be disabled via their ids in ExtensionSpec

* Remove unused constructs

* Deprecate convenient print method only usable for PrintStreams

* Remove obsolete ExitCode enum

* Make core a runtimeOnly dependency

* Make all detekt-core dependencies implementation-dependencies

* Make DefaultConfig object internal

* Make AnalysisResult.exitCode an extension function

* Remove BindingTrace entry point

* Make using a parsing strategy explicit

* Use yml to be consistent with other naming

* Remove unnecessary factory method for KtTreeCompiler

* Make Throwable branch the else branch

* Close only self constructed URLClassloaders

* Test exit codes from AnalysisResult

* Test either plugin paths or a classloader is used

* Test loading a DetektCli instance
2020-07-15 19:55:01 +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
Amit Dash
bf6f979e32 Cleanup rules regarding guard clauses (#2862)
* Use structural equality (==) instead of referential equality (===), use safe access instead of null check, cleanup test comments

* Reinstate referential equality for node comparison for guard clauses, rename test case as per MR review comment

* Remove code duplication and use common code for ELVIS guard clause for ThrowsCount, add test case for the same in ThrowsCountSpec

* Revert wildcard imports

* Add internal to the guard clause extension methods
2020-07-13 11:14:10 +02:00
Nicola Corti
1ec8d1fa70 Add test cases for UnusedPrivateMember false positives (#2858)
Fixes #2579
2020-07-10 12:05:56 +02:00
Brais Gabín
e341649159 Create less sub configs (#2849)
* Simplify analyze a bit

* We don't need to use any extension function here

* Reduce the config created

* Improve format
2020-07-06 23:44:20 +02:00
Brais Gabín
cb84f0263c Fix UnnecessaryLet false negatives (#2828)
* Use compileAndLint

* Improve documentation

* Add more tests

* Fix false positive

* Extract receiverIsUsed and make it positive

* Fix more false negatives

* Fix more false negatives

* minor improvement

* update docs

* refactor

* Reduce complexity

* Add one more case of false negative

* Test the message

* Fix false positive

* rename count
2020-07-01 19:45:53 +02:00
Brais Gabín
719cdf4c75 Fix false negative in MandatoryBracesIfStatements (#2835)
* Fix false negative in MandatoryBracesIfStatements

* Apply suggestions from code review

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

Co-authored-by: Nicola Corti <corti.nico@gmail.com>
2020-06-30 21:55:52 +02:00
Artur Bosch
4e3d83abe1 Prepare 1.10.0 (#2829)
* Prepare 1.10.0 release

* Deactivate IsPropertyNaming rule for 1.10.0 release

* Update self analysis and doc version
2020-06-27 20:31:12 +02:00
Brais Gabín
26a78f56e9 Improve UnnecessaryApply (#2827)
* Improve documentation of UnnecessaryApply

* Fix snippet format

* Recommend to replace apply to let
2020-06-27 18:57:41 +02:00
Brais Gabín
9ebfeded2f Minor fixes around IspropertyNaming (#2822)
* Fix format IsPropertyNamingSpec

* Fix documentation format

* Add missing test
2020-06-25 19:36:15 +02:00
Nicola Corti
b054d1a850 UnusedPrivateClass: tests cleanup (#2820) 2020-06-23 20:03:52 +02:00
Toshiaki Kameyama
ef299a7b2b UnusedPrivateClass: fix false negative with import directives (#2817)
* UnusedPrivateClass: fix false negative with import directives

* Fix test
2020-06-23 10:24:48 +02:00
Artur Bosch
dbb5ed1280 Implement new rule ImplictUnitReturnTypet (#2781)
* Implement rule ExpressionFunctionReturnsUnit

* Inspect resulting descriptor for return types or type arguments may get returned

* Update detekt-rules/src/test/kotlin/io/gitlab/arturbosch/detekt/rules/bugs/ImplicitUnitReturnTypeSpec.kt

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

* Update detekt-rules/src/test/kotlin/io/gitlab/arturbosch/detekt/rules/bugs/ImplicitUnitReturnTypeSpec.kt

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

Co-authored-by: Nicola Corti <corti.nico@gmail.com>
2020-06-23 10:12:16 +02:00
Niraj Palecha
e0407049e1 LongMethod: disregard params in method definition (#2806)
* failing tests for #2804 LongMethod with params

* fix test

* skipTrees for KtParameterList for linesOfCode

* use test snippets that compile

* [ci ckip] use fun body for LongMethod
- revert changes in LinesOfCode.kt
- still need to update nested methods

* remove unused import

* add functionToBodyLinesCache to track fun body length

* remove spaces from test asserts
2020-06-22 17:37:32 +02:00
Toshiaki Kameyama
82108b7d24 UnusedPrivateClass: don't report imported classes (#2812) 2020-06-21 09:24:42 +02:00
Igor Manushin
194ace6ad7 Feature/restrict is properties (#2779)
* add draft implementation of #2701

* extend tests, add inner types validation; fix #2701

* #2157 fix review notes, add tests, disable rule by default

* update documentation #2701

* #2157 fix syntax error in tests

* Update detekt-rules/src/main/kotlin/io/gitlab/arturbosch/detekt/rules/naming/IsPropertyNaming.kt

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

* Update detekt-rules/src/main/kotlin/io/gitlab/arturbosch/detekt/rules/naming/IsPropertyNaming.kt

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

* add tests for java Boolean

* documentation update

Co-authored-by: Artur Bosch <arturbosch@gmx.de>
Co-authored-by: Nicola Corti <corti.nico@gmail.com>
2020-06-20 17:02:13 +02:00
Nicola Corti
27f3207169 Compile Test Snippets on Java 14 (#2803) 2020-06-16 11:11:52 +02:00
Nicola Corti
c0f6c59cea Cleaup MayBeConst tests (#2802) 2020-06-15 19:59:03 +02:00
Artur Bosch
025697516b Local vars inside object literals can't be const - Closes #2794 (#2799) 2020-06-14 20:43:55 +02:00
Nicola Corti
ae9f7ce57c Fix false positive for UnusedPrivateClass on generics (#2793)
* Fix false positive for UnusedPrivateClass on generics

* Make test snippet val private

Co-authored-by: M Schalk <30376729+schalkms@users.noreply.github.com>
2020-06-12 23:40:05 +02:00
Remco Mokveld
1e712757bb Rename Blacklist and Whitelist to be self explanatory (#2778)
* Rename Blacklist and Whitelist to be self explanatory

SuppressedFalsePositive and TemporarySuppressedIssue describe better what each list is meant for and are more culturally appropriate.

* Add backward compatibility for deprecated baseline attributes

* Use better names for tags that replace blacklist and whitelist

* Define constants for Blacklist and Whitelist

This was done to make it more clear why they still exist in code

* Fix documentation after replacing whitelist terminology

* Move documentation to WildcardRule so generator does not complain

Co-authored-by: Artur Bosch <arturbosch@gmx.de>
2020-06-11 12:49:34 +02:00
Artur Bosch
d207bd3217 Report ComplexInterface issues at identifier (#2786) 2020-06-10 19:09:56 +02:00
Artur Bosch
98b89f4f1d Remove core module dependency for detekt-test (#2771)
* Fix two MaxLineLength issues

* Remove dependency on core.rules

* Move test helper for ProcessingSettings to core module

Besides of one usage in formatting it is only used by the core module.
Custom rule sets (formatting is treated as one) should not depend on core.

* Move FileProcessListener service registration to their respective modules

We merge the service loaders when constructing the cli shadowJar.
When combining jars dynamically this is not an issue as each jar has it's own services file.

* Move other test configuration into the configs folder

* Fixup after merging
2020-06-05 20:55:31 +02:00
Artur Bosch
92acdbcfc9 Introduce reporting extensions (#2755)
* Let DetektFacade execute OutputFacade

* Implement generic properties storage

Allows to pass arbitrary data to detekt extensions.

* Implement Baseline feature as an ReportingExtension

Reporting extensions provide interception points to filter findings and execute logic on detekt's result container.

* Share common processing settings creation logic between runners

* Implement OutputFacade as ReportingExtensions

* Run OutputFacade always last

* Describe why output reports needs to be run first

* Apply PR feedback

* Concert OutputFacade back to a core class instead of a ReportingExtension

An extensions which loads other extensions feels kind of wrong.
Reporting is a core logic and shouldn't be optional.
2020-06-04 07:07:33 +02:00
Artur Bosch
096578dee8 Improve the performance of tests using type resolution (#2756) 2020-06-02 21:30:33 +02:00
Ken Yee
d672a1abc7 add better documentation for the LongParameterList ignoreAnnotated (#2714)
* add better documentation for the LongParameterList ignoreAnnotated

* make LongParameterList doc changes in the right place

* Checkin documentation

Co-authored-by: Ken Yee <kyee@wayfair.com>
Co-authored-by: Artur Bosch <arturbosch@gmx.de>
2020-06-01 17:53:31 +02:00
Júlia Marczak Birkett
a7637493ac Add default values to SwallowedException rule (#2661)
* Adding NumberFormatException as default for SwallowedException rule

* Adding InterruptedException as default for SwallowedException rule

* Adding ParseException as default for SwallowedException rule

* Adding MalformedURLException as default for SwallowedException rule

* Refactoring code to use enum

* Fixing enum class name

* Using String instead of enum class

* Using generic Exception instead of custom exception

* Simplify ignored by default testcases by using dynamic tests

Co-authored-by: Artur Bosch <arturbosch@gmx.de>
2020-06-01 14:32:57 +02:00
Nicola Corti
12bce58366 Add default print methods to ForbiddenMethodCall (#2753)
* Add default print methods to ForbiddenMethodCall

Adding all the variations of print/println from Java and Kotlin
to the ForbiddenMethodCall.

The rationale is to encourage the usage of a Logger.

Moreover this fixes the rule that was not catching all the method
calls due to overriding visitQualifiedExpression rather than visitCallExpression

Fixes #2678

* Fixing indentation

* Fixed assert location
2020-05-31 14:09:00 +02:00
Nicola Corti
afb85a2d5e Cleanup tests in ProtectedMemberInFinalClass (#2752)
* Cleanup tests in ProtectedMemberInFinalClass

* Remove extra `reports` comments

* Improve the test description

Co-authored-by: M Schalk <30376729+schalkms@users.noreply.github.com>
2020-05-30 23:43:33 +02:00
M Schalk
0d84b1083a Add referential equality test in EqualsAlwaysReturnsTrueOrFalse rule (#2751)
This is a follow-up of #2744
2020-05-30 21:52:14 +02:00
hqzxzwb
39b0864801 Fix EqualsAlwaysReturnsTrueOrFalse doc (#2744)
* Fix EqualsAlwaysReturnsTrueOrFalse doc

Use `==` in equals causes infinite recursion.

* Update EqualsAlwaysReturnsTrueOrFalse.kt

Co-authored-by: M Schalk <30376729+schalkms@users.noreply.github.com>
2020-05-28 21:49:26 +02:00
Charles Anderson
82f431674c Add the ignoreAnnotated array parameter to the FunctionNaming rule. Add default "Composable" exclusion to ease the use of Jetpack Compose. (#2734) 2020-05-26 19:40:14 +02:00
Artur Bosch
56abbeaf69 Migrate to resource function of test-utils (#2728) 2020-05-25 11:37:11 +02:00
Artur Bosch
58575daddb Faster documentation generation (#2722)
* Get rid of cli and core dependency for generator

* Remove generic argument parsing made for sharing but introduced complexity

* Do not use expensive shadow plugin on internal generator module

* Apply shadow plugin for cli in packaging

* Generate documentation after compilation of rules

* Trigger generateDocumentation when formatting rules are changed

* Further reduce complexity of parsing args

* Start generateDocumentation directly from gradle

* Test additional error paths of CliArgs
2020-05-24 11:03:26 +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
bff3d645a7 Introduce parser and psi module (#2716)
* Introduce parser module which handles setting up kotlin environment

* Introduce psi-utils module cleaning up api module from shared KtFile extensions

* Return Path object instead of wrapping on call site
2020-05-22 21:57:38 +02:00
Nicola Corti
5926d84372 IgnoreReturnValue: config options (#2712)
* IgnoreReturnValue: config options

* Update detekt-rules/src/test/kotlin/io/gitlab/arturbosch/detekt/rules/bugs/IgnoredReturnValueSpec.kt

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

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

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

* Remove config as property from constructor

* Rebuild docs

* Remove unnecessary .trimIndent()

* Fix package in failing to compile scripts

* Do not use com.test package

Co-authored-by: M Schalk <30376729+schalkms@users.noreply.github.com>
Co-authored-by: Brais Gabín <braisgabin@gmail.com>
2020-05-21 16:30:56 +02:00