Skip to content
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

The eol_at_end_of_file lint reads file content from disk and can slow down linting #59704

Open
DanTup opened this issue Dec 12, 2024 · 1 comment
Labels
analyzer-linter Issues with the analyzer's support for the linter package area-analyzer Use area-analyzer for Dart analyzer issues, including the analysis server and code completion. P3 A lower priority bug or feature request

Comments

@DanTup
Copy link
Collaborator

DanTup commented Dec 12, 2024

Splitting this out of #55281 (comment) so it doesn't get lost.

This lint reads the content in a way that appears that it can hit the disk and can be quite slow when analyzing a lot of files (or a large library):

var content = node.declaredFragment?.source.contents.data;

One simple option suggested by @bwilkerson was:

    var unitContext =
        context.allUnits.firstWhereOrNull((unit) => unit.unit == node);
    var content = unitContext.content;

And @scheglov:

And yes, I think registerNodeProcessors() should have access to the current LintRuleUnitContext instance. Currently it knows all units of the library, and its defining unit, but not the current.

I had a quick look at this, but I am a little confused by LinterContext.definedUnit because it seems like there is code that passes each individual unit in for it. For example this call here happens inside a loop for all units within a library (called currentUnit):

_computeParsedResultLint(unitContext, unitContexts);

And then currentUnit is passed as definingUnit:

var context = LinterContextWithParsedResults(allUnits, currentUnit);

So I wonder whether definingUnit could just be rename and repurposed as currentUnit or whether any lints really do need/want the defining unit?

@DanTup DanTup added area-analyzer Use area-analyzer for Dart analyzer issues, including the analysis server and code completion. analyzer-linter Issues with the analyzer's support for the linter package labels Dec 12, 2024
@bwilkerson
Copy link
Member

I don't know whether any of the existing lints need the defining compilation unit. If there are any, then at least some of them are likely using it to get to the imports and that logic will need to be changed to support enhanced-parts. The only way for me to find the answer to that question would be to look at all uses of definingUnit and try to determine why it's being used.

@scheglov scheglov added the P3 A lower priority bug or feature request label Dec 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
analyzer-linter Issues with the analyzer's support for the linter package area-analyzer Use area-analyzer for Dart analyzer issues, including the analysis server and code completion. P3 A lower priority bug or feature request
Projects
None yet
Development

No branches or pull requests

3 participants