-
Notifications
You must be signed in to change notification settings - Fork 887
Introduce alternative to SkippableTokenAwareRuleWalker and scanAllTokens #2036
Conversation
Scanning the whole source file is very fragile, because the grammar is not context free. You had to skip certain ranges, that were known to cause trouble. For example regex literals or template expressions. This approach is also very fragile, as it didn't cover all cases and has to adopt new grammar as the language adds it. The new function hands the scanning and parsing off to the parser and only iterates over the tokens of all AST nodes. Skipping ranges is no longer necessary. Also added deprecation comment to scanAllTokens.
This enables this rule to check template expression. Tests are added. Failures in line 97 and 101 were not found by the previous implementation. Skip JsxElement and JsxSelfClosingElement as it was done before.
This rule now finds failures that it ignored previously
PerformanceLinting master: 10.9 sec to 11.4 sec Seems like a 10% overall speedup as a side effect of a bugfix isn't that bad, is it? Where's that coming from?
|
this is pretty amazing |
as far as the new errors it finds, I'd consider those as fixes which aren't breaking. @adidahiya for comment |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looks good, minor nits
} | ||
|
||
/** | ||
* Checks if there are any comments between `position` and the next non-tivia token |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
tivia
-> trivia
return true; | ||
} | ||
|
||
function hasCommentCallback() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
doesn't belong here, move inside hasCommentAfterPosition
or just use anonymous callback
@ajafff thanks! |
PR checklist
What changes did you make?
Scanning the whole source file is very fragile, because the grammar is not context free. You had to skip certain ranges, that were known to cause trouble. For example regex literals or template expressions.
This approach is prone to errors, as it didn't cover all cases and has to adopt new grammar as the language adds it.
The new function hands the scanning and parsing off to the parser and only iterates over the tokens of all AST nodes. Skipping ranges is no longer necessary.
This fixes #2007 and replaces #2009 (I took 2 commits from that PR to include the contained tests)
For more information please refer to the description of each individual commit.
Is there anything you'd like reviewers to focus on?
This is a rather big PR. I could split it into several smaller ones if you want.
WhitespaceRule
used to skipTemplateExpression
,JsxElement
andJsxSelfClosingElement
. That's no longer necessary.That means not all whitespace errors were found with the previous implementation. Now we find all errors, even inside
JsxExpression
andTemplateExpression
.If you think this is a breaking change, I would fall back to skipping the aforementioned nodes for now and submit a separate PR to include them for the next major version.
I'm currently investigating what the performance impact of this change is. I'll keep you posted.