我正在努力为我的项目运行 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) 我正在使用codacy来监控代码质量,但是看看在推送之前会遇到什么样的代码会很好.我看到它使用eslint和其他几种工具来决定捕获什么.有没有办法从codacy生成.eslintrc配置文件?这样我就可以在Webstorm中使用此配置,并在推送任何代码之前进行任何必要的更改.
在线搜索答案给出了两个突出的帖子(Codacy和Daniel 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) 我在github上有一个通过编码进行分析的项目.分析建议对以下代码行使用"避免使用null":
def doSomethingWithPath(path:Path) = {
require(path != null, "Path should not be null") //<-to avoid
...
}
Run Code Online (Sandbox Code Playgroud)
什么是最简单的scala惯用法来修复它?
我们有一个基于Kotlin的应用程序,最近我们添加了第三方代码质量工具(Codacy中的Detekt)。但是,我们开始遇到UnsafeCallOnNullableType错误。我们发现可行的方法是在所有可能为null的参数上添加requireNotNull检查。当前,我们正在使用肯定运算符(!!)
我们是否有任何特定的理由或约定选择一个而不是另一个。据我所知,两者都将抛出Exception并阻塞执行流程,除了一个将抛出IllegalArgumentException,而另一个将抛出NullPointerException。
我听说好的做法是使用一些东西来检查我的代码。我找到了一个叫做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) 我目前正在用Javascript开发一个小游戏,并且正在使用Codacy查看我的代码并帮助我清理它。
最常见的错误之一是通用对象注入接收器(安全性/检测对象注入)。
当我尝试使用变量访问数组中的值时,就会发生这种情况。像这个例子:
function getValString(value)
{
var values = ["Misérable", "Acceptable", "Excellente", "Divine"];
return values[value];
}
Run Code Online (Sandbox Code Playgroud)
此功能用于在屏幕上显示项目的值字符串。它接收一个可以为0、1、2或3的“值”,并返回该值的字符串。
现在这是我的问题:
Codacy告诉我应该禁止使用var [var],因为它会引起安全问题,并且由于我对javascript不太熟悉,所以我想知道为什么以及在这种情况下的良好做法是什么?
在通过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() 是错误的:
Run Code Online (Sandbox Code Playgroud)class AnotherOldStyleClass(OldStyleClass): def __init__(self): super(OldStyleClass, self).__init__() The super invocation应该:
Run Code Online (Sandbox Code Playgroud)super(AnotherOldStyleClass, self).__init__()
它似乎希望我这样做:
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中使用此语句
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:”或自定义方案。
现在我们有 Codacy 监控一个 DEV 分支,并且根据推荐的做法,每当我们做某事时,我们都会创建一个 DEV 的个人分支,对其进行处理,然后合并回来。事实是,如果 Codacy 发现问题,我们就会有从 DEV 中分支出来,修改,然后再次合并回来。同时,DEV 有这个有缺陷的代码,所以我们必须撤消那个合并,等等。如果你惊慌失措,那么有很大的出错空间,因为海外的人很快就会上线!
我想到了三种可接受的解决方案,可能更多:
这些可能吗?
codacy ×10
javascript ×2
optimization ×2
python ×2
scala ×2
angular ×1
arrays ×1
c++ ×1
clang-tidy ×1
cmake ×1
eslint ×1
github ×1
idiomatic ×1
kotlin ×1
monads ×1
pytest ×1
try-catch ×1
tslint ×1
typescript ×1
webstorm ×1