如何在Sonarqube Javascript扩展中获取项目路径

时间:2023-02-05 18:01:03

I am writing a custom rules plugin for the SonarQube Javascript Plugin. Now I want to disable my check in specific directories by the rule. (It should not be checked in the bin path for example)

我正在为SonarQube Javascript插件编写自定义规则插件。现在我想通过规则禁用我在特定目录中的检查。 (例如,不应在bin路径中检查)

Now my question: how can I get the path of the file that is checked relative to the project path. Or another Solution would be: How to get the project path?

现在我的问题是:如何获取相对于项目路径检查的文件的路径。或者另一个解决方案是:如何获得项目路径?

My code is:

我的代码是:

@Override
public void visitNode(Tree tree) {
    CallExpressionTree callExpression = (CallExpressionTree) tree;

    if (callExpression.callee().is(Kind.DOT_MEMBER_EXPRESSION)) {
        DotMemberExpressionTree callee = (DotMemberExpressionTree) callExpression.callee();

        // get the file that is checked
        File toTestedFile = getContext().getFile();

        //how to get the project path here to get the relative path???

        if (isCalleeConsoleLogging(callee)) {
            addLineIssue(tree, MESSAGE);
        }
    }

}

1 个解决方案

#1


2  

This is what the platform exclusions mechanism is for. If I were you, I wouldn't try to put such exclusions into a rule implementation. Instead, just write a blanket/generic rule implementation and set Issue exclusions at the global level to ignore the directories you want to leave out.

这就是平台排除机制的用途。如果我是你,我不会尝试将这些排除纳入规则实施。相反,只需编写一揽子/通用规则实现,并在全局级别设置问题排除,以忽略您想要忽略的目录。

#1


2  

This is what the platform exclusions mechanism is for. If I were you, I wouldn't try to put such exclusions into a rule implementation. Instead, just write a blanket/generic rule implementation and set Issue exclusions at the global level to ignore the directories you want to leave out.

这就是平台排除机制的用途。如果我是你,我不会尝试将这些排除纳入规则实施。相反,只需编写一揽子/通用规则实现,并在全局级别设置问题排除,以忽略您想要忽略的目录。