Not reporting Cognitive Complexity of methods

Please provide

  • Operating system: macOS
  • SonarQube for IntelliJ plugin version: 10.16.1.80464
  • IntelliJ version: Android Studio Ladybug Feature Drop | 2024.2.2
  • Programming language you’re coding in: Kotlin
  • Is connected mode used: Local/IDE

And a thorough description of the problem / question:

Since SonarQube for IntelliJ replaced SonarLint plugin the Cognitive Complexity is no longer being triggered.

Hey @Bitwise_DEVS, thank you for reaching out to us about this issue.

Could you please provide the code snippet/file on which you noticed this problem? It would be best if you could also provide the SonarQube for IDE logs. On my side, Cognitive Complexity is still reported.

It may be worth checking if the rule is enabled for Kotlin within your rule settings:

Also, please note that if you are using Connected Mode, configuration from the server applies.

override fun initViews(binding: FragmentMarketcapBinding) {

        binding.apply {

            with(requireContext()) {

                swipeRefreshLayout = refreshLayout.apply {
                    setColorSchemeColors(context.resToColor(R.color.mdc_colorWhite_PrimaryDark))
                }

                assetMinAdapter = AssetMinAdapter(
                    Firebase.remoteConfig.getString(AppConfig.CRYPTO_IMAGE_BASE_URL),
                    glide,
                    object : AssetMinAdapter.ItemListener {

                        override fun onItemSelected(position: Int, cardView: MaterialCardView) {

                            val domain = assetMinAdapter.currentList[position]

                            if (domain.name.equals(MessariAssetMinDataDomain.DEFAULT_ASSET, true)) {
                                return
                            }

                            val selectedSize = assetMinAdapter.currentList.filter { it.isSelected }.size

                            // To avoid abuse usage, limit the selectable asset market cap
                            // the default asset BTC is counted
                            if (selectedSize >= 6 && domain.isSelected.not()) {
                                showToast(getString(R.string.max_size_reach), Toast.LENGTH_LONG)
                                return
                            }

                            domain.isSelected = !cardView.isChecked
                            cardView.isChecked = domain.isSelected

                            fetchAssetsMarketCap(assetMinAdapter.currentList)

                        }

                        // ListAdapter may experience performance issues when updating its `currentList` after calling `submitList`.
                        // We cannot rely on the `onCurrentListChanged` callback for tasks like updating the UI when the list becomes empty after a fetch,
                        // as it does not provide context on which state change caused the list to become empty.
                        override fun onListUpdate(
                            previousList: List<MessariAssetMinDataDomain>,
                            currentList: List<MessariAssetMinDataDomain>
                        ) {
                            recyclerView.startLayoutAnimation()
                            if (currentList.isNotEmpty()) { // This exceed the 15 rule of Cognitive Complexity in SonarLint
                                isReadyForSearch = true
                            }
                        }

                    }
                )

                datePickerFrom = materialDatePicker(calendarConstraints = fromDateConstraints.first, fromDateConstraints.second).apply {

                    fromDateChip.text = selection?.let { Instant.fromEpochMilliseconds(it).toLocalDateTime(TimeZone.currentSystemDefault()).format(dateFormatter) }

                    addOnPositiveButtonClickListener {

                        fromDateChip.text = Instant.fromEpochMilliseconds(it).toLocalDateTime(TimeZone.currentSystemDefault()).format(dateFormatter)

                        fetchAssetsMarketCap(assetMinAdapter.currentList)

                    }

                }

                datePickerTo = materialDatePicker(calendarConstraints = toDateConstraints.first, toDateConstraints.second).apply {

                    toDateChip.text = selection?.let { Instant.fromEpochMilliseconds(it).toLocalDateTime(TimeZone.currentSystemDefault()).format(dateFormatter) }

                    addOnPositiveButtonClickListener {

                        toDateChip.text = Instant.fromEpochMilliseconds(it).toLocalDateTime(TimeZone.currentSystemDefault()).format(dateFormatter)

                        fetchAssetsMarketCap(assetMinAdapter.currentList)

                    }

                }

            }

        }

    }

Upon checking the Cognitive Complexity feature is enabled on Kotlin language.

As for the logs, I cannot find that option in Android Studio.

Sorry please disregard, I realized it is because I shelved some local changes and unshelving it now triggers the lint.

Super, thank you for letting us know that your issue is resolved. If you enjoy using SonarQube for IDE, feel free to leave a review on our plugin page!

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.