javascript 如何为 Node JS 项目集成声纳?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/31980418/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-28 14:41:50  来源:igfitidea点击:

How to integrate sonar for a Node JS project?

javascriptnode.jssonarqubesonar-runnergruntfile

提问by Irfan Fuard

I have integrated sonarqube to my Node JS project which am working and it seems to be working fine with the javascript plugin. I would like to know if there is any way we can specifically mention sonarqube to check the javascript as Node JS?

我已将 sonarqube 集成到我的 Node JS 项目中,该项目正在运行,并且它似乎与 javascript 插件一起工作正常。我想知道是否有任何方法可以特别提到 sonarqube 来检查 javascript 作为 Node JS?

The configurations to run sonar is specified in the gruntfile.js as below,

运行声纳的配置在 gruntfile.js 中指定如下,

sonarRunner: {
    analysis: {
        options: {
            debug: true,
            separator: '\n',
            dryRun: false,
            sonar: {
                host: {
                    url: 'http://localhost:9000'
                },
                jdbc: {
                    url: 'jdbc:mysql://localhost:3306/sonar?useUnicode=true&characterEncoding=utf8&rewriteBatchedStatements=true&useConfigs=maxPerformance',
                    username: 'root',
                    password: 'root'
                },

                projectKey: 'sonar:grunt-sonar-runner:0.1.0',
                projectName: 'Grunt Sonar Runner',
                projectVersion: '0.10',
                sources: '/app/scripts/controllers',
                language:'js',
                sourceEncoding: 'UTF-8'
            }
        }
    }
}

回答by G. Ann - SonarSource Team

The only library/framework-specific parameter available for JavaScript analysis is related to jQuery, so there's no need to make this distinction in your analysis.

唯一可用于 JavaScript 分析的库/框架特定参数与 jQuery 相关,因此无需在您的分析中进行区分。

However, if there were library-specific settings related to Node.js, you would have two options:

但是,如果有与 Node.js 相关的特定于库的设置,您将有两个选择:

  • simply add the setting in your parameters block. E.G. sonar.javascript.jQueryObjectAliases: foo
  • make the setting change via the project administration GUI (which is the preferred method)
  • 只需在您的参数块中添加设置。例如sonar.javascript.jQueryObjectAliases: foo
  • 通过项目管理 GUI 进行设置更改(这是首选方法)

If there are specific rule parameters that should be altered for Node.js projects, then you should accomplish that by creating a Node.js-specific rule profile with those parameter settings and assigning your project to it.

如果应该为 Node.js 项目更改特定的规则参数,那么您应该通过使用这些参数设置创建一个特定于 Node.js 的规则配置文件并将您的项目分配给它来实现。