Skip to content

Commit da58ca0

Browse files
srawlinsCommit Queue
authored andcommitted
analyzer: Convert getPubspecVisitor to a getter named pubspecVisitor
Work towards #50986 Change-Id: I1bcdc6b32efef0f7e70bbb49c3cce046f95351fb Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/428225 Commit-Queue: Samuel Rawlins <[email protected]> Reviewed-by: Brian Wilkerson <[email protected]> Reviewed-by: Konstantin Shcheglov <[email protected]>
1 parent 7698535 commit da58ca0

File tree

7 files changed

+13
-15
lines changed

7 files changed

+13
-15
lines changed

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

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,11 @@ sealed class AbstractAnalysisRule {
6363
/// The lint codes associated with this lint rule.
6464
List<LintCode> get lintCodes;
6565

66+
/// Returns a visitor that visits a [Pubspec] to perform analysis.
67+
///
68+
/// Diagnostics are reported via this [LintRule]'s error [reporter].
69+
PubspecVisitor? get pubspecVisitor => null;
70+
6671
@protected
6772
// Protected so that lint rule visitors do not access this directly.
6873
// TODO(srawlins): With the new availability of an ErrorReporter on
@@ -74,12 +79,6 @@ sealed class AbstractAnalysisRule {
7479

7580
set reporter(ErrorReporter value) => _reporter = value;
7681

77-
/// Returns a visitor to be passed to pubspecs to perform lint
78-
/// analysis.
79-
///
80-
/// Lint errors are reported via this [LintRule]'s error [reporter].
81-
PubspecVisitor? getPubspecVisitor() => null;
82-
8382
/// Registers node processors in the given [registry].
8483
///
8584
/// The node processors may use the provided [context] to access information

pkg/analyzer/lib/src/pubspec/pubspec_validator.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ List<Diagnostic> validatePubspec({
5959
if (analysisOptions != null && analysisOptions.lint) {
6060
var visitors = <AbstractAnalysisRule, PubspecVisitor>{};
6161
for (var linter in analysisOptions.lintRules) {
62-
var visitor = linter.getPubspecVisitor();
62+
var visitor = linter.pubspecVisitor;
6363
if (visitor != null) {
6464
visitors[linter] = visitor;
6565
}

pkg/linter/lib/src/rules/pub/package_names.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ class PackageNames extends LintRule {
1414
LintCode get lintCode => LinterLintCode.package_names;
1515

1616
@override
17-
PubspecVisitor<void> getPubspecVisitor() => Visitor(this);
17+
PubspecVisitor<void> get pubspecVisitor => Visitor(this);
1818
}
1919

2020
class Visitor extends PubspecVisitor<void> {

pkg/linter/lib/src/rules/pub/secure_pubspec_urls.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ class SecurePubspecUrls extends LintRule {
1616
LintCode get lintCode => LinterLintCode.secure_pubspec_urls;
1717

1818
@override
19-
PubspecVisitor<void> getPubspecVisitor() => Visitor(this);
19+
PubspecVisitor<void> get pubspecVisitor => Visitor(this);
2020
}
2121

2222
class Visitor extends PubspecVisitor<void> {

pkg/linter/lib/src/rules/pub/sort_pub_dependencies.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ class SortPubDependencies extends LintRule {
1717
LintCode get lintCode => LinterLintCode.sort_pub_dependencies;
1818

1919
@override
20-
PubspecVisitor<void> getPubspecVisitor() => Visitor(this);
20+
PubspecVisitor<void> get pubspecVisitor => Visitor(this);
2121
}
2222

2323
class Visitor extends PubspecVisitor<void> {

pkg/linter/lib/src/test_utilities/test_linter.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ class TestLinter implements AnalysisErrorListener {
5858
var spec = Pubspec.parse(contents, sourceUrl: sourceUrl);
5959

6060
for (var rule in options.enabledRules) {
61-
var visitor = rule.getPubspecVisitor();
61+
var visitor = rule.pubspecVisitor;
6262
if (visitor != null) {
6363
// Analyzer sets reporters; if this file is not being analyzed,
6464
// we need to set one ourselves. (Needless to say, when pubspec

pkg/linter/test/rule_test_support.dart

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -560,10 +560,9 @@ class PubPackageResolutionTest with MockPackagesMixin, ResourceProviderMixin {
560560
Future<List<Diagnostic>> _resolvePubspecFile(String content) async {
561561
var path = convertPath(testPackagePubspecPath);
562562
var pubspecRules = <AbstractAnalysisRule, PubspecVisitor<Object?>>{};
563-
for (var rule in Registry.ruleRegistry.where(
564-
(rule) => _lintRules.contains(rule.name),
565-
)) {
566-
var visitor = rule.getPubspecVisitor();
563+
var rules = Registry.ruleRegistry.where((r) => _lintRules.contains(r.name));
564+
for (var rule in rules) {
565+
var visitor = rule.pubspecVisitor;
567566
if (visitor != null) {
568567
pubspecRules[rule] = visitor;
569568
}

0 commit comments

Comments
 (0)