https://github.com/goldfinch-eng/solhint-plugin-modifiers
solhint plugin for linting function modifiers. Ensure modifiers are present in certain files, contracts, and methods with flexible matching.
https://github.com/goldfinch-eng/solhint-plugin-modifiers
solhint solhint-plugin solidity
Last synced: 6 months ago
JSON representation
solhint plugin for linting function modifiers. Ensure modifiers are present in certain files, contracts, and methods with flexible matching.
- Host: GitHub
- URL: https://github.com/goldfinch-eng/solhint-plugin-modifiers
- Owner: goldfinch-eng
- License: mit
- Created: 2021-03-25T18:26:57.000Z (about 4 years ago)
- Default Branch: master
- Last Pushed: 2021-03-26T00:07:37.000Z (about 4 years ago)
- Last Synced: 2024-11-19T07:20:54.816Z (7 months ago)
- Topics: solhint, solhint-plugin, solidity
- Language: JavaScript
- Homepage:
- Size: 24.4 KB
- Stars: 2
- Watchers: 5
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# solhint-plugin-modifiers
[](https://badge.fury.io/js/solhint-plugin-modifiers)
[solhint](https://protofire.github.io/solhint/) plugin for linting function modifiers. Ensure modifiers are present in certain files, contracts, and methods with flexible matching.
## Installation
Available on npm:
```sh
npm install solhint-plugin-modifiers --save-dev
```## Usage
Enable the plugin in your project's `.solhint.json`:
```json
{
"extends": "solhint:recommended",
"plugins": ["modifiers"],
"rules": {
"modifiers/ensure-modifiers": ["error", {
"required": {
"*": ["onlyAdmin"]
}
}]
},
}
```The above configuration will require the `onlyAdmin` modifier on all methods for all contracts in all linted files.
You can use globbing to limit the required modifiers:
```json
{
"required": {
"contracts/core/*.sol": {
"Contract.method": ["onlyAdmin"],
"Contract": {
"method": ["onlyAdmin"]
},
},
"contracts/core/*.sol:Contract.method": ["onlyAdmin"],
"contracts/core/*.sol:Contract": {
"method": ["onlyAdmin"],
},
}
}
```All of the rules in the previous example are equivalent. That is, they require the `onlyAdmin` modifier for `Contract.method` defined inside some solidity file in `contracts/core/`.
The file path, contract name, and method may all be globbed e.g.
```json
{
"required": {
"contracts/core/*.sol": {
"*.transfer": ["onlyAdmin"],
"Token.*": ["onlyMinter"]
},
}
}
```If `Token.transfer` is defined in `contracts/core/Token.sol`, then it will be matched by both rules. Note that matching modifiers are unioned, so `Token.transfer` would require both `onlyAdmin` and `onlyMinter` modifiers.
### Overrides
You might want to require a modifier everywhere by default but explicitly override the requirement for some methods. You can use the `override` key to achieve this:
```json
{
"required": {
"*": ["onlyAdmin"]
},
"override": {
"*.sol:Contract.method": []
}
}
```With this configuration, `Contract.method` is overridden to require no modifiers, but all other methods require the `onlyAdmin` modifier.
### Other configuration options
Default configuration is:
```json
{
"ignoreVisibility": ["internal"],
"ignoreStateMutability": ["view", "pure"],
"ignoreContractKind": ["abstract", "interface"],
"verbose": false,
"required": {},
"override": {}
}
```In other words, `internal`, `view`, and `pure` methods are ignored by default, as are methods in `abstract` or `interface` contracts.