Detection of design principle violations in Kotlin as a plugin to detekt.

Overview

detekt-hint (Attention: Looking for developers)

Detection of design principle violations in Kotlin added as comments on pull requests.

Getting started | 🏁 Roadmap | 💭 Ask a question | 📖 Documentation

Maintainability codecov Build Status Download Kotlinlang slack Awesome Kotlin Badge

ucih

detekt-hint is a plugin for detekt that includes detection of violation of programming principles. Since such violations are hard to detect with low false-positive rates, detekt-hint will provide hints during QA, minimizing noise during development. The idea is that a higher false-positive rate can be accepted if the detection could be of high value, and is easy to ignore. Detections on the architectural level of code is therefore most likely to provide value.

Through integration with Danger comments are added to the PR. Getting feedback directly on the PR makes it easy to ignore possible false-positives. Comments also include context and tips, making it easier for the developer to make the correct decisions.

Contributions are very much welcome and if you like the project - help me out with a . Especially help in which rules to implement, how to implement them and how to reduce the false-positives.

Currently supported detections

Use composition instead of inheritance - Will help developer ensure Liskov Substitution Principle is not violated. Will not report if you inherit from third-party libraries.

Lack Of Cohesion of Methods - Notifies you if the LCOM value is too high.

Interface Segregation Principles - Notifies you if you implement methods that the class does not need.

Open-Closed Principle - This rule reports use of switching on enums and classes, which may be a sign of violation the open closed principle.

Interface Segregation Principle

lcom

Single Responsibility Principle

lcom

Open-Closed Principle

lcom

Using detekt-hint

If you just want to analyze some code without bothering with the Danger integration (which really defeats the purpose of the tool) head to the command line section.

With Github Actions

  1. Configure a detekt-hint-config.yml to include detekt-hint rules and put it in a folder called "config" in your root project folder.

config/detekt-hint-config.yml

detekt-hint:
  UseCompositionInsteadOfInheritance:
    active: true
    yourUniquePackageName: "io.github.mkohm"
  LackOfCohesionMethods:
    active: true
    threshold: "0.8"
  InterfaceSegregationPrinciple:
      active: true
  OpenClosedPrinciple:
      active: true

Make sure you enter your unique package name in the configuration for the UseCompositionInsteadOfInheritance rule.

  1. Create a github action using the detekt-hint docker action.

.github/workflows/detekt-hint.yml

name: detekt hint

on:
  pull_request:
    branches:
      - '*'

jobs:
  gradle:
    strategy:
      matrix:
        os: [ubuntu-latest]
        jdk: [11]
    runs-on: ${{ matrix.os }}
    if: ${{ !contains(github.event.head_commit.message, 'detekt hint skip') }}
    env:
      JDK_VERSION:  ${{ matrix.jdk }}
    steps:
      - name: Checkout Repo
        uses: actions/checkout@v2
        
      - name: Run detekt hint
        uses: mkohm/[email protected]
        with:
          github-api-token: ${{ secrets.GITHUB_TOKEN }}
  1. Create a PR and see detekt-hint run as a separate action.

Having trouble? Please create an issue or contact me on the kotlinlang Slack (username: mkohm), and i will help you out.

With the command line

If you only want to do some analysis on your code without the power of Danger commenting on your PR you can use the tool from the command line. You must first clone detekt and detekt-hint repositories, and then build the required jars:

git clone https://github.com/Mkohm/detekt-hint && git clone https://github.com/arturbosch/detekt && cd detekt-hint && ./gradlew jar && cd ../detekt/ && ./gradlew build shadowJar && cd ..

Use the command line utility:

java -jar detekt/detekt-cli/build/libs/detekt-cli-[version]-all.jar --plugins detekt-hint/build/libs/detekt-hint-[version].jar --config detekt-hint/config/detekt.yml --classpath <your-classpath> --input <path-to-your-awesome-project>

For example:

java -jar detekt/detekt-cli/build/libs/detekt-cli-1.5.0-all.jar --plugins detekt-hint/build/libs/detekt-hint-0.0.2.jar --config detekt-hint/config/detekt.yml --classpath detekt-hint/ --input detekt-hint/

Remember to enter the latest detekt-cli version, the latest detekt-hint version and the path to your classpath and source code. Also, make sure that the detekt.yml you are using contains the unique package name in the configuration for the UseCompositionInsteadOfInheritance rule.

You might also like...
Kotlin-client-dsl - A kotlin-based dsl project for a (Client) - (Plugin) styled program

kotlin-client-dsl a kotlin-based dsl project for a (Client) - (Plugin) styled p

Same as an Outlined text fields presented in Material Design page but with some dynamic changes
Same as an Outlined text fields presented in Material Design page but with some dynamic changes

