Skip to content

Commit d807d85

Browse files
authored
Update index.js
1 parent f859dd7 commit d807d85

File tree

1 file changed

+11
-12
lines changed

1 file changed

+11
-12
lines changed

scripts/solhint-custom/index.js

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,7 @@ module.exports = [
3636
static ruleId = 'private-variables';
3737

3838
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') {
4140
this.error(node, 'State variables must be private');
4241
}
4342
}
@@ -47,37 +46,37 @@ module.exports = [
4746
static ruleId = 'leading-underscore';
4847

4948
VariableDeclaration(node) {
50-
if (node.isDeclaredConst && /^_/.test(node.name)) {
49+
if (node.isDeclaredConst && node.name.startsWith('_')) {
5150
this.error(node, 'Constant variables should not have leading underscore');
5251
}
53-
if (node.isImmutable && /^_/.test(node.name)) {
52+
if (node.isImmutable && node.name.startsWith('_')) {
5453
this.error(node, 'Immutable variables should not have leading underscore');
5554
}
56-
if (node.isStateVar && node.visibility === 'private' && !/^_/.test(node.name)) {
55+
if (node.isStateVar && node.visibility === 'private' && !node.name.startsWith('_')) {
5756
this.error(node, 'Private state variables must have leading underscore');
5857
}
59-
if (node.isStateVar && node.visibility === 'internal' && !/^_/.test(node.name)) {
58+
if (node.isStateVar && node.visibility === 'internal' && !node.name.startsWith('_')) {
6059
this.error(node, 'Internal state variables must have leading underscore');
6160
}
62-
if (node.isStateVar && node.visibility === 'public' && /^_/.test(node.name)) {
61+
if (node.isStateVar && node.visibility === 'public' && node.name.startsWith('_')) {
6362
this.error(node, 'Public state variables should not have leading underscore');
6463
}
6564
}
6665

6766
FunctionDefinition(node) {
68-
if (node.visibility === 'private' && !/^_/.test(node.name)) {
67+
if (node.visibility === 'private' && !node.name.startsWith('_')) {
6968
this.error(node, 'Private functions must have leading underscore');
7069
}
71-
if (node.visibility === 'internal' && node.parent.kind !== 'library' && !/^_/.test(node.name)) {
70+
if (node.visibility === 'internal' && node.parent.kind !== 'library' && !node.name.startsWith('_')) {
7271
this.error(node, 'Non-library internal functions must have leading underscore');
7372
}
74-
if (node.visibility === 'internal' && node.parent.kind === 'library' && /^_/.test(node.name)) {
73+
if (node.visibility === 'internal' && node.parent.kind === 'library' && node.name.startsWith('_')) {
7574
this.error(node, 'Library internal functions should not have leading underscore');
7675
}
77-
if (node.visibility === 'public' && /^_/.test(node.name)) {
76+
if (node.visibility === 'public' && node.name.startsWith('_')) {
7877
this.error(node, 'Public functions should not have leading underscore');
7978
}
80-
if (node.visibility === 'external' && /^_/.test(node.name)) {
79+
if (node.visibility === 'external' && node.name.startsWith('_')) {
8180
this.error(node, 'External functions should not have leading underscore');
8281
}
8382
}

0 commit comments

Comments
 (0)