Skip to content

Commit 11904ed

Browse files
DanTupCommit Queue
authored andcommitted
[analyzer] Add LinterContext.currentUnit and use it for content in eol_at_end_of_file
... instead of potentially reading the file from disk. Fixes #59704 Change-Id: Id5939dce4d11429a929a4b63611ff1823449b64c Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/401424 Reviewed-by: Phil Quitslund <[email protected]> Reviewed-by: Brian Wilkerson <[email protected]> Commit-Queue: Phil Quitslund <[email protected]>
1 parent 38bce3f commit 11904ed

File tree

5 files changed

+17
-1
lines changed

5 files changed

+17
-1
lines changed

pkg/analysis_server/lib/src/services/correction/bulk_fix_processor.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -565,6 +565,7 @@ class BulkFixProcessor {
565565
}
566566

567567
// Run lints that handle specific node types.
568+
context.currentUnit = currentUnit;
568569
currentUnit.unit.accept(AnalysisRuleVisitor(nodeRegistry));
569570
}
570571

pkg/analysis_server_plugin/lib/src/plugin_server.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -300,6 +300,7 @@ class PluginServer {
300300
}
301301
}
302302

303+
context.currentUnit = currentUnit;
303304
currentUnit.unit.accept(
304305
AnalysisRuleVisitor(nodeRegistry, shouldPropagateExceptions: true));
305306
// The list of the `AnalysisError`s and their associated

pkg/analyzer/lib/src/dart/analysis/library_analyzer.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -415,6 +415,7 @@ class LibraryAnalyzer {
415415
}
416416

417417
// Run lint rules that handle specific node types.
418+
context.currentUnit = currentUnit;
418419
unit.accept(
419420
AnalysisRuleVisitor(
420421
nodeRegistry,

pkg/analyzer/lib/src/lint/linter.dart

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,12 @@ abstract class LinterContext {
3636
/// including the defining compilation unit, all parts, and all augmentations.
3737
List<LintRuleUnitContext> get allUnits;
3838

39+
/// The compilation unit being linted.
40+
///
41+
/// `null` when a unit is not currently being linted (for example when node
42+
/// processors are being registered).
43+
LintRuleUnitContext? get currentUnit;
44+
3945
/// The defining compilation unit of the library under analysis.
4046
LintRuleUnitContext get definingUnit;
4147

@@ -80,6 +86,9 @@ final class LinterContextWithParsedResults implements LinterContext {
8086
@override
8187
final LintRuleUnitContext definingUnit;
8288

89+
@override
90+
LintRuleUnitContext? currentUnit;
91+
8392
@override
8493
final InheritanceManager3 inheritanceManager = InheritanceManager3();
8594

@@ -121,6 +130,9 @@ final class LinterContextWithResolvedResults implements LinterContext {
121130
@override
122131
final LintRuleUnitContext definingUnit;
123132

133+
@override
134+
LintRuleUnitContext? currentUnit;
135+
124136
@override
125137
final WorkspacePackage? package;
126138

pkg/linter/lib/src/rules/eol_at_end_of_file.dart

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@ class _Visitor extends SimpleAstVisitor<void> {
3535

3636
@override
3737
void visitCompilationUnit(CompilationUnit node) {
38-
var content = node.declaredFragment?.source.contents.data;
38+
assert(context.currentUnit?.unit == node);
39+
var content = context.currentUnit?.content;
3940
if (content != null &&
4041
content.isNotEmpty &&
4142
// TODO(srawlins): Re-implement this check without iterating over

0 commit comments

Comments
 (0)