@@ -9,6 +9,7 @@ import haxe.macro.Expr;
99class PublicPrivateCheck extends Check {
1010
1111 public var severity : String = " INFO" ;
12+ public var enforcePublicPrivate : Bool = false ;
1213
1314 override function _actualRun () {
1415 for (td in _checker .ast .decls ) {
@@ -30,16 +31,32 @@ class PublicPrivateCheck extends Check {
3031 }
3132
3233 function checkInterfaceField (f : Field ) {
33- if (f .access .indexOf (APublic ) > - 1 ) {
34- _warnPublicKeyword (f .name , f .pos );
35- return ;
34+ if (enforcePublicPrivate ) {
35+ if (f .access .indexOf (APublic ) < 0 ) {
36+ _warnPublicKeywordMissing (f .name , f .pos );
37+ return ;
38+ }
39+ }
40+ else {
41+ if (f .access .indexOf (APublic ) > - 1 ) {
42+ _warnPublicKeyword (f .name , f .pos );
43+ return ;
44+ }
3645 }
3746 }
3847
3948 function checkField (f : Field ) {
40- if (f .access .indexOf (APrivate ) > - 1 ) {
41- _warnPrivateKeyword (f .name , f .pos );
42- return ;
49+ if (enforcePublicPrivate ) {
50+ if ((f .access .indexOf (APublic ) < 0 ) && (f .access .indexOf (APrivate ) < 0 )) {
51+ _warnPrivateKeywordMissing (f .name , f .pos );
52+ return ;
53+ }
54+ }
55+ else {
56+ if (f .access .indexOf (APrivate ) > - 1 ) {
57+ _warnPrivateKeyword (f .name , f .pos );
58+ return ;
59+ }
4360 }
4461 }
4562
@@ -50,4 +67,12 @@ class PublicPrivateCheck extends Check {
5067 function _warnPublicKeyword (name : String , pos : Position ) {
5168 logPos (' No need of public keyword: ${name } (fields are by default public in interfaces)' , pos , Reflect .field (SeverityLevel , severity ));
5269 }
53- }
70+
71+ function _warnPrivateKeywordMissing (name : String , pos : Position ) {
72+ logPos (' Missing private keyword: ${name }' , pos , Reflect .field (SeverityLevel , severity ));
73+ }
74+
75+ function _warnPublicKeywordMissing (name : String , pos : Position ) {
76+ logPos (' Missing public keyword: ${name }' , pos , Reflect .field (SeverityLevel , severity ));
77+ }
78+ }
0 commit comments