[英]Eslint or prettier is adding 2 semi colons to the end of a line in vscode
In VScode when I accidentally leave off a semi colon at the end of a javascript line and save the file, vscode (prettier or eslint or both) fixes this by adding 2 semi colons to the end of the line. 在VScode中,当我意外地在javascript行的末尾留下一个半冒号并保存文件时,vscode(更漂亮或者是两者)通过在行的末尾添加2个半冒号来修复此问题。 Example
例
Original line 原线
const x = 1
Fixed line 固定的线
const x = 1;;
I want it to add only 1 ; 我希望它只添加1;
Where would I look to fix this? 我想在哪里解决这个问题? facepalm
捂脸
TL;DR: Check your ESLint rules, make sure you don't have a redundant one that is already being taken care of by your plugins. TL; DR:检查您的ESLint规则,确保您没有已经由插件处理的冗余规则。
I was having this issue. 我遇到了这个问题。 I solved it in my
.eslintrc.json
file, which I had mis-configured. 我在我的
.eslintrc.json
文件中解决了这个问题。
I have both the plugin installed for prettier 我安装了这两个插件更漂亮
"plugins": ["babel", "react", "prettier"],
as well a rule set for eslint to add semi colons 以及用于添加半冒号的eslint的规则集
"rules": {
"semi": ["error", "always"],
When I take either that rule out or the prettier plugin out, it would go to only adding one semicolon. 当我拿出那个规则或更漂亮的插件时,它只会添加一个分号。
However, when I would take out the prettier plugin, it would also give the error: Definition for rule 'prettier/prettier' was not foundeslint(prettier/prettier)
然而,当我拿出更漂亮的插件时,它也会给出错误:
Definition for rule 'prettier/prettier' was not foundeslint(prettier/prettier)
So the rule setting seemed to be redundant with the plugin, and removing the rule fixed this issue. 所以规则设置似乎是插件的冗余,删除规则修复了这个问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.