Skip to content

Commit 37c7a52

Browse files
committed
up rules
1 parent 21cd7e8 commit 37c7a52

File tree

1 file changed

+42
-22
lines changed

1 file changed

+42
-22
lines changed

scripts/solhint-custom/index.js

Lines changed: 42 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,11 @@ class Base {
2323

2424
module.exports = [
2525
class extends Base {
26-
static ruleId = 'interface-names';
26+
static ruleId = 'interface-only-external-functions';
2727

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');
3131
}
3232
}
3333
},
@@ -47,38 +47,58 @@ module.exports = [
4747
static ruleId = 'leading-underscore';
4848

4949
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+
}
5467
}
55-
} else if (node.visibility === 'private' && !/^_/.test(node.name)) {
56-
this.error(node, 'Non-constant private variables must have leading underscore');
5768
}
5869
}
5970

6071
FunctionDefinition(node) {
61-
if (node.visibility === 'private' || (node.visibility === 'internal' && node.parent.kind !== 'library')) {
72+
if (node.visibility === 'private') {
6273
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');
6480
}
6581
}
6682
if (node.visibility === 'internal' && node.parent.kind === 'library') {
6783
if (/^_/.test(node.name)) {
6884
this.error(node, 'Library internal functions should not have leading underscore');
6985
}
7086
}
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+
}
7192
}
7293
},
7394

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+
},
84104
];

0 commit comments

Comments
 (0)