@@ -14,8 +14,8 @@ class Base {
14
14
}
15
15
}
16
16
17
- error ( node , message ) {
18
- if ( ! this . ignored ) {
17
+ require ( condition , node , message ) {
18
+ if ( ! condition && ! this . ignored ) {
19
19
this . reporter . error ( node , this . ruleId , message ) ;
20
20
}
21
21
}
@@ -26,8 +26,8 @@ module.exports = [
26
26
static ruleId = 'interface-only-external-functions' ;
27
27
28
28
FunctionDefinition ( node ) {
29
- if ( node . parent . kind === 'interface' && node . visibility !== 'external' ) {
30
- this . error ( node , 'Interface functions must be external' ) ;
29
+ if ( node . parent . kind === 'interface' ) {
30
+ this . require ( node . visibility === 'external' , node , 'Interface functions must be external' ) ;
31
31
}
32
32
}
33
33
} ,
@@ -36,8 +36,12 @@ module.exports = [
36
36
static ruleId = 'private-variables' ;
37
37
38
38
VariableDeclaration ( node ) {
39
- if ( node . isStateVar && ! node . isDeclaredConst && ! node . isImmutable && node . visibility !== 'private' ) {
40
- this . error ( node , 'State variables must be private' ) ;
39
+ if ( node . isStateVar ) {
40
+ this . require (
41
+ node . isDeclaredConst || node . isImmutable || node . visibility === 'private' ,
42
+ node ,
43
+ 'State variables must be private' ,
44
+ ) ;
41
45
}
42
46
}
43
47
} ,
@@ -46,38 +50,45 @@ module.exports = [
46
50
static ruleId = 'leading-underscore' ;
47
51
48
52
VariableDeclaration ( node ) {
49
- if ( node . isDeclaredConst && node . name . startsWith ( '_' ) ) {
50
- this . error ( node , 'Constant variables should not have leading underscore' ) ;
51
- }
52
- if ( node . isImmutable && node . name . startsWith ( '_' ) ) {
53
- this . error ( node , 'Immutable variables should not have leading underscore' ) ;
54
- }
55
- if ( node . isStateVar && node . visibility === 'private' && ! node . name . startsWith ( '_' ) ) {
56
- this . error ( node , 'Private state variables must have leading underscore' ) ;
57
- }
58
- if ( node . isStateVar && node . visibility === 'internal' && ! node . name . startsWith ( '_' ) ) {
59
- this . error ( node , 'Internal state variables must have leading underscore' ) ;
60
- }
61
- if ( node . isStateVar && node . visibility === 'public' && node . name . startsWith ( '_' ) ) {
62
- this . error ( node , 'Public state variables should not have leading underscore' ) ;
53
+ if ( node . isDeclaredConst ) {
54
+ this . require ( ! node . name . startsWith ( '_' ) , node , 'Constant variables should not have leading underscore' ) ;
55
+ } else if ( node . isImmutable ) {
56
+ this . require ( ! node . name . startsWith ( '_' ) , node , 'Immutable variables should not have leading underscore' ) ;
57
+ } else if ( node . isStateVar ) {
58
+ switch ( node . visibility ) {
59
+ case 'private' :
60
+ this . require ( node . name . startsWith ( '_' ) , node , 'Private state variables must have leading underscore' ) ;
61
+ break ;
62
+ case 'internal' :
63
+ this . require ( node . name . startsWith ( '_' ) , node , 'Internal state variables must have leading underscore' ) ;
64
+ break ;
65
+ case 'public' :
66
+ this . require ( ! node . name . startsWith ( '_' ) , node , 'Public state variables should not have leading underscore' ) ;
67
+ break ;
68
+ }
63
69
}
64
70
}
65
71
66
72
FunctionDefinition ( node ) {
67
- if ( node . visibility === 'private' && ! node . name . startsWith ( '_' ) ) {
68
- this . error ( node , 'Private functions must have leading underscore' ) ;
69
- }
70
- if ( node . visibility === 'internal' && node . parent . kind !== 'library' && ! node . name . startsWith ( '_' ) ) {
71
- this . error ( node , 'Non-library internal functions must have leading underscore' ) ;
72
- }
73
- if ( node . visibility === 'internal' && node . parent . kind === 'library' && node . name . startsWith ( '_' ) ) {
74
- this . error ( node , 'Library internal functions should not have leading underscore' ) ;
75
- }
76
- if ( node . visibility === 'public' && node . name . startsWith ( '_' ) ) {
77
- this . error ( node , 'Public functions should not have leading underscore' ) ;
78
- }
79
- if ( node . visibility === 'external' && node . name . startsWith ( '_' ) ) {
80
- this . error ( node , 'External functions should not have leading underscore' ) ;
73
+ switch ( node . visibility ) {
74
+ case 'external' :
75
+ this . require ( ! node . name . startsWith ( '_' ) , node , 'External functions should not have leading underscore' ) ;
76
+ break ;
77
+ case 'public' :
78
+ this . require ( ! node . name . startsWith ( '_' ) , node , 'Public functions should not have leading underscore' ) ;
79
+ break ;
80
+ case 'internal' :
81
+ this . require (
82
+ node . name . startsWith ( '_' ) !== ( node . parent . kind === 'library' ) ,
83
+ node ,
84
+ node . parent . kind === 'library'
85
+ ? 'Library internal functions should not have leading underscore'
86
+ : 'Non-library internal functions must have leading underscore' ,
87
+ ) ;
88
+ break ;
89
+ case 'private' :
90
+ this . require ( node . name . startsWith ( '_' ) , node , 'Private functions must have leading underscore' ) ;
91
+ break ;
81
92
}
82
93
}
83
94
} ,
@@ -86,8 +97,12 @@ module.exports = [
86
97
static ruleId = 'no-external-virtual' ;
87
98
88
99
FunctionDefinition ( node ) {
89
- if ( node . visibility == 'external' && node . isVirtual ) {
90
- this . error ( node , 'Functions should not be external and virtual' ) ;
100
+ if ( node . visibility == 'external' ) {
101
+ this . require (
102
+ node . isReceiveEther || node . isFallback || ! node . isVirtual ,
103
+ node ,
104
+ 'Functions should not be external and virtual' ,
105
+ ) ;
91
106
}
92
107
}
93
108
} ,
0 commit comments