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

Allow to ignore certain directories #117

Closed
SantiMunin opened this issue Mar 23, 2015 · 16 comments
Closed

Allow to ignore certain directories #117

SantiMunin opened this issue Mar 23, 2015 · 16 comments

Comments

@SantiMunin
Copy link

Hello,

I am trying to set a goal in my project's cabal file that would run hlint and fail if it get any hint (see http://taylor.fausak.me/2014/03/04/haskeleton-a-haskell-project-skeleton - Static Analysis section). The problem is I am using BNFC too, which generates some files (in my case in src/Language) that I have no control over. I would like to check all the src tree except for that src/Language folder.

Is it possible now/will be in the future? Thanks

@ndmitchell
Copy link
Owner

You can put {-# ANN module "HLint: ignore" #-} at the top of the file to ignore the single file, or you can pass --ignore=... (where ...) is the name of a specific test to ignore those tests. I don't yet have any way to exclude a set of directories, but I probably should!

Out of curiosity, which hints does BNFC violate?

@SantiMunin
Copy link
Author

Adding the {-# ANN module "HLint: ignore" #-} is a good enough solution for me, I will just add a preHook to the build phase :)

Most of the hints showed are about redundant brackets and

src/Language/Test.hs:27:15: Error: Use when
Found:
  if v > 1 then putStrLn s else return ()
Why not:
  Control.Monad.when (v > 1) $ putStrLn s

src/Language/Test.hs:54:19: Error: Use getContents
Found:
  hGetContents stdin
Why not:
  getContents

@ndmitchell
Copy link
Owner

OK, glad you've fixed it for your case. I'll leave this ticket open to have a command line flag for directories/files to exclude.

@SantiMunin
Copy link
Author

Great, thanks!

@benperez
Copy link

benperez commented Nov 1, 2016

An issue that we've run into is that for certain newer language features that haven't made it into haskell-src-exts yet hlint fails to parse the files even with the {-# ANN module "HLint: ignore" #-} annotation at the top of the file. I'm guessing hlint first tries to parse the files, then when it sees the annotation, decides to simply ignore the hints generated. It would be cool to add the option to skip the parsing altogether and so avoid the parse error messages that this generates.

I've been working around it by keeping a list of files that are currently un-parseable in a file I call .hlintignore and then hacking that list into find ... ! -name unparseable1.hs ! -name unparseable2.hs ... command that feeds files to the hlint command.

If it would be pretty straightforward to add this command line option I'd be happy to submit a PR myself.

@nh2
Copy link

nh2 commented Mar 29, 2017

Is it possible to exclude a given file from being linted, when I give a directory to hlint?

@ndmitchell
Copy link
Owner

@nh2 No, not currently. If it has a good module name you can use the standard ignore stuff to ignore the module.

@MHova
Copy link

MHova commented Apr 25, 2017

As an alternative to @benperez's suggestion, I'm sticking unparseable files in a .src directory (remember to add .src to hs-source-dirs in your .cabal file)

MHova pushed a commit to MHova/haskell-canteven-http that referenced this issue Apr 25, 2017
In order to avoid having HLint parse the file at all. HLint currently does not support Template Haskell typed quotes: ndmitchell/hlint#332

Using this as a workaround: ndmitchell/hlint#117 (comment)
@bitemyapp
Copy link

@nh2 No, not currently. If it has a good module name you can use the standard ignore stuff to ignore the module.

That doesn't work in my case, we're using an HLint.hs module and adding an ignore rule scoped to module HLint ignores all hints/warnings.

{-# ANN module "HLint: ignore" #-}

module HLint where
$ make hlint
hlint -XQuasiQuotes .
No hints (179 ignored)

If I comment it out:

-- {-# ANN module "HLint: ignore" #-}

module HLint where

(tons of output, stuff that needs cleaned up)

The ability to ignore files (HLint.hs in this case) would solve my problem and I am not sure why the annotation gets scoped to the entire HLint run. Something to do with hint perhaps? I do not know.

@bitemyapp
Copy link

@ndmitchell I was doing some cleanup at work and remembered that we still can't use HLint because of this issue. Did I miss some baked-in solution to this problem?

@t3hmrman
Copy link

t3hmrman commented Apr 5, 2018

Just noting this is still a thing -- I've actually vendored some as-of-yet unreleased libraries in my source code, so I can't just edit them and put annotations in. Also, - ignore: {within: Module} didn't work as I expected in hlint.yaml.

I got past this limitation by editing the hlint command to just enumerate the directories I wanted checked.

@ndmitchell
Copy link
Owner

No solutions yet. I think it's waiting on a release of a file-pattern library that is being split out of Shake. Progress slow bug ongoing!

@ndmitchell
Copy link
Owner

Not that using the command line you can restrict hlint to specific directories - e.g. hlint foo bar - but not ignore certain directories.

@danbroooks
Copy link
Contributor

Is there any update to the above @ndmitchell ?

@dspies-leapyear
Copy link

GHC 8.6.5 doesn't seem to allow putting ANN annotations at the top of the file. When I put {-# ANN module "HLint: ignore" #-} after the imports, hlint still throws a parse error (because of QuantifiedConstraints)

@ndmitchell
Copy link
Owner

Great news is that HLint HEAD as of yesterday allows --ignore-glob=foo to ignore everything in the foo directory.

@dspies-leapyear I recommend using {- HLINT ignore -} instead of ANN. See https://github.com/ndmitchell/hlint#ignoring-hints for a discussion of the alternatives.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

9 participants