-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix #1266, make SourceCode only for no-deprecated rule #1271
Fix #1266, make SourceCode only for no-deprecated rule #1271
Conversation
src/ExportMap.js
Outdated
@@ -346,7 +348,7 @@ ExportMap.parse = function (path, content, context) { | |||
docStyleParsers[style] = availableDocStyleParsers[style] | |||
}) | |||
|
|||
const source = makeSourceCode(content, ast) | |||
const source = context.id === 'no-deprecated' ? makeSourceCode(content, ast) : null |
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.
Is there a way to make this metadata the rule can supply rather than hardcoding a single rule name?
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.
yeah, I'll take a look
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.
@ljharb It seems metadata doesn't provide an appropriate field: https://eslint.org/docs/developer-guide/working-with-rules#rule-basics
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.
perhaps an argument passed to ExportMap
?
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.
Passing an argument looks better, it seems rule id
isn't passed in ESlint 2-3.
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.
but more changes are required... 😓
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.
maybe instead of skipping the comments, we could make them lazy?
ie, instead of using properties, use functions that lazily create the source code object as needed (but memoize it across calls)?
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.
I'm afraid it's too late, we don't have required data (content, ast) when we need it, otherwise we have to store them as well
@ljharb any ideas regarding
I think I've already seen this in other PRs... |
d1715d2
to
fc26273
Compare
Closing in deference to #1275 |
Thanks for taking a stab at this, though! 😄 |
Parsing source code allocates a lot of memory since
SourceCode
instances are built recursively for each node in the dependency graph:https://github.com/benmosher/eslint-plugin-import/blob/1ec80fa35fa1819e2d35a70e68fb6a149fb57c5e/src/ExportMap.js#L349
SourceCode
instance is only used to capture docs from leading comments that are actually used only for no-deprecated rule:https://github.com/benmosher/eslint-plugin-import/blob/1ec80fa35fa1819e2d35a70e68fb6a149fb57c5e/src/ExportMap.js#L417-L418
https://github.com/benmosher/eslint-plugin-import/blob/1ec80fa35fa1819e2d35a70e68fb6a149fb57c5e/src/ExportMap.js#L453-L454
https://github.com/benmosher/eslint-plugin-import/blob/1ec80fa35fa1819e2d35a70e68fb6a149fb57c5e/src/ExportMap.js#L456-L459
However,
SourceCode
instances are built even if no-deprecated rule is turned off (btw the rule is in Stage 0 and is still work in progress). The PR prevents negative impact on other rules.Here's memory consumption before/after PR for pretty large code base, no-deprecated rule is disabled for both cases:
The 1st process failed with
heap out of memory
error.