36 Commits

Author SHA1 Message Date
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
a2734b18c1 Remove Unnecesary @Nested (#4740) 2022-04-25 23:04:26 +02:00
Toshiaki Kameyama
e331fd3809 OutdatedDocumentation: fix false positive with no primary constructor (#4728) 2022-04-18 13:26:44 +02: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
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
Matthew Haughton
efcc0d95de Migrate detekt-rules-documentation tests to JUnit (#4568) 2022-02-07 09:38:36 +01:00
Matej Drobnič
b274fea74f Add option for OutdatedDocumentation to allow param in constructor pr… (#4453) 2022-01-07 11:51:57 +00:00
M Schalk
28b4edb9df Formulate rule/documentation descriptions consistently (#4416)
* Formulate rule/documentation descriptions consistently

reference #4384

* Apply suggestion for missing license text msg
2021-12-28 02:13:20 +01:00
Matthew Haughton
7d46753d24 Fix typos and grammar in rule descriptions (#4219) 2021-10-31 21:58:35 -07:00
lukaszosowicki
844a97104f #4169 OutdatedDocumentation rule (#4185)
* Introduce OutdatedDocumentation rule

Basic implementation covers:
- class primary constructor parameters
- class primary constructor property parameters
- function parameters

* OutdatedDocumentation rule - type parameters matching

* OutdatedDocumentation rule - refactor and add more tests

* OutdatedDocumentation rule - report for secondary constructors

* OutdatedDocumentation rule - do not report when KDoc does not contain any @param or @property tag

* OutdatedDocumentation rule - add description

* OutdatedDocumentation rule - add configuration for type parameters and declarations order

* OutdatedDocumentation rule - refactor

* OutdatedDocumentation rule - fix CI

* OutdatedDocumentation rule - additional test cases

* OutdatedDocumentation rule - fix rule reporting for incorrect declarations order
2021-10-19 15:41:39 +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
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
M Schalk
15980dc6f0 Fix #3893 by only calling super.visit once (#3904)
* Fix #3893 by only calling super.visit once

In #3660 the EndOfSentenceFormat rule got refactored.
The rule is called by the MultiRule 'KDocStyle'.
Both the called and calling visitor function execute a super.visit().
This can cause problems.
Hence, super.visit only called once with the changes made.

Suspicion:
Multiple KtDeclaration super.visit calls cause the crash in #3893.

* Update test case description
2021-07-22 14:15:22 -07:00
Toshiaki Kameyama
db1e949435 UndocumentedPublicFunction: don't report when nested class is inside not public class (#3962)
* UndocumentedPublicFunction: don't report when nested class is inside not public class

* Update detekt-rules-documentation/src/main/kotlin/io/gitlab/arturbosch/detekt/rules/documentation/UndocumentedPublicFunction.kt

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

* Format

* Add a test for objects

* Simplify

Co-authored-by: Nicola Corti <corti.nico@gmail.com>
2021-07-20 19:14:28 +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
Anthony Restaino
b2aba98a06 UndocumentedPublicProperty and UndocumentedPublicFunction should include objects (#3940)
* Add test cases for objects with an undocumented public function

* Check the containing class or object instead of just the class

The class returned was null for functions inside an object, resulting in a false negative, so we instead use containingClassOrObject to determine if the containing object is public or not.

* Add test cases for objects with an undocumented public property

* Check the containing class or object instead of just the class when determining eligibility for UndocumentedPublicProperty check

containingClass() returns null when checking an object not nested in another class, making it ineligible to check. Switching to containingClassOrObject allows properties in an obect to be checked.

* Add test cases for interfaces to property and function documentation rules

* Fixing invalid kotlin in interface test
2021-07-07 22:15:29 +02:00
M Schalk
6f641782d0 Remove unnecessary constant declaration (#3903) 2021-06-25 21:51:01 +02:00
marschwar
0c6267fef0 Use annotation to configure rules in rules-documentation (#3770)
* use annotations to configure AbsentOrWrongFileLicense

* use annotations to configure EndOfSentenceFormat

* use annotations to configure UndocumentedPublicClass

* make config properties private

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

Co-authored-by: Markus Schwarz <post@markus-schwarz.net>
Co-authored-by: Brais Gabín <braisgabin@gmail.com>
2021-05-21 21:53:05 -07:00
zmunm
a592a3719f Fix document (#3765)
* Fix  2 spaces because the code block cannot be read

* Fix incomplete block

* Fix impossible case

* Fix annotation escape

* Use 4 spaces as indentation

Co-authored-by: M Schalk <30376729+schalkms@users.noreply.github.com>
2021-05-13 08:46:22 +02:00
arhont375
e41de94a68 Allow inline comments for properties in primary constructor as documentation (#3722)
* Allow inline comments for properties in primary constructor
Fixes #3677

* Revert blank line removal in UndocumentedPublicProperty

* - remove configuration
- update tests

* - remove unused import
2021-05-08 12:04:16 +02:00
Matthew Haughton
dc2f3d801c Enable Gradle's type-safe project accessors (#3742) 2021-05-06 20:59:44 +02:00
Zoroark
238c3cddbd Add DeprecatedBlockTag rule (#3660)
* Add DeprecatedBlockTag rule

* Refactor DeprecatedBlockTagSpec tests to remove Spek complexity

* Fix incorrect deprecation test snippets on property set/get

* Add link to official docs in DeprecatedBlockTag

* Extract KDocStyle class out of EndOfSentenceFormat.kt

* Fix EndOfSentenceFormat not visiting declarations on its own

* Add DeprecatedBlockTag to KDocStyle

* Fix code made useless by DeprecatedBlockTag move
2021-04-24 00:00:54 +02: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
Sergey Solovyev
d2dc38cf60 Allow using regular expressions when defining license header templates (#3486)
Problem: different projects might impose different rules on license headers.
It's not uncommon, for example, that a year in the license header is the year when the source
file was created. This leads to a situation when different source files have different license
headers (at least some parts of them differ) making it impossible to use a single static
license header template to match against.

This change makes it possible to define license header templates as regexps.
An example of such template is:
  \/\/ Copyright 20[0-9]{2} Artur Bosch & Contributors
which would match both
  // Copyright 2020 Artur Bosch & Contributors
and
  // Copyright 2021 Artur Bosch & Contributors

The way `AbsentOrWrongFileLicense` works now is controlled
by the new configuration option `licenseTemplateIsRegex`:
when `licenseTemplateIsRegex` is false the template is considered to be static
and the old matching rules apply.
If `licenseTemplateIsRegex` is set to true the new regexp based logic kicks in.

To avoid breakage of existing projects, the added configuration option
`licenseTemplateIsRegex` is disabled by default.

This commit implements a feature requested here #3100.
2021-02-22 12:22:27 +01:00
Nicola Corti
c5f23c8c27 Add a test for UndocumentedPublicClass and fun interfaces (#3374) 2021-01-13 21:20:00 +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
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
Artur Bosch
5c2d96f3d4 Move internal config api to core module (#3163)
* Move internal config api to core module

* Move YamlConfig to core and remove all remaining references

* Remove yaml dependency from api module

* Revert visibility modifier change
2020-11-02 10:15:23 +01:00
Brais Gabín
b5a423fde7 Don't use deprectad onStart (#3172) 2020-10-26 12:54:42 +01:00
M Schalk
e852dbc521 Improve description of AbsentOrWrongFileLicense rule (#3109)
* Improve description of AbsentOrWrongFileLicense rule

The new description states how the rule checks Kotlin source files
against the given license header.
Closes #3100

* Update grammar in description

* Regenerate docs
2020-09-27 16:26:38 +02:00
Artur Bosch
c45791768d Add bindingContext function to FileProcessListener - #2872 (#2900)
* Introduce binding context aware members for FileProcessListener

* Use FileProcessListener with binding context everywhere

* Move deprecation on function level
2020-07-28 08:05:16 +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
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