Skip to content

Commit

Permalink
remove DartProject references (dart-lang/linter#3399)
Browse files Browse the repository at this point in the history
  • Loading branch information
pq authored May 13, 2022
1 parent 54ec2f6 commit ed5ce95
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 35 deletions.
62 changes: 28 additions & 34 deletions lib/src/rules/package_prefixed_library_names.dart
Original file line number Diff line number Diff line change
Expand Up @@ -51,31 +51,20 @@ library my_package.src.private;
bool matchesOrIsPrefixedBy(String name, String prefix) =>
name == prefix || name.startsWith('$prefix.');

class PackagePrefixedLibraryNames extends LintRule
implements ProjectVisitor, NodeLintRule {
DartProject? project;

class PackagePrefixedLibraryNames extends LintRule {
PackagePrefixedLibraryNames()
: super(
name: 'package_prefixed_library_names',
description: _desc,
details: _details,
group: Group.style);

@override
ProjectVisitor getProjectVisitor() => this;

@override
void registerNodeProcessors(
NodeLintRegistry registry, LinterContext context) {
var visitor = _Visitor(this);
registry.addLibraryDirective(this, visitor);
}

@override
void visit(DartProject project) {
this.project = project;
}
}

class _Visitor extends SimpleAstVisitor<void> {
Expand All @@ -84,28 +73,33 @@ class _Visitor extends SimpleAstVisitor<void> {
_Visitor(this.rule);

@override
// ignore: prefer_expression_function_bodies
void visitLibraryDirective(LibraryDirective node) {
// If no project info is set, bail early.
// https://github.com/dart-lang/linter/issues/154
var project = rule.project;
var element = node.element;
if (project == null || element == null) {
return;
}

var source = element.source;
if (source == null) {
return;
}

var prefix = Analyzer.facade.createLibraryNamePrefix(
libraryPath: source.fullName,
projectRoot: project.root.absolute.path,
packageName: project.name);

var name = element.name;
if (name == null || !matchesOrIsPrefixedBy(name, prefix)) {
rule.reportLint(node.name);
}
// Project info is not being set.
//See: https://github.com/dart-lang/linter/issues/3395
return;

// // If no project info is set, bail early.
// // https://github.com/dart-lang/linter/issues/154
// var project = rule.project;
// var element = node.element;
// if (project == null || element == null) {
// return;
// }
//
// var source = element.source;
// if (source == null) {
// return;
// }
//
// var prefix = Analyzer.facade.createLibraryNamePrefix(
// libraryPath: source.fullName,
// projectRoot: project.root.absolute.path,
// packageName: project.name);
//
// var name = element.name;
// if (name == null || !matchesOrIsPrefixedBy(name, prefix)) {
// rule.reportLint(node.name);
// }
}
}
3 changes: 2 additions & 1 deletion test_data/rules/package_prefixed_library_names.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@

// test w/ `dart test -N package_prefixed_library_names`

library linter.not_where_it_should_be; //LINT
// See: https://github.com/dart-lang/linter/issues/3395
library linter.not_where_it_should_be; //FAILING

0 comments on commit ed5ce95

Please sign in to comment.