Skip to content

Commit

Permalink
Add rule for Interfaces being prefixed with 'I' (#10)
Browse files Browse the repository at this point in the history
  • Loading branch information
alecgard authored Feb 16, 2024
1 parent 1b4c0c2 commit 2f0a3a6
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 1 deletion.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ Create a `.solhint.json` in your root project directory:
"chainlink-solidity/prefix-private-functions-with-underscore": "warn",
"chainlink-solidity/prefix-storage-variables-with-s-underscore": "warn",
"chainlink-solidity/prefix-immutable-variables-with-i": "warn",
"chainlink-solidity/prefix-interfaces-with-i": "warn",
"chainlink-solidity/all-caps-constant-storage-variables": "warn",
"chainlink-solidity/no-hardhat-imports": "warn",
"chainlink-solidity/inherited-constructor-args-not-in-contract-definition": "warn",
Expand Down Expand Up @@ -77,6 +78,7 @@ src/Counter.sol
| `prefix-private-functions-with-underscore` | Naming convention |
| `prefix-storage-variables-with-s-underscore` | Naming convention |
| `prefix-immutable-variables-with-i` | Naming convention |
| `prefix-interfaces-with-i` | Naming convention |
| `all-caps-constant-storage-variables` | Naming convention |
| `no-hardhat-imports` | Leftover `hardhat/*.sol` imports not allowed |
| `inherited-constructor-args-not-in-contract-definition` | Inherited contract constructor arguments should be specified in the constructor block |
Expand Down
2 changes: 2 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ const PrefixInternalFunctionsWithUnderscore = require('./rules/prefixInternalFun
const PrefixPrivateFunctionsWithUnderscore = require('./rules/prefixPrivateFunctionsWithUnderscore.js');
const PrefixStorageVariablesWithSUnderscore = require('./rules/prefixStorageVariablesWithSUnderscore.js');
const PrefixImmutableVariablesWithI = require('./rules/prefixImmutableVariablesWithI');
const PrefixInterfacesWithI = require('./rules/prefixInterfacesWithI');
const AllCapsConstantStorageVariables = require('./rules/allCapsConstantStorageVariables.js');
const NoHardhatImports = require('./rules/noHardhatImports.js');
const InheritedConstructorArgsNotInContractDefinition = require('./rules/inheritedConstructorArgsNotInContractDefinition.js');
Expand All @@ -14,6 +15,7 @@ module.exports = [
PrefixPrivateFunctionsWithUnderscore,
PrefixStorageVariablesWithSUnderscore,
PrefixImmutableVariablesWithI,
PrefixInterfacesWithI,
AllCapsConstantStorageVariables,
NoHardhatImports,
InheritedConstructorArgsNotInContractDefinition,
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "@chainlink/solhint-plugin-chainlink-solidity",
"version": "1.2.0",
"version": "1.3.0",
"main": "index.js"
}
29 changes: 29 additions & 0 deletions rules/prefixInterfacesWithI.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
class PrefixInterfacesWithI {
constructor(reporter, config) {
this.ruleId = "prefix-interfaces-with-i";
this.reporter = reporter;
this.config = config;
}

ContractDefinition(ctx) {
const { type, kind, name } = ctx;

if (kind === "interface") {
if (name.endsWith("Interface")) {
this.reporter.error(
ctx,
this.ruleId,
`Interface ${name} is suffixed with 'Interface', should instead be prefixed with 'I' e.g. 'IFoo'`
);
} else if (!name.startsWith("I")) {
this.reporter.error(
ctx,
this.ruleId,
`Interface ${name} is not prefixed with 'I', e.g. 'IFoo'`
);
}
}
}
}

module.exports = PrefixInterfacesWithI;

0 comments on commit 2f0a3a6

Please sign in to comment.