Skip to content

Commit

Permalink
SONARKT-382 Update rules metadata (#404)
Browse files Browse the repository at this point in the history
  • Loading branch information
leveretka authored Dec 14, 2023
1 parent 9eadc7a commit eb22cc4
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 4 deletions.
2 changes: 1 addition & 1 deletion sonar-kotlin-plugin/sonarpedia.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"languages": [
"KOTLIN"
],
"latest-update": "2023-11-21T13:31:58.377021Z",
"latest-update": "2023-12-14T11:00:42.692746Z",
"options": {
"no-language-in-filenames": true,
"preserve-filenames": true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ <h3>What is the potential impact?</h3>
<h4>Readability and Understanding</h4>
<p>This change makes it easier to understand what a function does, because the semantics of indexed access operators is evident to the reader, while
for a function call, the reader would need to know what the called function does.</p>
<h4>Java interop</h4>
<p>The issue is also raised when Java API is used as a Kotlin compiler treats all <code>get(.)</code> methods as possible index access operators. Use
<code>CompletableFuture[timeout, unit]</code> instead of <code>CompletableFuture.get(timeout, unit)</code> when accessing Java’s
<code>CompletableFuture</code>.</p>
<h2>How to fix it</h2>
<p>Replace <code>instance.get(index)</code> with <code>instance[index]</code>.</p>
<p>Replace <code>instance.set(index, value)</code> with <code>instance[index] = value</code>.</p>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,17 @@ <h4>Noncompliant code example</h4>
</pre>
<h4>Compliant solution</h4>
<pre data-diff-id="1" data-diff-type="compliant">
ext {
mockitoVersion = "4.5.1"
}
const val mockitoVersion = "4.5.1"

dependencies {
testImplementation("org.mockito:mockito-core:$mockitoVersion")
testImplementation("org.mockito:mockito-inline:$mockitoVersion")
}
</pre>
<p>Alternatively, you can put <code>const val mockitoVersion = "4.5.1"</code> in any <code>.kt</code> file in <code>buildSrc/src/main/kotlin</code> or
use a more robust dependency management mechanism like <a href="https://plugins.gradle.org/plugin/io.spring.dependency-management">Spring dependency
management plugin</a> or <a href="https://www.youtube.com/watch?v=WvtcCCCLfOc&amp;list=PL0UJI1nZ56yAHv9H9kZA6vat4N1kSRGis&amp;index=21">Version
Catalogs</a>.</p>
<h2>Resources</h2>
<h3>Documentation</h3>
<ul>
Expand Down

0 comments on commit eb22cc4

Please sign in to comment.