Add custom linting rules
Fixes #3919
Add solhint-plugin-ozcontracts to devDependencies Add ozonctracts to .solhint.json plugins Add oz-contracts-custom to .solhint.json rules
PR Checklist
- [ x] Tests
- [ ] Documentation
- [ ] Changeset entry (run
npx changeset add)
⚠️ No Changeset found
Latest commit: 276dbae7c93b3f1c438f856f6db46b3b3099fced
Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.
This PR includes no changesets
When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types
Click here to learn what changesets are, and how to add one.
Click here if you're a maintainer who wants to add a changeset to this PR
Nice @lhemerly! This is appreciated.
Is it possible to have the "plugin" as a JS file in this repository, rather than a separate npm package? I would like to do that as it will be easier for us to maintain and evolve.
As far as I know it is not possible right now as you can't set-up the plugin path in solhint: Solhint - Issue#206
It is hardcoded to look up for solhint-plugin-${pluginName} in the node_modules folder:
Solhint loadPlugin Function
I may try a PR on Solhint for custom plugins paths later
Just a follow up, PR in solhint created: Solhint PR for Issue #206
Maybe we could make it work by defining the package locally in the repo? Not exactly but sort of monorepo style.
The way I can imagine making it work as solhint is right now is to take the "solhint-plugin-ozcontracts" folder inside node_modules out of the gitignore and work with the .js file there as part of the repo. The way npm (or yarn) install works it won't change that folder as long as we remove and keep it out of package.json.
If you think it is ok to go with that I can make the necessary changes
Putting in node_modules is not ideal. We should be able to put it in a subdirectory somewhere in the repo and add "solhint-plugin-custom": "file:./solhint-plugin" in the dependencies.
@lhemerly I've vendored your plugin into this repository like I suggested.
This should be a great start to begin to build more custom linting rules. Thanks!
@Amxx @ernestognw Note that this will allow us to have internal constants without leading underscore moving forward.
Just an update, development branch in solhint adjusted plugins to be in any path: https://github.com/protofire/solhint/pull/424#event-9745473144
Congrats, your important contribution to this open-source project has earned you a GitPOAP!
GitPOAP: 2023 OpenZeppelin Contracts Contributor:
Head to gitpoap.io & connect your GitHub account to mint!
Learn more about GitPOAPs here.