Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(@nomiclabs/hardhat-solhint): load .solhintignore file #3741

Closed
wants to merge 0 commits into from

Conversation

yhuard
Copy link
Contributor

@yhuard yhuard commented Mar 5, 2023

  • Because this PR includes a new feature, the change was previously discussed on an Issue or with someone from the team

Fixes #1665.
I'm not sure whether this is to be considered as a bugfix or a new feature.

@changeset-bot
Copy link

changeset-bot bot commented Mar 5, 2023

⚠️ No Changeset found

Latest commit: 839b4d2

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

@vercel
Copy link

vercel bot commented Mar 5, 2023

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated
hardhat ✅ Ready (Inspect) Visit Preview 💬 Add your feedback Mar 11, 2023 at 11:46AM (UTC)
hardhat-storybook ✅ Ready (Inspect) Visit Preview 💬 Add your feedback Mar 11, 2023 at 11:46AM (UTC)

@@ -84,7 +105,10 @@ function printReport(reports: any) {
subtask("hardhat-solhint:run-solhint", async (_, { config }) => {
const { processPath } = require("solhint/lib/index");
return processPath(
join(config.paths.sources, "**", "*.sol").replace(/\\/g, "/"),
relative(
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because ignore requires relative paths to properly work (used by Solhint here)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add a comment explaining this and the .replace?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done. Let me know if it's clear enough :)

Copy link
Member

@fvictorio fvictorio Mar 9, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this would be a bit more readable if it was done in two or three statements, with interspersed comments. Something like this:

// we need a relative path because...
const sourcesPath = relative(config.paths.root, config.paths.sources);

// we create a glob that matches all .sol files
const solFilesGlob = join(sourcesPath, "**", "*.sol");

// globs only use forward slashes, even on windows
const normalizedGlob = solFilesGlob.replace(...)

Wdyt @yhuard?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for your feedback @fvictorio I've refactored the code as you suggested.

@yhuard
Copy link
Contributor Author

yhuard commented Mar 5, 2023

I'm investigating the issue on Windows (again...)

Edit: never mind, I forgot to apply .replace(/\\/g, "/") to the output of relative(...)

@Oni-giri
Copy link

Oni-giri commented Mar 8, 2023

Thanks for taking the time to check it @yhuard !

@alcuadrado
Copy link
Member

Nice PR! Thanks 🙌

I just left a minor comment


// Make glob pattern relative to the current working directory
// See https://github.com/kaelzhang/node-ignore/tree/5.2.4#1-pathname-should-be-a-pathrelatived-pathname
const relativeGlob = relative(process.cwd(), solFilesGlob);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this should be relative(config.paths.root, solFilesGlob), right?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To be honest, I'm not 100% sure. First, I was using config.paths.root but I've changed it to process.cwd() in my last commit because it made more sense to me. Solhint calls fs.readFileSync(file) where file is the relative path of the file to lint. I.e. in the context of Solhint, process.cwd() is the reference directory from which relative paths start.

In the tests, both relative(config.paths.root, solFilesGlob) and relative(process.cwd(), solFilesGlob) work.
An edge case would be if Hardhat's root folder is different from the current working directory.
For instance:

  paths: {
    root: "..",
    sources: "solhintignore-project/contracts",
  },

In this case, with paths relative to process.cwd(), the tests would pass, while with paths relative to config.paths.root the tests wouldn't pass.

But this is a really unusual case. In most cases, config.paths.root work fine.

If we decide to use process.cwd(), then I'll have to make sure that all the ignore globs are relative to the current working directory as well.

If we decide to ignore this edge case (hardhat.root ≠ cwd), then I'll be happy to replace process.cwd() with config.paths.root.

I think I'm overthinking it 😅 Let me know what's best in your opinion.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @fvictorio! I've replaced process.cwd() with config.paths.root so as not to block this PR. It's highly unlikely that users will complain about the edge case I mentioned yesterday anyway.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status:ready This issue is ready to be worked on
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

.solhintignore file is not being recognized by @nomiclabs/hardhat-solhint plugin
5 participants