openzeppelin-contracts icon indicating copy to clipboard operation
openzeppelin-contracts copied to clipboard

Add custom linting rules

Open lhemerly opened this issue 3 years ago • 6 comments

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)

lhemerly avatar Mar 22 '23 23:03 lhemerly

⚠️ 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

changeset-bot[bot] avatar Mar 22 '23 23:03 changeset-bot[bot]

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.

frangio avatar Mar 22 '23 23:03 frangio

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

lhemerly avatar Mar 23 '23 00:03 lhemerly

Just a follow up, PR in solhint created: Solhint PR for Issue #206

lhemerly avatar Mar 24 '23 02:03 lhemerly

Maybe we could make it work by defining the package locally in the repo? Not exactly but sort of monorepo style.

frangio avatar Mar 24 '23 22:03 frangio

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

lhemerly avatar Mar 25 '23 00:03 lhemerly

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.

frangio avatar Jun 16 '23 17:06 frangio

@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!

frangio avatar Jul 06 '23 03:07 frangio

@Amxx @ernestognw Note that this will allow us to have internal constants without leading underscore moving forward.

frangio avatar Jul 06 '23 03:07 frangio

Just an update, development branch in solhint adjusted plugins to be in any path: https://github.com/protofire/solhint/pull/424#event-9745473144

lhemerly avatar Jul 06 '23 16:07 lhemerly

Congrats, your important contribution to this open-source project has earned you a GitPOAP!

GitPOAP: 2023 OpenZeppelin Contracts Contributor:

GitPOAP: 2023 OpenZeppelin Contracts Contributor GitPOAP Badge

Head to gitpoap.io & connect your GitHub account to mint!

Learn more about GitPOAPs here.

gitpoap-bot[bot] avatar Jul 10 '23 20:07 gitpoap-bot[bot]