@@ -36,8 +36,7 @@ module.exports = [
36
36
static ruleId = 'private-variables' ;
37
37
38
38
VariableDeclaration ( node ) {
39
- const constantOrImmutable = node . isDeclaredConst || node . isImmutable ;
40
- if ( node . isStateVar && ! constantOrImmutable && node . visibility !== 'private' ) {
39
+ if ( node . isStateVar && ! node . isDeclaredConst && ! node . isImmutable && node . visibility !== 'private' ) {
41
40
this . error ( node , 'State variables must be private' ) ;
42
41
}
43
42
}
@@ -47,37 +46,37 @@ module.exports = [
47
46
static ruleId = 'leading-underscore' ;
48
47
49
48
VariableDeclaration ( node ) {
50
- if ( node . isDeclaredConst && / ^ _ / . test ( node . name ) ) {
49
+ if ( node . isDeclaredConst && node . name . startsWith ( '_' ) ) {
51
50
this . error ( node , 'Constant variables should not have leading underscore' ) ;
52
51
}
53
- if ( node . isImmutable && / ^ _ / . test ( node . name ) ) {
52
+ if ( node . isImmutable && node . name . startsWith ( '_' ) ) {
54
53
this . error ( node , 'Immutable variables should not have leading underscore' ) ;
55
54
}
56
- if ( node . isStateVar && node . visibility === 'private' && ! / ^ _ / . test ( node . name ) ) {
55
+ if ( node . isStateVar && node . visibility === 'private' && ! node . name . startsWith ( '_' ) ) {
57
56
this . error ( node , 'Private state variables must have leading underscore' ) ;
58
57
}
59
- if ( node . isStateVar && node . visibility === 'internal' && ! / ^ _ / . test ( node . name ) ) {
58
+ if ( node . isStateVar && node . visibility === 'internal' && ! node . name . startsWith ( '_' ) ) {
60
59
this . error ( node , 'Internal state variables must have leading underscore' ) ;
61
60
}
62
- if ( node . isStateVar && node . visibility === 'public' && / ^ _ / . test ( node . name ) ) {
61
+ if ( node . isStateVar && node . visibility === 'public' && node . name . startsWith ( '_' ) ) {
63
62
this . error ( node , 'Public state variables should not have leading underscore' ) ;
64
63
}
65
64
}
66
65
67
66
FunctionDefinition ( node ) {
68
- if ( node . visibility === 'private' && ! / ^ _ / . test ( node . name ) ) {
67
+ if ( node . visibility === 'private' && ! node . name . startsWith ( '_' ) ) {
69
68
this . error ( node , 'Private functions must have leading underscore' ) ;
70
69
}
71
- if ( node . visibility === 'internal' && node . parent . kind !== 'library' && ! / ^ _ / . test ( node . name ) ) {
70
+ if ( node . visibility === 'internal' && node . parent . kind !== 'library' && ! node . name . startsWith ( '_' ) ) {
72
71
this . error ( node , 'Non-library internal functions must have leading underscore' ) ;
73
72
}
74
- if ( node . visibility === 'internal' && node . parent . kind === 'library' && / ^ _ / . test ( node . name ) ) {
73
+ if ( node . visibility === 'internal' && node . parent . kind === 'library' && node . name . startsWith ( '_' ) ) {
75
74
this . error ( node , 'Library internal functions should not have leading underscore' ) ;
76
75
}
77
- if ( node . visibility === 'public' && / ^ _ / . test ( node . name ) ) {
76
+ if ( node . visibility === 'public' && node . name . startsWith ( '_' ) ) {
78
77
this . error ( node , 'Public functions should not have leading underscore' ) ;
79
78
}
80
- if ( node . visibility === 'external' && / ^ _ / . test ( node . name ) ) {
79
+ if ( node . visibility === 'external' && node . name . startsWith ( '_' ) ) {
81
80
this . error ( node , 'External functions should not have leading underscore' ) ;
82
81
}
83
82
}
0 commit comments