README SSCustomEditTextOutlineBorder Getting Started SSCustomEditTextOutLineBorder is a small kotlin library for android to support outlined (stroked)

:octocat: A demo project based on MVVM architecture and material design & animations.
:octocat: A demo project based on MVVM architecture and material design & animations.

GithubFollows A simple demo project based on MVVM clean architecture and material design & animations. Architecture Specs & Open-source libraries Mini

NoteApp - Simple Note app using Room database and MVVM design pattern
NoteApp - Simple Note app using Room database and MVVM design pattern

General Used Room Database and Followed MVVM Architecture Pattern to build the a

It is far easier to design a class to be thread-safe than to retrofit it for thread safety later
It is far easier to design a class to be thread-safe than to retrofit it for thread safety later

"It is far easier to design a class to be thread-safe than to retrofit it for thread safety later." (Brian Goetz - Java concurrency: Publisher: Addiso

CryptoMovies is a small app that show modern Android developement: with Hilt, Coroutines, Flow, Jetpack and Material Design 3
CryptoMovies is a small app that show modern Android developement: with Hilt, Coroutines, Flow, Jetpack and Material Design 3

CryptoMovies is a small app that show modern Android developement: with Hilt, Coroutines, Flow, Jetpack and Material Design 3.

This app features -  Modern Design, MVVM, Hilt, Room, StateFlow, Jetpack Compose
This app features - Modern Design, MVVM, Hilt, Room, StateFlow, Jetpack Compose

MyMusic is a beautiful app showing how to build modern looking interfaces using Jetpack Compose, recommended libraries, best practices and architectur

Spigot-Plugin message providing system written in Kotlin

teller Spigot-Plugin message providing system written in Kotlin Usage Create an instance of PropertiesMessageProvider using the Constructor with an in

An under development minecraft plugin (1.8.8) to learning Kotlin language

CorePlus CorePlus is a minecraft plugin coded with Kotlin language. Still under development CorePlus will be an essential for each minecraft servers !

Comments
  • Bump addressable from 2.7.0 to 2.8.0

    Bump addressable from 2.7.0 to 2.8.0

    Bumps addressable from 2.7.0 to 2.8.0.

    Changelog

    Sourced from addressable's changelog.

    Addressable 2.8.0

    • fixes ReDoS vulnerability in Addressable::Template#match
    • no longer replaces + with spaces in queries for non-http(s) schemes
    • fixed encoding ipv6 literals
    • the :compacted flag for normalized_query now dedupes parameters
    • fix broken escape_component alias
    • dropping support for Ruby 2.0 and 2.1
    • adding Ruby 3.0 compatibility for development tasks
    • drop support for rack-mount and remove Addressable::Template#generate
    • performance improvements
    • switch CI/CD to GitHub Actions
    Commits
    • 6469a23 Updating gemspec again
    • 2433638 Merge branch 'main' of github.com:sporkmonger/addressable into main
    • e9c76b8 Merge pull request #378 from ashmaroli/flat-map
    • 56c5cf7 Update the gemspec
    • c1fed1c Require a non-vulnerable rake
    • 0d8a312 Adding note about ReDoS vulnerability
    • 89c7613 Merge branch 'template-regexp' into main
    • cf8884f Note about alias fix
    • bb03f71 Merge pull request #371 from charleystran/add_missing_encode_component_doc_entry
    • 6d1d809 Adding note about :compacted normalization
    • Additional commits viewable in compare view

    Dependabot compatibility score

    Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting @dependabot rebase.


    Dependabot commands and options

    You can trigger Dependabot actions by commenting on this PR:

    • @dependabot rebase will rebase this PR
    • @dependabot recreate will recreate this PR, overwriting any edits that have been made to it
    • @dependabot merge will merge this PR after your CI passes on it
    • @dependabot squash and merge will squash and merge this PR after your CI passes on it
    • @dependabot cancel merge will cancel a previously requested merge and block automerging
    • @dependabot reopen will reopen this PR if it is closed
    • @dependabot close will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually
    • @dependabot ignore this major version will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this minor version will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this dependency will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)
    • @dependabot use these labels will set the current labels as the default for future PRs for this repo and language
    • @dependabot use these reviewers will set the current reviewers as the default for future PRs for this repo and language
    • @dependabot use these assignees will set the current assignees as the default for future PRs for this repo and language
    • @dependabot use this milestone will set the current milestone as the default for future PRs for this repo and language

    You can disable automated security fix PRs for this repo from the Security Alerts page.

    dependencies 
    opened by dependabot[bot] 1
  • Snippet of githubaction is nt working

    Snippet of githubaction is nt working

    Hi :). I try to make the plugin work with the danger bot but when i run the github action on PR, i have the following : Capture d’écran 2020-12-01 à 10 00 22 But i dont understand whats happening. Thank you :)

    opened by SaezChristopher 1
  • Bump kramdown from 2.1.0 to 2.3.0

    Bump kramdown from 2.1.0 to 2.3.0

    Bumps kramdown from 2.1.0 to 2.3.0.

    Commits

    Dependabot compatibility score

    Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting @dependabot rebase.


    Dependabot commands and options

    You can trigger Dependabot actions by commenting on this PR:

    • @dependabot rebase will rebase this PR
    • @dependabot recreate will recreate this PR, overwriting any edits that have been made to it
    • @dependabot merge will merge this PR after your CI passes on it
    • @dependabot squash and merge will squash and merge this PR after your CI passes on it
    • @dependabot cancel merge will cancel a previously requested merge and block automerging
    • @dependabot reopen will reopen this PR if it is closed
    • @dependabot close will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually
    • @dependabot ignore this major version will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this minor version will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this dependency will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)
    • @dependabot use these labels will set the current labels as the default for future PRs for this repo and language
    • @dependabot use these reviewers will set the current reviewers as the default for future PRs for this repo and language
    • @dependabot use these assignees will set the current assignees as the default for future PRs for this repo and language
    • @dependabot use this milestone will set the current milestone as the default for future PRs for this repo and language

    You can disable automated security fix PRs for this repo from the Security Alerts page.

    dependencies 
    opened by dependabot[bot] 1
  • Rule: Analysing LCOM value (Lack Of Cohesion of Methods) (Sign of Single Responsibility Principle violation)

    Rule: Analysing LCOM value (Lack Of Cohesion of Methods) (Sign of Single Responsibility Principle violation)

    https://blog.ndepend.com/lack-of-cohesion-methods/

    Suggestion: Can report classes with low lcom and which methods with low cohesion, that are subject for refactoring.

    enhancement 
    opened by Mkohm 1
