简体   繁体   English

我如何解释 Prettier --debug-check output?

[英]How do I interpret Prettier --debug-check output?

I am using prettier --debug-check and it is producing the following error information...我正在使用 prettier --debug-check 并且它正在产生以下错误信息......

[error] my.js: ast(input) !== ast(prettier(input))
[error] Index:
[error] ===================================================================
[error] ---
[error] +++
[error] @@ -3497,8 +3497,6 @@
[error]                                "argument": {
[error]                                  "type": "LogicalExpression",
[error] -                                "operator": "&&",
[error]                                  "left": {
[error]                                    "type": "LogicalExpression",
[error] -                                  "operator": "&&",
[error]                                    "left": {
[error]                                      "type": "LogicalExpression",
[error] @@ -3529,4 +3527,5 @@
[error]                                      }
[error]                                    },
[error] +                                  "operator": "&&",
[error]                                    "right": {
[error]                                      "type": "Identifier",
[error] @@ -3534,4 +3533,5 @@
[error]                                    }
[error]                                  },
[error] +                                "operator": "&&",
[error]                                  "right": {
[error]                                    "type": "BinaryExpression",
[error]
[error] Index:
[error] ===================================================================
...
... below this appears to be a diff between the original file and the 
... prettier output...there is a huge difference between them.

I am having a hard time determining what in the original file is resulting in this error being produced.我很难确定原始文件中的什么导致了这个错误的产生。 I assume that the error information is trying to tell me where to look...is it?我假设错误信息试图告诉我去哪里看……是吗?

How can I resolve this error so prettier can be used to format the file?我该如何解决这个错误,以便更漂亮地用于格式化文件?

Perhaps someone else will be able to provide a better answer.也许其他人能够提供更好的答案。

The error output provided by --debug-check is uninterpretable. --debug-check 提供的错误 output 是无法解释的。

To resolve the issue, a method that worked was to comment out code until I was able to narrow it down to the line that Pettier was complaining about.要解决这个问题,一种有效的方法是注释掉代码,直到我能够将其缩小到 Pettier 抱怨的行。

The line had the form:该行具有以下形式:

return (a && a.length > 0) && (b && b.length > 0);

Now, clearly the parenthesis are not needed, but including them leads to two different ASTs.现在,显然不需要括号,但包含它们会导致两个不同的 AST。

The solution was to write the line without the parenthesis:解决方案是写下不带括号的行:

return a && a.length > 0 && b && b.length > 0;

Doing so stops Prettier from complaining.这样做可以阻止 Prettier 抱怨。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM