28 Commits

Author SHA1 Message Date
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
Brais Gabín
a2734b18c1 Remove Unnecesary @Nested (#4740) 2022-04-25 23:04:26 +02:00
davidburstrom
5325fd09a8 Fix concurrency issue when creating PomModel (#4609) (#4631)
Co-authored-by: David Burström <davidburstrom@spotify.com>
2022-03-18 09:10:40 +01:00
Nicola Corti
56f34c4cf8 Fix AutoCorrection crashing with Missing extension point (#4545) 2022-02-04 23:11:26 +00: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
ad270ef4f1 migrate tests in detekt-parser to junit (#4512)
Co-authored-by: Markus Schwarz <post@markus-schwarz.net>
2022-01-24 09:43: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
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
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
Nicola Corti
fff8632949 Remove Extensions.getRootArea (#3848) 2021-06-01 18:16:21 +02:00
Matthew Haughton
9f364d8a71 Checkout files with LF line endings on Windows (#3782)
* Use LF line endings in working directory

* Ensure LF & CRLF test assertions are OS-independent
2021-05-16 21:37:24 +02:00
Matthew Haughton
dc2f3d801c Enable Gradle's type-safe project accessors (#3742) 2021-05-06 20:59:44 +02:00
Matthew Haughton
4ee28ac074 Enable version catalogs (#3741) 2021-05-06 08:46:30 +10:00
Brais Gabín
0388ffe88c Warnings as errors (#3646)
* Deprecate Location.file in favor of Location.filePath

* Fix warnings

* Enable warningsAsErrors again

This was removed in #2981 for an issue with kotlin 1.4 but that issue
is fixed now so it's safe to enable it again
2021-04-17 10:14:17 +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
M Schalk
5043656ed3 Enable more rules by default (#3229)
* This is a first draft for enabling more detekt rules by default.
This way users can benefit from a good default config.

Closes #2838

* Regenerate default-detekt-config.yml

* Resolve SwallowedException with judgement calls

* Address ImplicitDefaultLocale

* Fix ImplicitDefaultLocale in tests

Co-authored-by: Artur Bosch <arturbosch@gmx.de>
Co-authored-by: Chao Zhang <cazhang@linkedin.com>
2021-01-19 21:17:25 +01:00
Chao Zhang
c87a0acc15 Integrate SARIF report with Github code scanning (#3359)
* Integrate SARIF report with Github Actions

* Simplify workflow setup

* Set OriginalUriBaseIds in output report
2021-01-11 22:03:29 +01:00
Chao Zhang
5019fe7279 Support relative output paths (#3319)
* Support relative output paths

* Enrich test spec description and add KDoc

* Update documentation

* Refactor FilePath

* Fix CI failures

* Fix detekt failures and restore defaults as absolute

* Renamed report base path back to base path
2021-01-07 14:02:13 +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
Artur Bosch
ee49144114 Support Kotlin 1.4 (#2981)
* Update to Gradle 6.6

* Update to Kotlin 1.4

* Upgrade to prerelease of KtLint 0.38

* Fix testcase by unwrapping the original descriptor

* Increase max heap for dokka on Java 11

* Update minimal supported Gradle version to 5.3

* Do not run warningsAsErrors on CI due to Gradle not supporting Kotlin 1.4

* Remove new line testing as it fails on windows

* Require Gradle 5.4 to reflect Kotlin's required version from their website
2020-08-20 20:00:38 +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
9a9d8d58cc Use KtFile.name instead of storing an absolute path key (#2898)
* Fix applying only the fileName to the created KtFile

* Remove complexity from calculating signatures

* Remove hack to find absolute path of a KtFile

* Use KtFile.name for absolute paths

* Declare fileName utilities on the interface PsiFile instead of KtFile

* Use a Path to be compliant with Windows

* Simplify whitespaces regex

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

Co-authored-by: Nicola Corti <corti.nico@gmail.com>
2020-07-28 08:04:50 +02:00
Artur Bosch
9874528fa6 Simplify internal parsing to KtFile's (#2875)
* Simplify parsing to KtFile's

* Do not mark KtFiles as generated
2020-07-20 19:17:26 +02: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
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