Owner
Marius Kohmann
App, app, app
Marius Kohmann
Detekt rule no string parameter with kotlin

Detekt custom rule template This repository is a template. You can use it to generate your own repository to write and share your custom rules. How to

Christian Wüstner 0 Nov 26, 2021
With Viola android face detection library, you can detect faces in a bitmap, crop faces using predefined algorithm and get additional information from the detected faces.

Viola Viola android face detection library detects faces automatically from a bitmap, crop faces using the predefined algorithms, and provides supplem

Darwin Francis 58 Nov 1, 2022
On-device wake word detection powered by deep learning.

Porcupine Made in Vancouver, Canada by Picovoice Porcupine is a highly-accurate and lightweight wake word engine. It enables building always-listening

Picovoice 2.8k Dec 30, 2022
Plugin-shared-preferences - Pluto plugin to manage your Shared Preferences

Pluto Shared Preferences Plugin Pluto Shared Preferences is a Pluto plugin to in

Pluto 1 Feb 14, 2022
A somewhat copy past of Jetbrain's code from the kotlin plugin repo to make it humanly possible to test Intellij IDEA kotlin plugins that work on kotlin

A somewhat copy past of Jetbrain's code from the kotlin plugin repo to make it humanly possible to test Intellij IDEA kotlin plugins that work on kotlin

common sense OSS 0 Jan 20, 2022
🎬 A demo project for The Movie DB based on Kotlin MVVM architecture and material design & animations.

TheMovies A simple project for The Movie DB based on Kotlin MVVM clean architecture and material design & animations. How to build on your environment

Jaewoong Eum 419 Jan 7, 2023
Hands-On-Design-Patterns-with-Kotlin, published by Packt

Hands-on-Design-Patterns-with-Kotlin This is the code repository for Hands-on-Design-Patterns-with-Kotlin, published by Packt. Build scalable applicat

Alexey Soshin 26 Nov 3, 2022
Design Patterns implemented in Kotlin

Design Patterns In Kotlin ⚠️ New article about testing: Unit Testing with Mockito 2 Project maintained by @dbacinski (Dariusz Baciński) Inspired by De

Dariusz Baciński 5.5k Jan 4, 2023
Simple Design for Kotlin bridge with Javascript. Also can get javascript console.log.

SDBridgeJava is here. If your h5 partner confused about how to deal with iOS and Android. This Demo maybe help. bilibili video introduction is here. Y

null 14 Dec 19, 2022
Spring Kotlin Design Patterns

Spring Kotlin Design Patterns This is a project for learning design patterns in Kotlin Sources 1- GURU Requirements Java 11+ IntelliJ IDEA / Netbeans

Gustavo 2 Nov 22, 2022