标签: codacy

如何为 clang-tidy 指定编译数据库

我正在努力为我的项目运行 clang-tidy 。我正在尝试为我的项目运行 clang-tidy 以将数据发送到 Codacy。我这样做是这样的:

clang-tidy $PWD -header-filter=.*,-checks=-*,clang-analyzer-*,-clang-analyzer-cplusplus* | ./codacy-clang-tidy-1.1.1 | \
        curl -XPOST -L -H "project-token: $CODACY_PROJECT_TOKEN" \
            -H "Content-type: application/json" -d @- \
            "https://api.codacy.com/2.0/commit/$TRAVIS_COMMIT/issuesRemoteResults"

        curl -XPOST -L -H "project-token: $CODACY_PROJECT_TOKEN" \
            -H "Content-type: application/json" \
            "https://api.codacy.com/2.0/commit/$TRAVIS_COMMIT/resultsFinal"
Run Code Online (Sandbox Code Playgroud)

但报错找不到编译数据:

Error while trying to load a compilation database:
Could not auto-detect compilation database for file "/home/travis/build/mVento3/Duckvil/build"
No compilation database found in /home/travis/build/mVento3/Duckvil or any parent directory
fixed-compilation-database: Error while opening fixed database: No such file or directory
json-compilation-database: Error while …
Run Code Online (Sandbox Code Playgroud)

c++ continuous-integration cmake codacy clang-tidy

9
推荐指数
1
解决办法
1万
查看次数

来自codacy的Eslint配置文件

我正在使用codacy来监控代码质量,但是看看在推送之前会遇到什么样的代码会很好.我看到它使用eslint和其他几种工具来决定捕获什么.有没有办法从codacy生成.eslintrc配置文件?这样我就可以在Webstorm中使用此配置,并在推送任何代码之前进行任何必要的更改.

javascript software-quality webstorm eslint codacy

7
推荐指数
1
解决办法
838
查看次数

scala.util.Try比try..catch有什么优势?

在线搜索答案给出了两个突出的帖子(CodacyDaniel Westheide),两者都给出了与Scala官方文档Try相同的答案:

上面示例中显示的Try的一个重要属性是它能够管理或链接操作,沿途捕获异常.

上面引用的示例是:

import scala.io.StdIn
import scala.util.{Try, Success, Failure}

