Coder Social home page Coder Social logo

mkohm / detekt-hint Goto Github PK

View Code? Open in Web Editor NEW
79.0 5.0 3.0 9.17 MB

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

Home Page: https://mkohm.github.io/detekt-hint/

Kotlin 3.84% Ruby 0.15% TeX 9.01% HTML 86.99%
detekt detekt-plugin kotlin design-principles software-architecture static-code-analysis danger detekt-hint detections programming-principles

detekt-hint's Introduction

detekt-hint (Attention: Looking for developers)

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

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.

detekt-hint's People

Contributors

mkohm avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

Forkers

cyclopt hbmartin

detekt-hint's Issues

Adding context to rules

Since many programming principles can be confusing and easily misinterpreted, i think adding some context in the comment could be helpful. In addition to giving a rule of thumb when to use composition over inheritance one could also print the public interface of the different classes.

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 :)

Kotlinc crash during github action running

I encountered this problem.
Everything run fine on PR but when the githubaction is running, kotlinc is crashing

�[0;0mExecuting kotlinc -script-templates systems.danger.kts.DangerFileScript -cp /usr/local/lib/danger/danger-kotlin.jar -script /Dangerfile.df.kts /tmp/danger-dsl.json danger_out.json - pid 374�[0;0m
Uncaught Kotlin exception: kotlin.Exception: Command kotlinc -script-templates systems.danger.kts.DangerFileScript -cp /usr/local/lib/danger/danger-kotlin.jar -script /Dangerfile.df.kts /tmp/danger-dsl.json danger_out.json exited with code 256
    at kfun:systems.danger.cmd.Cmd#exec(){} (0x228518)
    at kfun:systems.danger.cmd.dangerfile.DangerFile#execute(kotlin.String;kotlin.String){} (0x22915b)
    at kfun:systems.danger.DangerKotlin#run(){} (0x227408)
    at Init_and_run_start (0x22c005)
    at __libc_start_main (0x7ff97b9ceb97)
    at  (0x211029)
    at  ((nil))

Enable filtering

Figure out how to enable filtering such that only changed files are commented on.

Resolving problem related to lots of files reformatted

This resulted in a rate-abuse error from github. A max count of comments could maybe be applied to handle these issues. Ideally detecting what is formatting changes, and ignore warnings on that kind of code-changes.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.