Closed cyw3 closed 2 years ago
the test case is the index.js of prettier@2.0.5
Hi,
Sorry for the long waiting. I will be on a work break next week and will fix this then.
Terry
On 15 Jul 2020, at 4:41 PM, cyw3 notifications@github.com wrote:
the test case is the index.js of prettier@2.0.5
https://user-images.githubusercontent.com/11549103/87523771-f03cfe80-c6b9-11ea-8992-da0167b644ba.png — You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/terryyin/lizard/issues/293#issuecomment-658632433, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAGASYQHL5556ASGUPJI3R3R3VTTHANCNFSM4OWHTJ5A.
We are also facing same issue.
+1
The core of the problem here is that the tokenizer is expecting every open html tag, i.e <Tag>
to end with a closing tag </Tag>
.
However, js also have generics, i.e Array<Tag>
and then we quickly get into endless recursion of not having any closing tags.
Example snippet out of the referenced prettier:
{
type: 'DebuggerStatement';
_DebuggerStatement: void;
end: number;
innerComments: ?Array<Comment>;
leadingComments: ?Array<Comment>;
loc: {
end: { column: number, line: number },
start: { column: number, line: number },
};
start: number;
trailingComments: ?Array<Comment>;
}
each <Comment>
block is leading us to nest into another tokenizer ...
Not sure whats the best approach to resolve this.
To help lizard at least survive these encounters, one may apply this crude monkey patch (or something similar):
diff --git a/lizard.py b/lizard.py
index ba8b0eb..ab74698 100755
--- a/lizard.py
+++ b/lizard.py
@@ -562,8 +562,11 @@ class FileAnalyzer(object): # pylint: disable=R0903
tokens = reader.generate_tokens(code)
for processor in self.processors:
tokens = processor(tokens, reader)
- for _ in reader(tokens, reader):
- pass
+ try:
+ for _ in reader(tokens, reader):
+ pass
+ except RecursionError as err:
+ print("skipped:", filename, "with reason: RecursionError (unclosed tags/scopes?)") # or something similar ...
return context.fileinfo
Thanks!
Lizard 1.17.5 Python 3.7.0
When I want to update lizard 1.16.3 to lizard 1.17.5, I get a error:
And when use Lizard 1.16.3 to scan the same project, it works.