def divide: Try[Int] = {
  val dividend = Try(StdIn.readLine("Enter an Int that you'd like to divide:\n").toInt)
  val divisor = Try(StdIn.readLine("Enter an Int that you'd like to divide by:\n").toInt)
  val problem = dividend.flatMap(x => divisor.map(y => x/y))
  problem match {
    case Success(v) =>
      println("Result of " + dividend.get + "/"+ divisor.get +" is: " + v)
      Success(v)
    case Failure(e) =>
      println("You must've divided by zero …
Run Code Online (Sandbox Code Playgroud)

monads scala try-catch codacy

7
推荐指数
1
解决办法
1800
查看次数

Scala避免使用null

我在github上有一个通过编码进行分析的项目.分析建议对以下代码行使用"避免使用null":

def doSomethingWithPath(path:Path) = {
    require(path != null, "Path should not be null") //<-to avoid
    ...
}
Run Code Online (Sandbox Code Playgroud)

什么是最简单的scala惯用法来修复它?

scala idiomatic preconditions codacy

7
推荐指数
2
解决办法
1354
查看次数

requireNotNull vs确定运算符!在科特林

我们有一个基于Kotlin的应用程序,最近我们添加了第三方代码质量工具(Codacy中的Detekt)。但是,我们开始遇到UnsafeCallOnNullableType错误。我们发现可行的方法是在所有可能为null的参数上添加requireNotNull检查。当前,我们正在使用肯定运算符(!!)

我们是否有任何特定的理由或约定选择一个而不是另一个。据我所知,两者都将抛出Exception并阻塞执行流程,除了一个将抛出IllegalArgumentException,而另一个将抛出NullPointerException。

kotlin codacy

7
推荐指数
1
解决办法
664
查看次数

需要空格缩进 - Codacy

我听说好的做法是使用一些东西来检查我的代码。我找到了一个叫做Codacy 的东西。我理解除了来自 TSLint 和 TSLint4 的“预期空格缩进”之外的所有内容。是因为我在项目中的身份是标签吗?如果是,我怎样才能改变这一规则?

import {NgModule} from '@angular/core';
import {CommonModule}  from '@angular/common';
import {RouterModule, Routes} from '@angular/router';

import {TranslationModule} from '../translate.module';

const adminRoutes: Routes = [
    {
        path: 'admin',
        children: [
        ]
    }
];

@NgModule({
    imports: [
    CommonModule, RouterModule.forRoot(adminRoutes), TranslationModule
    ],
    declarations: [
    ],
    exports: [
    ]
})
export class AdminModule { }
Run Code Online (Sandbox Code Playgroud)

Codacy 显示问题

{
    path: 'admin',
    children: [
    ]
}
Run Code Online (Sandbox Code Playgroud)

typescript tslint codacy angular

5
推荐指数
1
解决办法
8825
查看次数

为什么调用带有变量的数组索引很糟糕?

我目前正在用Javascript开发一个小游戏,并且正在使用Codacy查看我的代码并帮助我清理它。

最常见的错误之一是通用对象注入接收器(安全性/检测对象注入)。

当我尝试使用变量访问数组中的值时,就会发生这种情况。像这个例子:

function getValString(value)
{
    var values = ["Mis&eacuterable", "Acceptable", "Excellente", "Divine"];
    return values[value];
}
Run Code Online (Sandbox Code Playgroud)

此功能用于在屏幕上显示项目的值字符串。它接收一个可以为0、1、2或3的“值”,并返回该值的字符串。

现在这是我的问题:

Codacy告诉我应该禁止使用var [var],因为它会引起安全问题,并且由于我对javascript不太熟悉,所以我想知道为什么以及在这种情况下的良好做法是什么?

javascript arrays optimization codacy

5
推荐指数
2
解决办法
2896
查看次数

守则不好 第一个参数给了 super

在通过codacy审查一些代码时,Codacy给出了以下代码的问题:

def MyClass(OldClass):
    def __init__(self, arg1, arg2, *args, **kwargs)
        self.arg1 = arg1
        self.arg2 = arg2
        super(OldClass, self).__init__(*args, **kwargs)
Run Code Online (Sandbox Code Playgroud)

解释如下:

为什么这是一个问题?

例如,使用基类作为第一个参数调用 super() 是错误的:

class AnotherOldStyleClass(OldStyleClass):
    def __init__(self):
        super(OldStyleClass, self).__init__() The super invocation 
Run Code Online (Sandbox Code Playgroud)

应该:

super(AnotherOldStyleClass, self).__init__()
Run Code Online (Sandbox Code Playgroud)

它似乎希望我这样做:

def MyClass(OldClass):
    def __init__(self, arg1, arg2, *args, **kwargs)
        self.arg1 = arg1
        self.arg2 = arg2
        super(OldClass, self).__init__(*args, **kwargs)
Run Code Online (Sandbox Code Playgroud)

或者也许是这样的:

def MyClass(OldClass):
    def __init__(self, arg1, arg2, *args, **kwargs)
        super(MyClass, self).__init__(*args, **kwargs)
        self.arg1 = arg1
        self.arg2 = arg2
Run Code Online (Sandbox Code Playgroud)

有人可以告诉我哪一个是正确的以及为什么这是首选行为?

作为参考,这里是我使用选项 2 找到的示例。

编辑:这是我的代码,因为它看起来完全一样。这解释了我的错误:

class TransferToBigQuery(GoogleCloudStorageToBigQueryOperator): …
Run Code Online (Sandbox Code Playgroud)

python optimization codacy

5
推荐指数
1
解决办法
2167
查看次数

为允许的方案打开审核URL。允许使用“文件:”或自定义方案通常是意外的

我在Python中使用此语句

 jsonreq = json.dumps({'jsonrpc': '2.0', 'id': 'qwer', 'method': 'aria2.pauseAll'})
 jsonreq = jsonreq.encode('ascii')
 c = urllib.request.urlopen('http://localhost:6800/jsonrpc', jsonreq)
Run Code Online (Sandbox Code Playgroud)

在执行代码质量测试时,我收到此警告/错误

为允许的方案打开审核URL。经常允许使用“ file:”或自定义方案。

python pytest codacy

5
推荐指数
2
解决办法
872
查看次数

配置 Codacy 来检查受监控分支的所有分支?

现在我们有 Codacy 监控一个 DEV 分支,并且根据推荐的做法,每当我们做某事时,我们都会创建一个 DEV 的个人分支,对其进行处理,然后合并回来。事实是,如果 Codacy 发现问题,我们就会有从 DEV 中分支出来,修改,然后再次合并回来。同时,DEV 有这个有缺陷的代码,所以我们必须撤消那个合并,等等。如果你惊慌失措,那么有很大的出错空间,因为海外的人很快就会上线!

我想到了三种可接受的解决方案,可能更多:

  • 配置 Codacy 以在提交后检查受监控分支的所有分支
  • 我们倾向于一致地命名我们的分支,因此可以指定正则表达式
  • 配置 GitHub 和/或 Codacy 以防止在存在悬而未决的 Codacy 问题时拉取受监控的分支

这些可能吗?

configuration github codacy

5
推荐指数
1
解决办法
685
查看次数