From 37c7a5216f8903629c20cfa4bdfa0203541c12a9 Mon Sep 17 00:00:00 2001 From: Gonzalo Othacehe Date: Thu, 10 Jul 2025 16:53:03 -0300 Subject: [PATCH 1/7] up rules --- scripts/solhint-custom/index.js | 64 +++++++++++++++++++++------------ 1 file changed, 42 insertions(+), 22 deletions(-) diff --git a/scripts/solhint-custom/index.js b/scripts/solhint-custom/index.js index 9625027eefe..28d5ebf4fef 100644 --- a/scripts/solhint-custom/index.js +++ b/scripts/solhint-custom/index.js @@ -23,11 +23,11 @@ class Base { module.exports = [ class extends Base { - static ruleId = 'interface-names'; + static ruleId = 'interface-only-external-functions'; - ContractDefinition(node) { - if (node.kind === 'interface' && !/^I[A-Z]/.test(node.name)) { - this.error(node, 'Interface names should have a capital I prefix'); + FunctionDefinition(node) { + if (node.parent.kind === 'interface' && node.visibility !== 'external') { + this.error(node, 'Interface functions must be external'); } } }, @@ -47,20 +47,36 @@ module.exports = [ static ruleId = 'leading-underscore'; VariableDeclaration(node) { - if (node.isDeclaredConst) { - // TODO: expand visibility and fix - if (node.visibility === 'private' && /^_/.test(node.name)) { - this.error(node, 'Constant variables should not have leading underscore'); + if (node.isDeclaredConst || node.isImmutable) { + if (/^_/.test(node.name)) { + this.error(node, 'Constant and immutable variables should not have leading underscore'); + } + } + else { + if (node.isStateVar) { + if (node.visibility === 'private' || node.visibility === 'internal') { + if (!/^_/.test(node.name)) { + this.error(node, 'Private and internal state variables must have leading underscore'); + } + } + else { + if (/^_/.test(node.name)) { + this.error(node, 'Public state variables should not have leading underscore'); + } + } } - } else if (node.visibility === 'private' && !/^_/.test(node.name)) { - this.error(node, 'Non-constant private variables must have leading underscore'); } } FunctionDefinition(node) { - if (node.visibility === 'private' || (node.visibility === 'internal' && node.parent.kind !== 'library')) { + if (node.visibility === 'private') { if (!/^_/.test(node.name)) { - this.error(node, 'Private and internal functions must have leading underscore'); + this.error(node, 'Private functions must have leading underscore'); + } + } + if (node.visibility === 'internal' && node.parent.kind !== 'library') { + if (!/^_/.test(node.name)) { + this.error(node, 'Non-library internal functions must have leading underscore'); } } if (node.visibility === 'internal' && node.parent.kind === 'library') { @@ -68,17 +84,21 @@ module.exports = [ this.error(node, 'Library internal functions should not have leading underscore'); } } + if (node.visibility === 'public' || node.visibility === 'external') { + if (/^_/.test(node.name)) { + this.error(node, 'Public and external functions should not have leading underscore'); + } + } } }, - // TODO: re-enable and fix - // class extends Base { - // static ruleId = 'no-external-virtual'; - // - // FunctionDefinition(node) { - // if (node.visibility == 'external' && node.isVirtual) { - // this.error(node, 'Functions should not be external and virtual'); - // } - // } - // }, + class extends Base { + static ruleId = 'no-external-virtual'; + + FunctionDefinition(node) { + if (node.visibility == 'external' && node.isVirtual) { + this.error(node, 'Functions should not be external and virtual'); + } + } + }, ]; From 6e13ca783a60367f7d23b93b719a548b96586c41 Mon Sep 17 00:00:00 2001 From: Hadrien Croubois Date: Thu, 10 Jul 2025 23:38:29 +0200 Subject: [PATCH 2/7] Update index.js --- scripts/solhint-custom/index.js | 28 ++++++++++++---------------- 1 file changed, 12 insertions(+), 16 deletions(-) diff --git a/scripts/solhint-custom/index.js b/scripts/solhint-custom/index.js index 28d5ebf4fef..7f6cb5d5b9a 100644 --- a/scripts/solhint-custom/index.js +++ b/scripts/solhint-custom/index.js @@ -47,23 +47,19 @@ module.exports = [ static ruleId = 'leading-underscore'; VariableDeclaration(node) { - if (node.isDeclaredConst || node.isImmutable) { - if (/^_/.test(node.name)) { - this.error(node, 'Constant and immutable variables should not have leading underscore'); - } + if (node.isDeclaredConst || node.isImmutable) { + if (/^_/.test(node.name)) { + this.error(node, 'Constant and immutable variables should not have leading underscore'); } - else { - if (node.isStateVar) { - if (node.visibility === 'private' || node.visibility === 'internal') { - if (!/^_/.test(node.name)) { - this.error(node, 'Private and internal state variables must have leading underscore'); - } - } - else { - if (/^_/.test(node.name)) { - this.error(node, 'Public state variables should not have leading underscore'); - } - } + } else if (node.isStateVar) { + if (node.visibility === 'private' || node.visibility === 'internal') { + if (!/^_/.test(node.name)) { + this.error(node, 'Private and internal state variables must have leading underscore'); + } + } else { + if (/^_/.test(node.name)) { + this.error(node, 'Public state variables should not have leading underscore'); + } } } } From 56b120f607f79a30afa37091e83edf527f724fe3 Mon Sep 17 00:00:00 2001 From: Hadrien Croubois Date: Thu, 10 Jul 2025 23:40:26 +0200 Subject: [PATCH 3/7] Update index.js --- scripts/solhint-custom/index.js | 24 ++++++++---------------- 1 file changed, 8 insertions(+), 16 deletions(-) diff --git a/scripts/solhint-custom/index.js b/scripts/solhint-custom/index.js index 7f6cb5d5b9a..03a33779e8e 100644 --- a/scripts/solhint-custom/index.js +++ b/scripts/solhint-custom/index.js @@ -65,25 +65,17 @@ module.exports = [ } FunctionDefinition(node) { - if (node.visibility === 'private') { - if (!/^_/.test(node.name)) { - this.error(node, 'Private functions must have leading underscore'); - } + if (node.visibility === 'private' && !/^_/.test(node.name)) { + this.error(node, 'Private functions must have leading underscore'); } - if (node.visibility === 'internal' && node.parent.kind !== 'library') { - if (!/^_/.test(node.name)) { - this.error(node, 'Non-library internal functions must have leading underscore'); - } + if (node.visibility === 'internal' && node.parent.kind !== 'library' && !/^_/.test(node.name)) { + this.error(node, 'Non-library internal functions must have leading underscore'); } - if (node.visibility === 'internal' && node.parent.kind === 'library') { - if (/^_/.test(node.name)) { - this.error(node, 'Library internal functions should not have leading underscore'); - } + if (node.visibility === 'internal' && node.parent.kind === 'library' && /^_/.test(node.name)) { + this.error(node, 'Library internal functions should not have leading underscore'); } - if (node.visibility === 'public' || node.visibility === 'external') { - if (/^_/.test(node.name)) { - this.error(node, 'Public and external functions should not have leading underscore'); - } + if (node.visibility === 'public' || node.visibility === 'external' && /^_/.test(node.name)) { + this.error(node, 'Public and external functions should not have leading underscore'); } } }, From ba351f3211ed3d990aa1c822426966c41d13c7bd Mon Sep 17 00:00:00 2001 From: Hadrien Croubois Date: Thu, 10 Jul 2025 23:41:44 +0200 Subject: [PATCH 4/7] Update index.js --- scripts/solhint-custom/index.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/scripts/solhint-custom/index.js b/scripts/solhint-custom/index.js index 03a33779e8e..a586790aadd 100644 --- a/scripts/solhint-custom/index.js +++ b/scripts/solhint-custom/index.js @@ -74,8 +74,11 @@ module.exports = [ if (node.visibility === 'internal' && node.parent.kind === 'library' && /^_/.test(node.name)) { this.error(node, 'Library internal functions should not have leading underscore'); } - if (node.visibility === 'public' || node.visibility === 'external' && /^_/.test(node.name)) { - this.error(node, 'Public and external functions should not have leading underscore'); + if (node.visibility === 'public' && /^_/.test(node.name)) { + this.error(node, 'Public functions should not have leading underscore'); + } + if (node.visibility === 'external' && /^_/.test(node.name)) { + this.error(node, 'External functions should not have leading underscore'); } } }, From bee7bc3b497857e2a182b379900c8b396b8d80bc Mon Sep 17 00:00:00 2001 From: Hadrien Croubois Date: Wed, 16 Jul 2025 22:31:26 +0200 Subject: [PATCH 5/7] Update index.js --- scripts/solhint-custom/index.js | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/scripts/solhint-custom/index.js b/scripts/solhint-custom/index.js index a586790aadd..6718ab7b858 100644 --- a/scripts/solhint-custom/index.js +++ b/scripts/solhint-custom/index.js @@ -52,14 +52,14 @@ module.exports = [ this.error(node, 'Constant and immutable variables should not have leading underscore'); } } else if (node.isStateVar) { - if (node.visibility === 'private' || node.visibility === 'internal') { - if (!/^_/.test(node.name)) { - this.error(node, 'Private and internal state variables must have leading underscore'); - } - } else { - if (/^_/.test(node.name)) { - this.error(node, 'Public state variables should not have leading underscore'); - } + if (node.visibility === 'private' && !/^_/.test(node.name)) + this.error(node, 'Private state variables must have leading underscore'); + } + if (node.visibility === 'internal' && !/^_/.test(node.name)) { + this.error(node, 'Internal state variables must have leading underscore'); + } + if (node.visibility === 'public' && /^_/.test(node.name)) { + this.error(node, 'Public state variables should not have leading underscore'); } } } From f859dd7933f7a1e6fc18ac6c7c129e24ef2497b2 Mon Sep 17 00:00:00 2001 From: Hadrien Croubois Date: Wed, 16 Jul 2025 22:33:10 +0200 Subject: [PATCH 6/7] Update index.js --- scripts/solhint-custom/index.js | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/scripts/solhint-custom/index.js b/scripts/solhint-custom/index.js index 6718ab7b858..060ee81d6a3 100644 --- a/scripts/solhint-custom/index.js +++ b/scripts/solhint-custom/index.js @@ -47,20 +47,20 @@ module.exports = [ static ruleId = 'leading-underscore'; VariableDeclaration(node) { - if (node.isDeclaredConst || node.isImmutable) { - if (/^_/.test(node.name)) { - this.error(node, 'Constant and immutable variables should not have leading underscore'); - } - } else if (node.isStateVar) { - if (node.visibility === 'private' && !/^_/.test(node.name)) - this.error(node, 'Private state variables must have leading underscore'); - } - if (node.visibility === 'internal' && !/^_/.test(node.name)) { - this.error(node, 'Internal state variables must have leading underscore'); - } - if (node.visibility === 'public' && /^_/.test(node.name)) { - this.error(node, 'Public state variables should not have leading underscore'); - } + if (node.isDeclaredConst && /^_/.test(node.name)) { + this.error(node, 'Constant variables should not have leading underscore'); + } + if (node.isImmutable && /^_/.test(node.name)) { + this.error(node, 'Immutable variables should not have leading underscore'); + } + if (node.isStateVar && node.visibility === 'private' && !/^_/.test(node.name)) { + this.error(node, 'Private state variables must have leading underscore'); + } + if (node.isStateVar && node.visibility === 'internal' && !/^_/.test(node.name)) { + this.error(node, 'Internal state variables must have leading underscore'); + } + if (node.isStateVar && node.visibility === 'public' && /^_/.test(node.name)) { + this.error(node, 'Public state variables should not have leading underscore'); } } From d807d85c14ea35ac533bfc46d5453d65c9ee9d79 Mon Sep 17 00:00:00 2001 From: Hadrien Croubois Date: Wed, 16 Jul 2025 22:36:28 +0200 Subject: [PATCH 7/7] Update index.js --- scripts/solhint-custom/index.js | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/scripts/solhint-custom/index.js b/scripts/solhint-custom/index.js index 060ee81d6a3..5fe96ee1b3b 100644 --- a/scripts/solhint-custom/index.js +++ b/scripts/solhint-custom/index.js @@ -36,8 +36,7 @@ module.exports = [ static ruleId = 'private-variables'; VariableDeclaration(node) { - const constantOrImmutable = node.isDeclaredConst || node.isImmutable; - if (node.isStateVar && !constantOrImmutable && node.visibility !== 'private') { + if (node.isStateVar && !node.isDeclaredConst && !node.isImmutable && node.visibility !== 'private') { this.error(node, 'State variables must be private'); } } @@ -47,37 +46,37 @@ module.exports = [ static ruleId = 'leading-underscore'; VariableDeclaration(node) { - if (node.isDeclaredConst && /^_/.test(node.name)) { + if (node.isDeclaredConst && node.name.startsWith('_')) { this.error(node, 'Constant variables should not have leading underscore'); } - if (node.isImmutable && /^_/.test(node.name)) { + if (node.isImmutable && node.name.startsWith('_')) { this.error(node, 'Immutable variables should not have leading underscore'); } - if (node.isStateVar && node.visibility === 'private' && !/^_/.test(node.name)) { + if (node.isStateVar && node.visibility === 'private' && !node.name.startsWith('_')) { this.error(node, 'Private state variables must have leading underscore'); } - if (node.isStateVar && node.visibility === 'internal' && !/^_/.test(node.name)) { + if (node.isStateVar && node.visibility === 'internal' && !node.name.startsWith('_')) { this.error(node, 'Internal state variables must have leading underscore'); } - if (node.isStateVar && node.visibility === 'public' && /^_/.test(node.name)) { + if (node.isStateVar && node.visibility === 'public' && node.name.startsWith('_')) { this.error(node, 'Public state variables should not have leading underscore'); } } FunctionDefinition(node) { - if (node.visibility === 'private' && !/^_/.test(node.name)) { + if (node.visibility === 'private' && !node.name.startsWith('_')) { this.error(node, 'Private functions must have leading underscore'); } - if (node.visibility === 'internal' && node.parent.kind !== 'library' && !/^_/.test(node.name)) { + if (node.visibility === 'internal' && node.parent.kind !== 'library' && !node.name.startsWith('_')) { this.error(node, 'Non-library internal functions must have leading underscore'); } - if (node.visibility === 'internal' && node.parent.kind === 'library' && /^_/.test(node.name)) { + if (node.visibility === 'internal' && node.parent.kind === 'library' && node.name.startsWith('_')) { this.error(node, 'Library internal functions should not have leading underscore'); } - if (node.visibility === 'public' && /^_/.test(node.name)) { + if (node.visibility === 'public' && node.name.startsWith('_')) { this.error(node, 'Public functions should not have leading underscore'); } - if (node.visibility === 'external' && /^_/.test(node.name)) { + if (node.visibility === 'external' && node.name.startsWith('_')) { this.error(node, 'External functions should not have leading underscore'); } }