• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

SonarSource/sonar-kotlin: SonarSource Static Analyzer for Kotlin Code Quality an ...

原作者: [db:作者] 来自: 网络 收藏 邀请

开源软件名称(OpenSource Name):

SonarSource/sonar-kotlin

开源软件地址(OpenSource Url):

https://github.com/SonarSource/sonar-kotlin

开源编程语言(OpenSource Language):

Kotlin 78.5%

开源软件介绍(OpenSource Introduction):

Code Quality and Security for Kotlin

Build Status Quality Gate Status Coverage

This SonarSource project is a code analyzer for Kotlin projects.

Features

  • 50+ rules (including 10+ security rules using semantic)
  • Metrics (cognitive complexity, cyclomatic complexity, number of lines etc.)
  • Import of test coverage reports
  • Import of external linters: Detekt, ktLint, AndroidLint

Useful links

Build

Build and run Unit Tests:

./gradlew build

Integration Tests

By default, Integration Tests (ITs) are skipped during the build. If you want to run them, you need first to retrieve the related projects which are used as input:

git submodule update --init its/sources
cd its/sources/kotlin/ktor

Then you need to switch to Java8 and run the command to generate binaries for Ktor project:

./gradlew assemble

Then build and run the Integration Tests using the its property:

./gradlew build -Pits --info --no-daemon -Dsonar.runtimeVersion=7.9

You can also build and run only Ruling Tests using the ruling property:

./gradlew build -Pruling --info --no-daemon -Dsonar.runtimeVersion=7.9

You can also build and run only Plugin Tests using the plugin property:

./gradlew build -Pplugin --info --no-daemon -Dsonar.runtimeVersion=7.9

To run e.g. the ruling tests in the IDE, create a new Run/Debug Configuration where you run the following:

:its:ruling:test -Pruling -Dsonar.runtimeVersion=7.9

You can also run single ruling tests, e.g.:

:its:ruling:test --tests "org.sonarsource.slang.SlangRulingTest.test_kotlin_corda" -Pruling -Dsonar.runtimeVersion=7.9

Debugging ruling tests

You can debug the scanner when running ruling tests. As a new JVM is spawned to run the analysis you can't simply click 'debug' on a ruling test, however. You need to tell the Sonar Scanner (which is being used to run the analysis in the background) to launch a debuggable JVM. Then you can attach to this JVM instance and debug as normal via your IDE.

The ruling test already provides a convenient API where all you need to do is supply the port you want to debug on (e.g. 5005) to sonar.rulingDebugPort. So, for instance, if you start the ruling tests from the CLI, run:

./gradlew build -Pruling --info --no-daemon -Dsonar.runtimeVersion=7.9 -Dsonar.rulingDebugPort=5005

You can obviously do the same in the IDE and/or only run a particular test:

:its:ruling:test --tests "org.sonarsource.slang.SlangRulingTest.test_kotlin_corda" -Pruling -Dsonar.runtimeVersion=7.9 -Dsonar.rulingDebugPort=5005

Utilities and Developing

Generating/downloading rule metadata

The Gradle task generateRuleMetadata will download the rule metadata from the RSPEC repository.

For example, execute the following in the project root to fetch the metadata for rule S42:

./gradlew generateRuleMetadata -PruleKey=S42

If you want to update all rules' metadata, you can use:

./gradlew updateRuleMetadata

Implementing a new rule

The Gradle task setupRuleStubs will create the commonly required files for implementing a new rule, including usual boilerplate code. It will also put the rule into the list of checks and call generateRuleMetadata to download the rule's metadata.

To use this task, you need to know the rule key and a fitting name for the check class. For instance, if you want to implement the new rule S42 in the class AnswersEverythingCheck, you can call the following in the root of the project:

./gradlew setupRuleStubs -PruleKey=S42 -PclassName=AnswersEverythingCheck



鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap