Skip to content

Add custom lint to sanity check analyzer public API #60058

@stereotype441

Description

@stereotype441

After mistakenly exposing some private implementation details of package:_fe_analyzer_shared through the analyzer public API, and having to do a lot of work to clean up my mistake (see #59763), I'd like to add a custom lint to the analyzer, to verify the following:

  • For this lint, I'd like to define the analyzer's public API to be:

    • All top level elements of files in package:analyzer but not in package:analyzer/src whose names are public

    • All elements annotated with @AnalyzerPublicApi(), a new annotation I propose adding. (The annotation will be defined in package:_fe_analyzer_shared so that types in that package can use it. The rationale for this is that some things look like they aren't part of the analyzer's public API but actually are, such as the Token class defined in package:_fe_analyzer_shared.)

    • For any member of the analyzer's public API that defines a type or an extension, all of its public members.

  • The types of the methods, functions, getters, setters, constructors, and supertypes in the analyzer's public API may only refer to types defined in the analyzer's public API (or types defined in dart:core and a few permitted packages, e.g. package:pub_semver).

  • The export directives in package:analyzer but not in package:analyzer/src may only export elements that are in the analyzer's public API.

  • No top level element in package:analyzer but not in package:analyzer/src may have a name ending in Impl. (This prevents us from accidentally exposing "Impl" classes by declaring them in the wrong place.)

  • Any part directives in package:analyzer but not in package:analyzer/src must also point to files in package:analyzer but not in package:analyzer/src. (Without this rule, an element might sneak into the analyzer's public API without being noticed by this lint. Note that the analyzer currently uses part files very rarely, but this may change after augmentation support is added to the language.)

Metadata

Metadata

Assignees

Labels

P2A bug or feature request we're likely to work onanalyzer-apiIssues that impact the public API of the analyzer packagelegacy-area-analyzerUse area-devexp instead.type-enhancementA request for a change that isn't a bug

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions