Add custom lint to sanity check analyzer public API #60058
Labels
analyzer-api
Issues that impact the public API of the analyzer package
legacy-area-analyzer
Use area-devexp instead.
P2
A bug or feature request we're likely to work on
type-enhancement
A request for a change that isn't a bug
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 inpackage:analyzer/src
whose names are publicAll elements annotated with
@AnalyzerPublicApi()
, a new annotation I propose adding. (The annotation will be defined inpackage:_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 theToken
class defined inpackage:_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 inpackage:analyzer/src
may only export elements that are in the analyzer's public API.No top level element in
package:analyzer
but not inpackage:analyzer/src
may have a name ending inImpl
. (This prevents us from accidentally exposing "Impl" classes by declaring them in the wrong place.)Any part directives in
package:analyzer
but not inpackage:analyzer/src
must also point to files inpackage:analyzer
but not inpackage: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.)The text was updated successfully, but these errors were encountered: