使用 SonarQube 在 Rails 个项目上扫描 Ruby

Scanning Ruby on Rails Projects with SonarQube

我想用 sonarqube 在 Rails 应用程序上检查我的 Ruby。我已经添加了应该与 Ruby 一起使用的 Web 插件,但是我在声纳执行期间收到以下错误:

app/controllers/course_statistics_controller.rb
java.lang.NullPointerException: null
at org.sonar.plugins.web.checks.sonar.UnsupportedTagsInHtml5Check.isUnsupportedTag(UnsupportedTagsInHtml5Check.java:77) ~[na:na]
at org.sonar.plugins.web.checks.sonar.UnsupportedTagsInHtml5Check.startElement(UnsupportedTagsInHtml5Check.java:71) ~[na:na]
at org.sonar.plugins.web.visitor.HtmlAstScanner.scanElementTag(HtmlAstScanner.java:117) ~[na:na]
at org.sonar.plugins.web.visitor.HtmlAstScanner.scanElement(HtmlAstScanner.java:96) ~[na:na]
at org.sonar.plugins.web.visitor.HtmlAstScanner.scan(HtmlAstScanner.java:80) ~[na:na]
at org.sonar.plugins.web.visitor.HtmlAstScanner.scan(HtmlAstScanner.java:59) ~[na:na]
at org.sonar.plugins.web.core.WebSensor.analyse(WebSensor.java:93) ~[na:na]
at org.sonar.batch.phases.SensorsExecutor.executeSensor(SensorsExecutor.java:59) [sonar-batch-maven-compat-5.1.jar:na]
at org.sonar.batch.phases.SensorsExecutor.execute(SensorsExecutor.java:51) [sonar-batch-maven-compat-5.1.jar:na]
at org.sonar.batch.phases.DatabaseModePhaseExecutor.execute(DatabaseModePhaseExecutor.java:120) [sonar-batch-maven-compat-5.1.jar:na]
at org.sonar.batch.scan.ModuleScanContainer.doAfterStart(ModuleScanContainer.java:264) [sonar-batch-maven-compat-5.1.jar:na]
at org.sonar.api.platform.ComponentContainer.startComponents(ComponentContainer.java:92) [sonar-batch-maven-compat-5.1.jar:na]
at org.sonar.api.platform.ComponentContainer.execute(ComponentContainer.java:77) [sonar-batch-maven-compat-5.1.jar:na]
at org.sonar.batch.scan.ProjectScanContainer.scan(ProjectScanContainer.java:235) [sonar-batch-maven-compat-5.1.jar:na]
at org.sonar.batch.scan.ProjectScanContainer.scanRecursively(ProjectScanContainer.java:230) [sonar-batch-maven-compat-5.1.jar:na]
at org.sonar.batch.scan.ProjectScanContainer.doAfterStart(ProjectScanContainer.java:220) [sonar-batch-maven-compat-5.1.jar:na]
at org.sonar.api.platform.ComponentContainer.startComponents(ComponentContainer.java:92) [sonar-batch-maven-compat-5.1.jar:na]
at org.sonar.api.platform.ComponentContainer.execute(ComponentContainer.java:77) [sonar-batch-maven-compat-5.1.jar:na]
at org.sonar.batch.scan.ScanTask.scan(ScanTask.java:57) [sonar-batch-maven-compat-5.1.jar:na]
at org.sonar.batch.scan.ScanTask.execute(ScanTask.java:45) [sonar-batch-maven-compat-5.1.jar:na]
at org.sonar.batch.bootstrap.TaskContainer.doAfterStart(TaskContainer.java:135) [sonar-batch-maven-compat-5.1.jar:na]
at org.sonar.api.platform.ComponentContainer.startComponents(ComponentContainer.java:92) [sonar-batch-maven-compat-5.1.jar:na]
at org.sonar.api.platform.ComponentContainer.execute(ComponentContainer.java:77) [sonar-batch-maven-compat-5.1.jar:na]
at org.sonar.batch.bootstrap.GlobalContainer.executeTask(GlobalContainer.java:158) [sonar-batch-maven-compat-5.1.jar:na]
at org.sonar.batch.bootstrapper.Batch.executeTask(Batch.java:95) [sonar-batch-maven-compat-5.1.jar:na]
at org.sonar.batch.bootstrapper.Batch.execute(Batch.java:67) [sonar-batch-maven-compat-5.1.jar:na]
at org.sonar.runner.batch.IsolatedLauncher.execute(IsolatedLauncher.java:48) [sonar-runner-batch1741912612400004619.jar:na]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.7.0_65]
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) ~[na:1.7.0_65]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.7.0_65]
at java.lang.reflect.Method.invoke(Method.java:606) ~[na:1.7.0_65]
at org.sonar.runner.impl.BatchLauncher.delegateExecution(BatchLauncher.java:87) [sonar-runner-dist-2.4.jar:na]
at org.sonar.runner.impl.BatchLauncher.run(BatchLauncher.java:75) [sonar-runner-dist-2.4.jar:na]
at java.security.AccessController.doPrivileged(Native Method) [na:1.7.0_65]
at org.sonar.runner.impl.BatchLauncher.doExecute(BatchLauncher.java:69) [sonar-runner-dist-2.4.jar:na]
at org.sonar.runner.impl.BatchLauncher.execute(BatchLauncher.java:50) [sonar-runner-dist-2.4.jar:na]
at org.sonar.runner.api.EmbeddedRunner.doExecute(EmbeddedRunner.java:102) [sonar-runner-dist-2.4.jar:na]
at org.sonar.runner.api.Runner.execute(Runner.java:100) [sonar-runner-dist-2.4.jar:na]
at org.sonar.runner.Main.executeTask(Main.java:70) [sonar-runner-dist-2.4.jar:na]
at org.sonar.runner.Main.execute(Main.java:59) [sonar-runner-dist-2.4.jar:na]
at org.sonar.runner.Main.main(Main.java:53) [sonar-runner-dist-2.4.jar:na]

怎么了?

SonarQube 已放弃对 Ruby 的支持。

如果您想为您的应用程序提供代码样式检查,请查看以下链接:

Ruby Style Guide.

RuboCop - Ruby static code analyzer. Out of the box it will enforce many of the guidelines outlined in the community rails-style-guide。非常可配置且维护良好 gem.

Guard-ruboCop - 允许您在修改文件时使用 RuboCop 自动检查 Ruby 代码风格。

Rails best practices - 用于检查 rails 鳕鱼质量的代码度量工具。维护良好。

Simplecov - Ruby(测试)的代码覆盖率分析工具。

Reek - 是一种检查 Ruby 类、模块和方法并报告它发现的任何代码味道的工具。

https://ebertapp.io/ 是 rails 代码审查的好选择

看起来 SonarQube 7.4 现在支持 Ruby!

https://www.sonarqube.org/sonarqube-7-4/