我是 npm 的新手,正在尝试了解重新创建node_modules部署目录的工作原理。
我们使用npm ci而不是npm install确保在部署期间干净利落。但是,当我们在没有任何标志的情况下运行它时,我们会收到以下错误:
修复上游依赖冲突,或使用 --force 或 --legacy-peer-deps 重试此命令以接受不正确(并且可能已损坏)的依赖解析。
该文件为npm install用于--force如下(有上没有国旗npm ci的页面):
-f 或 --force 参数将强制 npm 获取远程资源,即使磁盘上存在本地副本。
同时,文档--legacy-peer-deps说:
--legacy-peer-deps:安装时忽略所有 peerDependencies,采用 npm 版本 4 到版本 6 的风格。
似乎这两个标志都npm ci可以node_modules毫无问题地生成目录,但我仍然不清楚两者之间的区别。
据我了解,--force听起来它将基于最后下载的依赖项,并将覆盖任何以前下载的依赖项。同时,--legacy-peer-deps听起来它在安装过程中总是会跳过对等依赖项(无论是什么),即使没有问题。
这两个标志有什么区别,我们什么时候应该使用它们?
我有下面的代码,它定义了一个枚举并用于enum.auto()给出从 1 开始的条目生成值:
from enum import Enum, auto
class Colors(Enum):
RED = auto()
BLUE = auto()
YELLOW = auto()
def main():
print(Colors.RED.value)
print(Colors.BLUE.value)
print(Colors.YELLOW.value)
if __name__ == '__main__':
main()
Run Code Online (Sandbox Code Playgroud)
输出:
1
2
3
Run Code Online (Sandbox Code Playgroud)
该代码工作正常并且过去没有任何警告,但今天更新 PyCharm 后,我现在收到以下警告auto():
Parameter(s) unfilled
Possible callees:
EnumMeta.__call__(cls: Type[_T], value, names: None = ...)
EnumMeta.__call__(cls: EnumMeta, value: str, names: Union[str, Iterable[str], Iterable[Iterable[str]], Mapping[str, Any]], *, module: Optional[str] = ..., qualname: Optional[str] = ..., type: Optional[type] = ..., start: int = ..., boundary: Optional[FlagBoundary] …Run Code Online (Sandbox Code Playgroud) 我注意到如果我尝试在for循环中使用goroutine附加到切片,则会出现我会丢失/空白数据的情况:
destSlice := make([]myClass, 0)
var wg sync.WaitGroup
for _, myObject := range sourceSlice {
wg.Add(1)
go func(closureMyObject myClass) {
defer wg.Done()
var tmpObj myClass
tmpObj.AttributeName = closureMyObject.AttributeName
destSlice = append(destSlice, tmpObj)
}(myObject)
}
wg.Wait()
Run Code Online (Sandbox Code Playgroud)
有时,当我打印所有AttributeNames时destSlice,一些元素是空字符串(""),有时,某些元素sourceSlice不存在destSlice.
我的代码是否有数据竞争,这是否意味着append多个goroutine并发使用它不是线程安全的?
我目前正在使用 VS Code 进行 C# 开发,因为我发现它比 Visual Studio 本身轻量得多,但似乎没有任何可用的代码分析工具。这是一个问题,因为我没有收到有关未使用函数的任何警告(但是,我能够收到有关未使用局部变量的警告)。
一些示例代码:
namespace MyProject
{
// No warning for this unused class.
public class Dog
{
private int _age;
private string _name;
// No warning for this unused field.
private string _furColor;
public Dog(int age, string name)
{
// This unused variable generates a warning as expected.
int unusedVariable = 2;
_age = age;
_name = name;
}
// No warning for this unused private function.
private int Age()
{ …Run Code Online (Sandbox Code Playgroud) 我用 测试我的代码go test ./... -v -short。
不幸的是,-v它只在每次测试发生时将其打印出来,而不会像 Java 那样在底部留下结果摘要。这意味着,如果顶部某处的任何测试失败,我必须向上滚动并查找该单词FAIL或在文本编辑器中搜索它。
这-failfast标志也没有帮助,因为我的一些测试在第一次测试失败后由于某种原因仍然被打印。
我真的不在乎测试在初始测试失败后是否运行。我只是希望能够轻松判断是否有任何测试失败,最好只在一个地方(例如,有多少测试通过或失败的摘要,或者通过查看所有测试是否通过的标志)。
有没有一种方法可以轻松判断是否存在测试失败,因为如果仍然存在测试失败,我不想意外地继续编码。
我使用的是 Windows 10 64 位。
更新:非常感谢@icza 的提示findstr。后来我意识到我还想看到错误描述以及测试失败,但不想运行go test两次。这是我为 CMD 提出的(不适用于 Powershell):
go test ./... -v -short > test-results.txt & findstr "FAIL _test" test-results.txt
Run Code Online (Sandbox Code Playgroud)
现在findstr应该报告测试失败以及错误描述。如果您想查看完整的测试结果,只需打开test-results.txt.
我发现editor.codeActionsOnSave配置非常烦人,因为很多时候当我保存时,它会占用一些时间来获取我当前使用的语言(例如 Golang)的一些代码操作。
我不希望也不需要这样的功能,因为我已经在其他地方保存时配置了所需的操作。
我已经在 VS Code 配置文件中添加了以下条目:
"editor.codeActionsOnSave": {},
"[go]": {
"editor.codeActionsOnSave": {}
},
Run Code Online (Sandbox Code Playgroud)
但是,设置空值似乎并没有禁用这个烦人的功能,因为我仍然会收到弹出窗口,提示 VS Code 正在获取一些代码操作。
以前,默认editor.codeActionsOnSave设置为null,但这也不会禁用该功能。
如何禁用此功能?
编辑:我还在这里提交了一个关于此问题的 GitHub 问题。
编辑:我正在使用 VS Code。
对于使用下划线作为私有字段前缀的代码,我收到以下警告:
Naming rule violation: Prefix '_' is not expected [MyProject]csharp(IDE1006)
Run Code Online (Sandbox Code Playgroud)
下面是我的代码:
namespace MyProject
{
public class Dog
{
// Naming rule violation: Prefix '_' is not expected [MyProject]csharp(IDE1006)
private int _age;
public int Age()
{
return _age;
}
public void SetAge(int age)
{
_age = age;
}
}
}
Run Code Online (Sandbox Code Playgroud)
以下是我的.editorconfig文件:
[*.cs]
# Require private fields to begin with an underscore (_).
dotnet_naming_rule.instance_fields_should_be_camel_case.severity = warning
dotnet_naming_rule.instance_fields_should_be_camel_case.symbols = instance_fields
dotnet_naming_rule.instance_fields_should_be_camel_case.style = instance_field_style
dotnet_naming_symbols.instance_fields.applicable_kinds = field
dotnet_naming_style.instance_field_style.capitalization …Run Code Online (Sandbox Code Playgroud) c# warnings suppress-warnings visual-studio-code editorconfig
我正在尝试根据开始值和结束值将值分配给特定数量的值持有者。
如果 Value Holders 的数量等于 Start Values 和 End Values 的差值,这只是一个简单的迭代:
Start Value : 1
End Value : 10
Value Holders: 10
|
Expected Result: 1 2 3 4 5 6 7 8 9 10
Run Code Online (Sandbox Code Playgroud)
如果 Value Holder 的数量小于 Start Values 和 End Values 的差值,我们需要跳过一些数字。目标是尝试尽可能均匀地分配值。
注意:靠左/靠右并不重要:)
Start Value : 1
End Value : 10
Value Holders: 5
|
Expected Result: 1 3 5 8 10
or
1 3 6 8 10
Start Value : 1
End Value : 10
Value …Run Code Online (Sandbox Code Playgroud) 我有以下结构:
type Parent struct {
id string
children []Child
}
type Child struct {
id string
}
Run Code Online (Sandbox Code Playgroud)
我用以下值制作了一片父母:
parents := make([]Parent, 0)
p1 := Parent {
"3",
[]Child {
{"2"},
{"3"},
{"1"},
},
}
p2 := Parent {
"1",
[]Child {
{"8"},
{"9"},
{"7"},
},
}
p3 := Parent {
"2",
[]Child {
{"5"},
{"6"},
{"4"},
},
}
parents = append(parents, p1, p2, p3)
Run Code Online (Sandbox Code Playgroud)
我正在尝试按以下顺序对“父母”切片进行排序:
1) First, sort all Parents by Parent.id
2) Next, sort each Parent's "children" slice by …Run Code Online (Sandbox Code Playgroud) Visual Studio Code 不会注释掉空行
我到处搜索这个问题的解决方案,但找不到任何东西,几个月来一直困扰着我。
基本上,当你告诉它注释掉多行代码时,VS Code 会忽略空行。
例如,假设我突出显示了下面的所有代码并告诉 VS Code 将其注释掉:
package com.mycompany.app;
public class MyApp {
public static void main(String[] args) {
SayHello();
}
static void SayHello() {
System.out.println("Hello!");
}
}
Run Code Online (Sandbox Code Playgroud)
我期望得到的:
// package com.mycompany.app;
//
// public class MyApp {
// public static void main(String[] args) {
// SayHello();
// }
//
// static void SayHello() {
// System.out.println("Hello!");
// }
// }
Run Code Online (Sandbox Code Playgroud)
我得到的是:
// package com.mycompany.app;
// public class MyApp {
// public static void main(String[] …Run Code Online (Sandbox Code Playgroud) c# ×3
go ×3
warnings ×2
analysis ×1
append ×1
comments ×1
concurrency ×1
editorconfig ×1
enums ×1
goroutine ×1
node-modules ×1
node.js ×1
npm ×1
npm-ci ×1
npm-install ×1
pycharm ×1
python ×1
refactoring ×1
slice ×1
testing ×1
unit-testing ×1