@@ -13,81 +13,14 @@ import 'package:analyzer/dart/element/element.dart';
1313import 'package:analyzer/dart/element/type.dart' ;
1414import 'package:analyzer/error/error.dart' ;
1515
16+ import '../lint_codes.dart' ;
17+
1618const _desc =
1719 'Do not expose implementation details through the analyzer public API.' ;
1820
1921class AnalyzerPublicApi extends MultiAnalysisRule {
2022 static const ruleName = 'analyzer_public_api' ;
2123
22- /// Lint issued if a file in the analyzer public API contains a `part`
23- /// directive that points to a file that's not in the analyzer public API.
24- ///
25- /// The rationale for this lint is that if such a `part` directive were to
26- /// exist, it would cause all the members of the part file to become part of
27- /// the analyzer's public API, even though they don't appear to be public API.
28- ///
29- /// Note that the analyzer doesn't make very much use of `part` directives,
30- /// but it may do so in the future once augmentations and enhanced parts are
31- /// supported.
32- static const LintCode badPartDirective = LintCode (
33- 'analyzer_public_api_bad_part_directive' ,
34- 'Part directives in the analyzer public API should point to files in the '
35- 'analyzer public API.' ,
36- );
37-
38- /// Lint issued if a method, function, getter, or setter in the analyzer
39- /// public API makes use of a type that's not part of the analyzer public API,
40- /// or if a non-public type appears in an `extends` , `implements` , `with` , or
41- /// `on` clause.
42- ///
43- /// The reason this is a problem is that it makes it possible for analyzer
44- /// clients to implicitly reference analyzer internal types. This can happen
45- /// in many ways; here are some examples:
46- ///
47- /// - If `C` is a public API class that implements `B` , and `B` is a private
48- /// class with a getter called `x` , then a client can access `B.x` via `C` .
49- ///
50- /// - If `f` has return type `T` , and `T` is a private class with a getter
51- /// called `x` , then a client can access `T.x` via `f().x` .
52- ///
53- /// - If `f` has type `void Function(T)` , and `T` is a private class with a
54- /// getter called `x` , then a client can access `T.x` via
55- /// `var g = f; g = (t) { print(t.x); }` .
56- ///
57- /// This lint can be suppressed either with an `ignore` comment, or by marking
58- /// the referenced type with `@AnalyzerPublicApi(...)` . The advantage of
59- /// marking the referenced type with `@AnalyzerPublicApi(...)` is that it
60- /// causes the members of referenced type to be checked by this lint.
61- static const LintCode badType = LintCode (
62- 'analyzer_public_api_bad_type' ,
63- 'Element makes use of type(s) which is not part of the analyzer public '
64- 'API: {0}.' ,
65- );
66-
67- /// Lint issued if a file in the analyzer public API contains an `export`
68- /// directive that exports a name that's not part of the analyzer public API.
69- ///
70- /// This lint can be suppressed either with an `ignore` comment, or by marking
71- /// the exported declaration with `@AnalyzerPublicApi(...)` . The advantage of
72- /// marking the exported declaration with `@AnalyzerPublicApi(...)` is that it
73- /// causes the members of the exported declaration to be checked by this lint.
74- static const LintCode exportsNonPublicName = LintCode (
75- 'analyzer_public_api_exports_non_public_name' ,
76- 'Export directive exports element(s) that are not part of the analyzer '
77- 'public API: {0}.' ,
78- );
79-
80- /// Lint issued if a top level declaration in the analyzer public API has a
81- /// name ending in `Impl` .
82- ///
83- /// Such declarations are not meant to be members of the analyzer public API,
84- /// so if they are either declared outside of `package:analyzer/src` , or
85- /// marked with `@AnalyzerPublicApi(...)` , that is almost certainly a mistake.
86- static const LintCode implInPublicApi = LintCode (
87- 'analyzer_public_api_impl_in_public_api' ,
88- 'Declarations in the analyzer public API should not end in "Impl".' ,
89- );
90-
9124 AnalyzerPublicApi ()
9225 : super (
9326 name: ruleName,
@@ -97,10 +30,10 @@ class AnalyzerPublicApi extends MultiAnalysisRule {
9730
9831 @override
9932 List <DiagnosticCode > get diagnosticCodes => [
100- badPartDirective ,
101- badType ,
102- exportsNonPublicName ,
103- implInPublicApi ,
33+ LinterLintCode .analyzerPublicApiBadPartDirective ,
34+ LinterLintCode .analyzerPublicApiBadType ,
35+ LinterLintCode .analyzerPublicApiExportsNonPublicName ,
36+ LinterLintCode .analyzerPublicApiImplInPublicApi ,
10437 ];
10538
10639 @override
@@ -170,7 +103,7 @@ class _Visitor extends SimpleAstVisitor<void> {
170103 if (badNames != null ) {
171104 rule.reportAtNode (
172105 node,
173- diagnosticCode: AnalyzerPublicApi .exportsNonPublicName ,
106+ diagnosticCode: LinterLintCode .analyzerPublicApiExportsNonPublicName ,
174107 arguments: [badNames.join (', ' )],
175108 );
176109 }
@@ -187,7 +120,7 @@ class _Visitor extends SimpleAstVisitor<void> {
187120 if (! partElement.includedFragment! .source.uri.isInAnalyzerPublicLib) {
188121 rule.reportAtNode (
189122 node,
190- diagnosticCode: AnalyzerPublicApi .badPartDirective ,
123+ diagnosticCode: LinterLintCode .analyzerPublicApiBadPartDirective ,
191124 );
192125 }
193126 }
@@ -217,7 +150,7 @@ class _Visitor extends SimpleAstVisitor<void> {
217150 rule.reportAtOffset (
218151 fragment.nameOffset! ,
219152 name.length,
220- diagnosticCode: AnalyzerPublicApi .implInPublicApi ,
153+ diagnosticCode: LinterLintCode .analyzerPublicApiImplInPublicApi ,
221154 );
222155 }
223156 switch (fragment) {
@@ -302,7 +235,7 @@ class _Visitor extends SimpleAstVisitor<void> {
302235 rule.reportAtOffset (
303236 offset,
304237 length,
305- diagnosticCode: AnalyzerPublicApi .badType ,
238+ diagnosticCode: LinterLintCode .analyzerPublicApiBadType ,
306239 arguments: [problems.join (', ' )],
307240 );
308241 }
0 commit comments