solhint icon indicating copy to clipboard operation
solhint copied to clipboard

lint-staged npm package does not read .solhintignore

Open gitpusha opened this issue 5 years ago • 3 comments

I use lint-staged like so to run my husky pre-commit hook.

image

So it runs solhint against every .sol file.

However, I had a linter bug with solc 0.7.4 which I reported here #262 . So I put that file in .solhintignore. When I ran solhint manually it ignores that file. But when solhint is run by lint-staged somehow it does not seem to ignore that file and the linting throws an error and the lint-staged process exits with code 2.

So I guess, lint-staged somehow does not read .solhintignore ?

gitpusha avatar Oct 21 '20 13:10 gitpusha

I'm guessing the problem is that doing:

solhint Foo.sol

doesn't ignore Foo.sol even if it's in .solhintignore. Is that correct?

I'm not sure what is the ideal behavior here. eslint does this, which seems good enough:

  • If you run eslint . and there's an ignored file in that directory, it is ignored.
  • If you run eslint foo.js and foo.js is ignored, you get a warning saying that that file is ignored, and to use the --no-ignore flag to override that behavior.
  • If you run eslint '*.js' (the quotes are important), then ignored files are ignored (that is, it has a different behavior when using a glob).

fvictorio avatar Mar 08 '21 22:03 fvictorio

For me when I run yarn solhint path/to/ignored/contract it ignores it as expected.

Same if I use a glob.

However, when I run solhint against *.sol in lint-staged it somehow stops ignoring ignored files.

gitpusha avatar Apr 01 '21 16:04 gitpusha

If you are looking for a fix read on.

Initial setup:

  • My package.json command is "solhint": "solhint './contracts/**/*.sol'"
  • Content of .solhintignore is ./contracts/dependencies/**/*.sol

Run:

  • npm run solhint: End command looks like this solhint './contracts/**/*.sol' and it will ignore files given in ignore pattern.
  • Run with lintstaged: Command that run looks like this solhint './contracts/**/*.sol' 'user/x/y/z/contracts/a/b.sol'....'user/x/y/z/contracts/dependencies/a/b.sol'. You can see that ignore will work for 1st argument but not for all as lintstaged is passing each file individually again and with full qualified path.

Workaround

  • No change in package.json command
  • Update ignore pattern like this **/contracts/dependencies/**/*.sol. Notice wildcard before contracts.

Run

  • It will work with both approach. as new ignore pattern can filter files with full qualified path

rokso avatar Apr 12 '22 16:04 rokso