问题描述
我正在使用 Angular 和 Vs Code 进行 FE 项目。 我们有一个带有 extensions.json 和 setting.json 的 .vscode。
并且 Git 正在检测此代码上的一些烦人的更改,如下所示:
情况如何:
return new MyClass.Option(
{
option
}
他的提交更改
return new MyClass.Option(
{
option
}
注意选项缩进的变化。我假设这与 VsCode 相关,因为我们都使用相同的操作系统(Windows,请不要判断,由公司强制执行)并且所有相关更改都应由 .vscode 上的文件应用。
我们正在使用 eslint 和 Prettier (svipas.prettier-plus)
有人看过吗?有关如何修复它的任何建议?自项目开始以来,我们有超过 10 名开发人员参与其中,这是第一次发生,现在只发生在他身上。
这是我们的设置示例,以防万一:
{
"editor.formatOnSave": true,"editor.defaultFormatter": "svipas.prettier-plus","editor.tabSize": 2,"editor.insertSpaces": true,"editor.detectIndentation": false,"[typescript]": {
"editor.codeActionsOnSave": {
"source.organizeImports": true
},"editor.defaultFormatter": "svipas.prettier-plus"
},"prettier.singleQuote": true,"prettier.trailingComma": "none",// Exclude third party modules and build artifacts from the editor watchers/searches.
"files.watcherExclude": {
"**/.git/objects/**": true,"**/.git/subtree-cache/**": true,"**/node_modules/**": true,"**/bazel-out/**": true,"**/dist/**": true,"**/aio/src/generated/**": true
},"search.exclude": {
"**/node_modules": true,"**/bower_components": true,"**/bazel-out": true,"**/dist": true,"**/aio/src/generated": true
},"git.ignoreLimitWarning": true,"[html]": {
"editor.defaultFormatter": "svipas.prettier-plus"
},"[scss]": {
"editor.defaultFormatter": "svipas.prettier-plus"
},"[json]": {
"editor.defaultFormatter": "svipas.prettier-plus"
}
}
更新:
发现问题。小背景,一周前我们从tslint更新到eslint。 现在,该文件中有此代码:
.pipe(map(streamer),mergeAll())
.subscribe((response) => {
const assetId = response?.[0]?.assetId;
const hasAlerts = !!assetId;
虽然它在 TS 上运行没有任何问题,但输出更漂亮:
Expression expected. (542:34)
540 | .pipe(map(streamer),mergeAll())
541 | .subscribe((response) => {
> 542 | const assetId = response?.[0]?.assetId;
| ^
如果我将代码更改为 `response[0].assetId,更漂亮的作品和我上面提到的所有格式问题都有效,用户配置或工作区配置没有问题。
事实是,我不想因为更漂亮而停止使用 Angular 9 中的该功能。我一直在谷歌上搜索解决方案,但到目前为止没有找到?
解决方法
请注意,并非所有设置都可以被项目 settings.json 覆盖。例如,user settings.json 中的 editor.tabsize = 4 不会被 project setting.json 中的 editor.tabsize = 2 打败。
也许您的同事有一些无法被团队在项目中使用的设置覆盖的用户设置。