@@ -23,11 +23,11 @@ class Base {
23
23
24
24
module . exports = [
25
25
class extends Base {
26
- static ruleId = 'interface-names ' ;
26
+ static ruleId = 'interface-only-external-functions ' ;
27
27
28
- ContractDefinition ( node ) {
29
- if ( node . kind === 'interface' && ! / ^ I [ A - Z ] / . test ( node . name ) ) {
30
- this . error ( node , 'Interface names should have a capital I prefix ' ) ;
28
+ FunctionDefinition ( node ) {
29
+ if ( node . parent . kind === 'interface' && node . visibility !== 'external' ) {
30
+ this . error ( node , 'Interface functions must be external ' ) ;
31
31
}
32
32
}
33
33
} ,
@@ -47,38 +47,58 @@ module.exports = [
47
47
static ruleId = 'leading-underscore' ;
48
48
49
49
VariableDeclaration ( node ) {
50
- if ( node . isDeclaredConst ) {
51
- // TODO: expand visibility and fix
52
- if ( node . visibility === 'private' && / ^ _ / . test ( node . name ) ) {
53
- this . error ( node , 'Constant variables should not have leading underscore' ) ;
50
+ if ( node . isDeclaredConst || node . isImmutable ) {
51
+ if ( / ^ _ / . test ( node . name ) ) {
52
+ this . error ( node , 'Constant and immutable variables should not have leading underscore' ) ;
53
+ }
54
+ }
55
+ else {
56
+ if ( node . isStateVar ) {
57
+ if ( node . visibility === 'private' || node . visibility === 'internal' ) {
58
+ if ( ! / ^ _ / . test ( node . name ) ) {
59
+ this . error ( node , 'Private and internal state variables must have leading underscore' ) ;
60
+ }
61
+ }
62
+ else {
63
+ if ( / ^ _ / . test ( node . name ) ) {
64
+ this . error ( node , 'Public state variables should not have leading underscore' ) ;
65
+ }
66
+ }
54
67
}
55
- } else if ( node . visibility === 'private' && ! / ^ _ / . test ( node . name ) ) {
56
- this . error ( node , 'Non-constant private variables must have leading underscore' ) ;
57
68
}
58
69
}
59
70
60
71
FunctionDefinition ( node ) {
61
- if ( node . visibility === 'private' || ( node . visibility === 'internal' && node . parent . kind !== 'library' ) ) {
72
+ if ( node . visibility === 'private' ) {
62
73
if ( ! / ^ _ / . test ( node . name ) ) {
63
- this . error ( node , 'Private and internal functions must have leading underscore' ) ;
74
+ this . error ( node , 'Private functions must have leading underscore' ) ;
75
+ }
76
+ }
77
+ if ( node . visibility === 'internal' && node . parent . kind !== 'library' ) {
78
+ if ( ! / ^ _ / . test ( node . name ) ) {
79
+ this . error ( node , 'Non-library internal functions must have leading underscore' ) ;
64
80
}
65
81
}
66
82
if ( node . visibility === 'internal' && node . parent . kind === 'library' ) {
67
83
if ( / ^ _ / . test ( node . name ) ) {
68
84
this . error ( node , 'Library internal functions should not have leading underscore' ) ;
69
85
}
70
86
}
87
+ if ( node . visibility === 'public' || node . visibility === 'external' ) {
88
+ if ( / ^ _ / . test ( node . name ) ) {
89
+ this . error ( node , 'Public and external functions should not have leading underscore' ) ;
90
+ }
91
+ }
71
92
}
72
93
} ,
73
94
74
- // TODO: re-enable and fix
75
- // class extends Base {
76
- // static ruleId = 'no-external-virtual';
77
- //
78
- // FunctionDefinition(node) {
79
- // if (node.visibility == 'external' && node.isVirtual) {
80
- // this.error(node, 'Functions should not be external and virtual');
81
- // }
82
- // }
83
- // },
95
+ class extends Base {
96
+ static ruleId = 'no-external-virtual' ;
97
+
98
+ FunctionDefinition ( node ) {
99
+ if ( node . visibility == 'external' && node . isVirtual ) {
100
+ this . error ( node , 'Functions should not be external and virtual' ) ;
101
+ }
102
+ }
103
+ } ,
84
104
] ;
0 commit comments